Nodejs & Socket.io 可以支持多少用户?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10161796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:32:13  来源:igfitidea点击:

How many users Nodejs & Socket.io can support?

node.jssocket.io

提问by 3s2ng

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 服务器?

采纳答案by Andrey Sidorov

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

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

回答by Milan Babu?kov

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。这是在英特尔 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.

另外,请检查您的代码。您可能正在同步做一些应该异步的事情。

回答by Yuri Lapitsky

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 调用。远程客户端和不稳定的连接可能会出现很多问题。