gpt4 book ai didi

node.js - Node : 100s of simultaneous requests slows down server substantially. 操作系统问题?

转载 作者:搜寻专家 更新时间:2023-10-31 23:27:19 26 4
gpt4 key购买 nike

我的 Node 应用程序正在向 A 和 B 两个服务器发出请求。对于服务器 A,它会等待一个请求完成,然后再发出下一个请求。对于服务器 B,它每秒发出 20 个请求而无需等待。当我向服务器 B 发出请求时,对服务器 A 的请求需要很长时间。当我不向服务器 B 发出请求时,它们会很快进行。对服务器 B 的请求堆积如山,但同时处理的请求不超过几百个。

我在 Joyent smartos 实例上运行了完全相同的应用程序,具有相同的 Node 版本,但我没有遇到这个问题,所以我假设它是操作系统设置的限制问题,而不是限制该 Node 集。在 Node 中,我确实将 maxSockets 设置为 10000,如此处所述,http://markdawson.tumblr.com/post/17525116003/node

我正在使用 upstart 运行我的应用程序,但我不知道如果没有它我是否会遇到问题(那将是我的下一个测试)。在我的 upstart 配置文件中,我限制了 nofile 90000 90000。还有一些我可以提高的其他限制,如此处所述,http://upstart.ubuntu.com/wiki/Stanzas#limit ,但我不知道他们做什么。其中之一会导致问题吗?我的 Ubuntu 机器的限制还可以设置在哪里?

我应该补充一点,我正在通过 Monit 启动 upstart 程序以防万一。

最佳答案

你没有提到你是如何与 ServerA 或 ServerB 交谈的,但是 Node 的 HTTP library每个主机(协议(protocol)/服务器/端口)组合的默认限制为六个连接。您可以使用 http.globalAgent.maxSockets = 20; 或任何您希望的最大值来增加它。

其他问题可能与您操作系统中的打开文件/套接字限制有关...您需要查看 /proc/sys/fs/file-max

来自最近的 linux/Documentation/sysctl/fs.txt:

file-max & file-nr:

The kernel allocates file handles dynamically, but as yet it doesn't free them again.

The value in file-max denotes the maximum number of file- handles that the Linux kernel will allocate. When you get lots of error messages about running out of file handles, you might want to increase this limit.

Historically, the three values in file-nr denoted the number of allocated file handles, the number of allocated but unused file handles, and the maximum number of file handles. Linux 2.6 always reports 0 as the number of free file handles -- this is not an error, it just means that the number of allocated file handles exactly matches the number of used file handles.

Attempts to allocate more file descriptors than file-max are reported with printk, look for "VFS: file-max limit reached".


特别是对于 Ubuntu,如果您有很多 ufw(防火墙)和/或 iptables 规则,这也会产生影响。

关于node.js - Node : 100s of simultaneous requests slows down server substantially. 操作系统问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26879466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com