Monday, 11 November 2019

Scaling nodejs socket io room based game with cluster

When a pleyer connects he can join a room or create one and wait for other players to join.I keep each game in a global variable and update it:setInterval(() => {for (let game in games) {games[game].run(); }}, 1000/30);As more users make rooms I can image this could get heavy so I want to use the cluster module in nodejs to use multiple cores.I don't want each node to be able to talk to each other with Redis as a pub-sub. I want to redirect the client to the node instance for which some conditions exist. Like for example if the client wants to join a room search all node instances and connect to the instance the first free room is found or if the client wants to make a room, redirect him to the instance which has the least rooms. The problem is I don't know how to direct a client to a particular node instance and where to store information on which he can make a decision which instance to join.

Submitted November 12, 2019 at 02:08AM by macrocop

No comments:

Post a Comment