Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Good way to use socket.io with cluster in multi-core server?

Good way to use socket.io with cluster in multi-core server?

Problem

Now, I wanted to scale my application vertically, by enabling it to run on multi-core system using cluster module in nodejs.

Everything in my application stores data in Redis, therefore, there isn't a problem dealing with some basic data & sessions.

However, when I spawn multiple worker processes using cluster, it seems that each worker has its own socket handling.

For example, lets assume there is a chat room called 'guest' room.

User A and user B connects to the room, and they are distributed to the different worker process.

Since they are in different processs and these processes do not share sockets listener, there is no way for user A and user B to talk to each other.

What is a good approach to solve this problem? Does socket.io supports multi-core system?

Is socket.io only for single core use?

Problem courtesy of: user482594

Solution

You could use socket.io as normal but with a redis store in the background. It will also support multiple instances on socket.io without any external library. It even supports rooms over multiple instances.

Link to how to set up socket.io with redis: Using Multiples Nodes/Processes with socket.io

Solution courtesy of: Martin

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Good way to use socket.io with cluster in multi-core server?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×