Using multiple rooms to support one large map?

Hi before trying to implement this I want to get some feedback about this design approach.

Basically I want to have a large map, with the possibility of 1000+ players on it. But to save bandwidth I want to section the map off into its own rooms, possibly having each room living on a different process. And then each room would have logic that tells the client when they need to connect to another room, dynamically leaving/joining rooms as needed.

Is this the correct approach to accomplish this?

if(cluster.isMaster) {
    const cpus = os.cpus().length;
    for (let i = 0; i < 2; ++i) {
        cluster.fork();
    }
} else {
    const gameServer = new colyseus.Server({
        server: http.createServer(),
        presence: new colyseus.MemsharedPresence()
    });

    const id = cluster.worker.id;
    gameServer.register("game" + id, Game); // should be able to join game1, game2, etc from client
    gameServer.listen(8081);
}

When I try to run this I can connect to game1 but it says the game2 handler does not exist.

Do I need to be listening on a different port? I want the client to be able to join in and out of rooms so creating a new connection seems overkill.. I feel like it should be working without that. Any idea how to fix this problem?

When I try joining game1 just once on my client my requestJoin logs out

requesting to join
This process is your pid 8739
requesting to join
This process is your pid 8739

@visgotti said in Using multiple rooms to support one large map?:

Is this the correct approach to accomplish this?

Hi @visgotti, absolutely, splitting the map into smaller "rooms" would be the recommended way for dealing with huge maps.

I'd say you don't need to worry about registering a different room name per worker id. Actually, every worker should have the exact same room names registered. By using either MemsharedPresence or RedisPresence, you should have the rooms being created on different processes.

@endel I see. So there's no way to have a room assigned to a process and have another one assigned to another process? I'm guessing Colyseus will just automatically balance out traffic between all the workers?

@visgotti Ideally, yes, Colyseus should balance the rooms to ensure rooms are distributed across processes. Right now this balancing is not perfect, though. I'd suggest to just use the way it is, and eventually we can have this!

@endel Sounds good. Thank you! For persisting data between rooms, I'm using the room.presence functions for getting/setting player attributes on onAuth and onLeave. Is this acceptable or is there a more efficient way of accomplishing the same thing?

Cool, sounds good! That's the way to go IMO. You can persist user data on any storage (Redis, MongoDB, etc) on onLeave, and restore it on onAuth or onJoin.

Feel free to post your progress in the showcase section of the forums!

@endel Thank you!! and yes definitely can't wait till I get to show off what I've been building :P This framework is awesome. I was using pomelo before this and I can say for sure working with colyseus has been a way better experience. Speed, complexity, documentation, etc all trump it.

Amazing work. Thank you again for your efforts in building such an awesome framework.

That's great to hear @visgotti, thanks a lot ❤️❤️❤️