Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I scale socket.io?

Let's say a server gets 10,000 concurrent connections (via socket.io). That's a lot, and if it can't handle any more, I need to spin up another server.

How can I sync the two servers together with their socket.io?

like image 247
TIMEX Avatar asked May 10 '11 03:05

TIMEX


People also ask

Does Socket.IO scale?

This makes the server infrastructure transparent to the clients which means you can scale the servers up or down without changing the client behavior at all. In fact, you can even add more than one physical server box and increase capacity even further that way.

How much traffic can Socket.IO handle?

Once you reboot your machine, you will now be able to happily go to 55k concurrent connections (per incoming IP).

How many rooms can Socket.IO handle?

socket.io rooms are a lightweight data structure. They are simply an array of connections that are associated with that room. You can have as many as you want (within normal memory usage limits). There is no heavyweight thing that makes a room expensive in terms of resources.

Which is better Socket.IO or pusher?

Pusher is the category leader in delightful APIs for app developers building communication and collaboration features. On the other hand, Socket.IO is detailed as "Realtime application framework (Node. JS server)". Socket.IO enables real-time bidirectional event-based communication.


2 Answers

I wouldn't use Cluster to scale Socket.IO. Socket.IO 0.6 is designed as a single process server, and it uses long living connections or polling connections to achieve a real time connection between the server and client.

If you put Cluster infront of your socket.io client you will basically distribute the polling transports between different servers, who are not aware of the client. This will result in broken connections. But also broadcasting to all your clients will be a pain as they are all distributed on different servers and you don't have IPC between them.

So I would only advice to use Cluster if you only use Web Socket & Flash Socket connections and don't need to use the broadcast functionality.

So what should you do?

You could wait until socket.io 0.7 is released which is designed from the ground up to be used on multiple processes.

Or you can use pub/sub to send messages between different servers.

like image 80
3rdEden Avatar answered Sep 23 '22 23:09

3rdEden


You can try to use for example cluster module and distribute the load to multiple cores (in case you have a multi-core CPU). In case this is not enough you can try to use reverse proxy for distributing requests across multiple servers and redis as a central session data store (if it's possible for your scenario).

like image 38
yojimbo87 Avatar answered Sep 20 '22 23:09

yojimbo87