开发者

How can I scale socket.io?

Let's say a server gets 10,000 concurrent connections (via socket.io). 开发者_如何学Python 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?


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜