我正在使用Hello world像这样的例子 -
var sys = require("sys"),
my_http = require("http");
my_http.createServer(function(request,response){
response.writeHeader(200, {"Content-Type": "text/plain"});
response.writeHeader(200,{"Connection":"Keep-Alive"});
response.write("Hello World");
response.end();
}).listen(8080);
sys.puts("Server Running on 8080");
在客户端,我使用 ab 如下 - (使用 5k 并发连接总共 100000 个请求)
ab -n 100000 -c 5000 http://192.168.0.99:8080/
当我这样做时netstat -antp | 8080 | grep 8080 grep ESTABLISHED |wc -l
我只得到200到300之间的值。在服务器端,相同的命令仅显示10-20个并发连接。
首先,为什么两个数字存在差异?两者不应该是一样的吗?
其次,为什么我没有看到 1000 个 ESTABLISHED 连接?
服务器端配置-http://pastebin.com/Cc77YQp7
客户端配置 - http://pastebin.com/4pV16TuD
如您所见,我已将 TIME_WAIT 设置为 1 秒后过期,并在 Google 后优化了其他参数(增加 ulimit 等),但我找不到这两个问题的根本原因。
事实上,很多时候我在客户端(在 ab 工具中)遇到错误 - apr_socket_recv: Connection timed out (110)
客户端在 Ubuntu 12 LTS 上运行,Node.JS 在 Debian 稳定版上运行(喘息)
最佳答案
您可能需要增加套接字池的值。尝试:
my_http.globalAgent.maxSockets = Infinity//或一些合理的数字...
关于performance - 简单的 Node.js 服务器无法处理数百个并发请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19827060/