有多少用户Nodejs和Socket。io可以支持吗?

时间:2021-03-22 00:59:06

I got a website that implements the broadcast.emit. that sends message to all users of the site. It is just the simplest implementation of socket.io but I currently having a problem. When I hit about 100 concurrent users. The nodejs server starts to lag until it hangs that I can no longer access my whole website. When we checked the server. The nodejs is taking 100% of the CPU. Is it normal?

我有一个实现broadcast.emit的网站。将消息发送给站点的所有用户。它只是socket.io最简单的实现,但我目前遇到了问题。当我达到约100个并发用户时。 nodejs服务器开始滞后,直到它挂起,我无法再访问我的整个网站。当我们检查服务器时。 nodejs占用了100%的CPU。这是正常的吗?

I was wondering how many users can socket.io supports? And when this thing happen is there a way to restart the nodejs server programatically?

我想知道socket.io支持多少用户?当这件事发生时,有没有办法以编程方式重新启动nodejs服务器?

3 个解决方案

#1


16  

At least 250k concurrent connections (and for most use cases bottleneck is memory)

至少250k并发连接(对于大多数用例,瓶颈是内存)

#2


19  

I have a multiplayer card game. Socket.io maxes out my CPU at around 3000 concurrent users. This is on Intel i7 CPU. Because of this I have to run multiple node/socket.io processes to handle the load.

我有一个多人纸牌游戏。 Socket.io在大约3000个并发用户的情况下最大化了我的CPU。这是在Intel i7 CPU上。因此,我必须运行多个node / socket.io进程来处理负载。

For 100 concurrent connections you should be fine. Perhaps you are using some VPS and CPU is shared with all the other VMs? Do you run a dedicated server?

对于100个并发连接,你应该没问题。也许您正在使用某些VPS并且CPU与所有其他VM共享?你运行专用服务器吗?

Also, check your code. You might be doing synchronously some stuff that should go async.

另外,检查您的代码。您可能正在同步执行一些应该异步的东西。

#3


3  

Is it critical for you to deliver message to all clients without dropping it? If no, I'd propose to use socket.volatile.emit call. There can be a lot of problems with remote clients and non-stable connectons.

您是否有必要在不丢弃消息的情况下向所有客户发送消息?如果不是,我建议使用socket.volatile.emit调用。远程客户端和非稳定连接器可能存在很多问题。

#1


16  

At least 250k concurrent connections (and for most use cases bottleneck is memory)

至少250k并发连接(对于大多数用例,瓶颈是内存)

#2


19  

I have a multiplayer card game. Socket.io maxes out my CPU at around 3000 concurrent users. This is on Intel i7 CPU. Because of this I have to run multiple node/socket.io processes to handle the load.

我有一个多人纸牌游戏。 Socket.io在大约3000个并发用户的情况下最大化了我的CPU。这是在Intel i7 CPU上。因此,我必须运行多个node / socket.io进程来处理负载。

For 100 concurrent connections you should be fine. Perhaps you are using some VPS and CPU is shared with all the other VMs? Do you run a dedicated server?

对于100个并发连接,你应该没问题。也许您正在使用某些VPS并且CPU与所有其他VM共享?你运行专用服务器吗?

Also, check your code. You might be doing synchronously some stuff that should go async.

另外,检查您的代码。您可能正在同步执行一些应该异步的东西。

#3


3  

Is it critical for you to deliver message to all clients without dropping it? If no, I'd propose to use socket.volatile.emit call. There can be a lot of problems with remote clients and non-stable connectons.

您是否有必要在不丢弃消息的情况下向所有客户发送消息?如果不是,我建议使用socket.volatile.emit调用。远程客户端和非稳定连接器可能存在很多问题。