NodeJS和apache基准测试的奇怪行为

时间:2012-10-11 06:43:44

标签: apache node.js apachebench

我正在测试nodejs(0.8.11)。

使用以下服务器应用程序:

var http = require('http');
http.createServer(function (req, res) {
    console.log('hit!');
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

我运行了apache基准测试:

ab -r -v 4'http://127.0.0.1:1337 /'

我得到以下输出:

hit!
hit!
hit!
hit!
hit!
hit!
hit!
hit!
hit!
... (alot more)

ab:

的输出
Benchmarking 127.0.0.1 (be patient)...INFO: POST header == 
---
GET / HTTP/1.0
Host: 127.0.0.1:1337
User-Agent: ApacheBench/2.3
Accept: */*


---
LOG: header received:
HTTP/1.1 200 OK
Content-Type: text/plain
Date: Thu, 11 Oct 2012 06:40:04 GMT
Connection: close

Hello World

LOG: Response code = 200
..done


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            1337

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      1
Time taken for tests:   0.009 seconds
Complete requests:      1
Failed requests:        0
Write errors:           0
Total transferred:      113 bytes
HTML transferred:       12 bytes
Requests per second:    115.05 [#/sec] (mean)
Time per request:       8.692 [ms] (mean)
Time per request:       8.692 [ms] (mean, across all concurrent requests)
Transfer rate:          12.70 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        8    8   0.0      8       8
Processing:     0    0   0.0      0       0
Waiting:        0    0   0.0      0       0
Total:          9    9   0.0      9       9

并认为默认的请求数不是1,如ab手册中所述,我试过:

ab -v 4 -n 1 -c 1 'http://127.0.0.1:1337/'

我得到相同的输出(日志中有很多'命中!')

这里发生了什么?

这是针对节点的,我用我的码头应用尝试了同样的问题ab -c 1 -n 1,只记录了一次...

注意:我尝试过卷曲节点服务 - 只有1'命中!'在日志......

2 个答案:

答案 0 :(得分:4)

我还在nodejs google群组中发布了此内容。显然这是apache / ab的macosx lion版本中的一个错误。

来自nodejs组的原始回复:

https://groups.google.com/d/msg/nodejs/OqVZ4zPbqp0/DitO9xkmFOUJ

此处还有描述问题的相关页面的direct link

答案 1 :(得分:0)

  

这里发生了什么?

每个'点击'都是新连接。从你的角度来看,为什么它看起来不对?