Description
When reading the readme, if I'm not wrong, Redis broadcasts to ALL node processes for EVERY room message. I wonder how scalable/efficient this approach is with a large number of node processes and rooms.
Let's say a common scenario - in our case, we're building a chat app where users can have group conversations with each other (like whatsapp/fb messenger), and each chat group could have up to 500 people.
Say I have 32 node processes running socket.io-redis, from what I understand, all these processes are subscribed to redis. Now I send a particular message to a room called user
via io.to("user1").emit("hello")
. This will prompt Redis to send a message to ALL 32 node processes asking which process(es) contain the room "user1", and send the message "hello" to the corresponding sockets in that room.
In our design, when a user connects, he joins a room named after his own user ID, which is why the above room is called user1
, basically this is how we send a message to a particular user.
So, back to the problem. In a chat group of 500 users, a user sends "hello", db fetches the userID
s of all those users, and for each user Redis will ask ALL 32 node processes if they have that user's room. So in total 500 * 32
commands being issued, instead of only 500
commands. Can this lead to scalability issues? i.e. the queries got amplified by the number of nodejs processes.
Therefore, using this package, should we limit the number of nodejs processes? i.e. instead of having 32 processes each connecting to a small number of sockets (each occupying a small memory, like 1G of RAM), we should have much fewer processes (say 4), but each can take a large amount of memory, like 8G of RAM (thus can contain a large number of sockets)? But of course this needs to flag node using --max-old-space-size= 8192
for example.
I wonder if anyone (or the maintainers) have suggestion for chat apps running with a large number of concurrently online users (1+ million)? Please let me know if I'm making any sense. Thanks!