Node.js 最大并发连接数为 1000 [英] Node.js maxing out at 1000 concurrent connections

查看:197
本文介绍了Node.js 最大并发连接数为 1000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在 AWS (EC2) 上使用简单的 Hello World 节点服务器对节点性能进行基准测试.

We're benchmarking node performance using a simple Hello World node server on AWS (EC2).

无论我们使用什么大小的实例,Node 总是显示最大并发连接数为 1000 个(这不是每秒 1000 个,而是它可以在 1 次处理 1000 个).不久之后,CPU 激增,节点基本冻结.

No matter what size instance we use Node always appears to max out at 1000 concurrent connections (this is NOT 1000 per second, but 1000 it can handle at 1 time). Shortly after that the CPU spikes and node basically freezes.

节点 v0.10.5

var http = require('http');
var server = http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('loaderio-dec86f35bc8ba1b9b604db6c328864c1');
});
server.maxHeadersCount = 0;
server.listen(4000);

Node 应该能够处理比这更多的事情吗?任何想法将不胜感激.

Node should be able to handle more than this correct? Any thoughts would be greatly appreciated.

还将文件描述符(软、硬、系统)设置为 65096)

Also the file descriptors (soft, hard, system) are set to 65096)

推荐答案

使用 posix 模块来提高进程可以使用的文件描述符数量的限制.

Use the posix module to raise the limit on the number of file descriptors your process can use.

安装 posix

npm install posix

然后在您启动应用程序时运行的代码中...

Then in your code that runs when you launch your app...

var posix = require('posix');

// raise maximum number of open file descriptors to 10k,
// hard limit is left unchanged
posix.setrlimit('nofile', { soft: 10000 });

这篇关于Node.js 最大并发连接数为 1000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆