我的ApacheBench负载测试结果中的长度请求失败

时间:2009-10-02 23:39:35

标签: php scalability lighttpd load-testing apachebench

我有一个PHP的网站,Lighttpd。它也在Centos 5上使用MySQL。我用Apache Bench(ab)测试了我的PHP代码。它导致一些错误(失败的请求)表明其他长度超过正常。我绝对相信我的PHP结果总是应该具有相同的确切长度。我已经查看了我的Lighttpd和MySQL日志和错误日志,并且没有任何错误。

当结果有其他长度或者有没有其他方法可以找出原因是什么或“坏”结果是什么时,有没有办法确切检查ab得到了什么?

我需要知道,因为我需要100%的好结果。

-bash-3.2# ab -n 500 -c 200 http://domain.com/test/index.php
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking domain.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 500 requests


Server Software:        lighttpd/1.4.20
Server Hostname:        domain.com
Server Port:            80

Document Path:          /test/index.php
Document Length:        15673 bytes

Concurrency Level:      200
Time taken for tests:   0.375862 seconds
Complete requests:      500
Failed requests:        499
   (Connect: 0, Length: 499, Exceptions: 0)
Write errors:           0
Total transferred:      7920671 bytes
HTML transferred:       7837000 bytes
Requests per second:    1330.28 [#/sec] (mean)
Time per request:       150.345 [ms] (mean)
Time per request:       0.752 [ms] (mean, across all concurrent requests)
Transfer rate:          20579.36 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   10   9.4      6      30
Processing:     0  113 133.5     16     342
Waiting:        0  111 134.3     12     341
Total:          0  123 138.9     16     370

Percentage of the requests served within a certain time (ms)
  50%     16
  66%    235
  75%    289
  80%    298
  90%    331
  95%    345
  98%    365
  99%    368
 100%    370 (longest request)

3 个答案:

答案 0 :(得分:18)

使用ab参数运行-v 2,这意味着详细级别为2.这将转储响应标头。如果您的请求未使用分块编码,您将看到一个“Content-Length”标题,指示每个响应的大小。

gw:~$ ab -n 1 -v 2 "http://whatever.com/"

...

LOG: header received:
HTTP/1.0 200 OK
...
Content-Length: 1568399

如果您的回复使用分块编码,则在传输结束之前不知道长度。通常,chunked编码仅用于压缩响应,而ApacheBench默认不进行压缩。

如果 压缩响应,无论出于何种原因都可以解释它;压缩长度取决于内容。

您还可以使用curl -i--compress选项查看包含和不包含压缩的单个请求的响应标头。

答案 1 :(得分:3)

使用tcpdump

打开qty 2终端/ shell窗口或只使用屏幕。

在第一个窗口中,使用tcpdump从/向NIC(eth0)捕获传输数据到文件:

sudo tcpdump -s 9999 -i eth0 -w myfile.txt

在第二个窗口中,关闭你的ab命令:

ab -n 500 -c 200 http://domain.com/test/index.php

完成所有操作后,使用字符串和grep:

解析文件
strings myfile2.txt | grep -C 3 "200 OK"

您应该能够通过观察或grep结果来监控那里的所有数据段。

答案 2 :(得分:1)

ab假设所有回答都相同。它查看第一个响应的内容长度,然后将其他响应与之比较。

从手册页:

Document Length
  This is the size in bytes of the first successfully returned document. 
  If the document length changes during  testing,  the  response  is 
  considered an error.

因此,如果您的第一个请求包含以下数据:

{"hostname":"nodecellar-1-dwfxd","serverip":"10.1.3.3"}

下一个是:

{"hostname":"nodecellar-1-dwfxd","serverip":"10.1.3.30"}

ab将因长度错误而失败,因为输出的长度是一个字符。