我对Node.js相对较新(已经玩了一段时间,但只是开始用它来做严肃的事情)。在本地测试时,我遇到了一些非常奇怪的基准行为,并决定构建最基本的可能HTTP服务器并使用Apache Benchmark(ab)对其进行基准测试。
这是我的代码:
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello, world!');
res.end();
}).listen(8888);
当我像这样跑ab时:
ab -n 1000000 -c 100 'http://127.0.0.1:8888/'
我得到以下结果:
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
apr_socket_recv: Operation timed out (60)
Total of 16413 requests completed
我使用的是nodejs版本0.10.25。在运行我的服务器和ab之前,我还将ulimit设置为8192(最大值),因此无法达到文件描述符限制。
这是我不明白的地方:
谢谢!
额外奖励:我已经录制了一个您可以在此处查看的小型截屏视频:http://recordit.co/9i0ja6GZqR这显示了我正在谈论的内容。
更新
看到这篇文章后:Why does a simple Thin server stop responding at 16500 requests when benchmarking?并正在运行:
sudo sysctl -w net.inet.tcp.msl=1000
我能够通过以下结果成功完成我的ab命令:
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 100000 requests
Completed 200000 requests
Completed 300000 requests
Completed 400000 requests
Completed 500000 requests
Completed 600000 requests
Completed 700000 requests
Completed 800000 requests
Completed 900000 requests
Completed 1000000 requests
Finished 1000000 requests
Server Software:
Server Hostname: 127.0.0.1
Server Port: 8888
Document Path: /
Document Length: 13 bytes
Concurrency Level: 100
Time taken for tests: 338.545 seconds
Complete requests: 1000000
Failed requests: 0
Write errors: 0
Total transferred: 114000000 bytes
HTML transferred: 13000000 bytes
Requests per second: 2953.82 [#/sec] (mean)
Time per request: 33.854 [ms] (mean)
Time per request: 0.339 [ms] (mean, across all concurrent requests)
Transfer rate: 328.84 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 14 212.3 0 8363
Processing: 0 20 114.8 11 4205
Waiting: 0 20 114.2 11 4205
Total: 0 34 240.8 11 8368
Percentage of the requests served within a certain time (ms)
50% 11
66% 13
75% 14
80% 14
90% 17
95% 21
98% 32
99% 605
100% 8368 (longest request)
不幸的是,我无法超越100个并发请求 - 例如,如果我达到200,我会得到以下内容:
rdegges at Randalls-MacBook-Pro in ~
○ ab -n 1000000 -c 200 'http://127.0.0.1:8888/'
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
apr_socket_recv: Connection reset by peer (54)
似乎我基本上限制了100个并发请求。
我关注的另一件事是来自第一个ab命令的响应时间。它的平均响应时间大约为33.854ms,考虑到服务器正在做什么,这似乎非常高。
所以我想我的问题是:我可以做些什么来改善并发请求并减少每个请求的处理时间?我确定我在这里做错了什么。
谢谢!
答案 0 :(得分:0)
让基准目标计算机除了运行集群或其他多核节点解决方案之外什么都不做(它对基准单进程节点没有用或相关)。
让多台计算机通过本地网络轰炸目标计算机,不要从服务器本身运行ab或类似计算机。