我怎么能把足球拉高?

时间:2022-08-22 14:37:04

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.

假设一个服务器有10,000个并发连接(通过socket.io)。这是很多,如果它不能再处理,我需要旋转另一个服务器。

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

如何将两个服务器与它们的socket.io同步?

2 个解决方案

#1


3  

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

您可以尝试使用集群模块并将负载分配到多个内核(如果您有一个多核CPU)。如果这还不够,您可以尝试使用反向代理跨多个服务器分发请求,并将redis作为中心会话数据存储(如果可能的话)。

#2


42  

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.

我不会用集群来扩展Socket.IO。套接字。IO 0.6被设计成一个单独的进程服务器,它使用长时间的连接或轮询连接来实现服务器和客户机之间的实时连接。

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.

如果你把集群放在你的套接字前面。io客户端您将在不同的服务器之间分发轮询传输,而这些服务器并不知道客户端。这将导致断开连接。但同时向所有客户端广播也会很痛苦,因为它们都分布在不同的服务器上,而且它们之间没有IPC。

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.

因此,如果您只使用Web套接字和Flash套接字连接,并且不需要使用广播功能,那么我只建议您使用Cluster。

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.

你可以等到插座。io 0.7是发布的,从地面设计到用于多个进程。

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

或者您可以使用pub/sub在不同的服务器之间发送消息。

#1


3  

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

您可以尝试使用集群模块并将负载分配到多个内核(如果您有一个多核CPU)。如果这还不够,您可以尝试使用反向代理跨多个服务器分发请求,并将redis作为中心会话数据存储(如果可能的话)。

#2


42  

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.

我不会用集群来扩展Socket.IO。套接字。IO 0.6被设计成一个单独的进程服务器,它使用长时间的连接或轮询连接来实现服务器和客户机之间的实时连接。

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.

如果你把集群放在你的套接字前面。io客户端您将在不同的服务器之间分发轮询传输,而这些服务器并不知道客户端。这将导致断开连接。但同时向所有客户端广播也会很痛苦,因为它们都分布在不同的服务器上,而且它们之间没有IPC。

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.

因此,如果您只使用Web套接字和Flash套接字连接,并且不需要使用广播功能,那么我只建议您使用Cluster。

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.

你可以等到插座。io 0.7是发布的,从地面设计到用于多个进程。

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

或者您可以使用pub/sub在不同的服务器之间发送消息。