2009-10-02 29 views
21

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

有没有什么办法来检查什么时候结果有其他的长度或有任何其他方式找出的原因是什么或什么是“坏”的结果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) 

回答

17

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

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

... 

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

如果您的回复使用分块编码,那么直到传输结束才会知道长度。通常,分块编码仅用于压缩响应,ApacheBench默认不进行压缩。

如果压缩的可能解释是什么原因的响应;压缩的长度取决于内容。

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

+27

**匿名用户评论(拒绝编辑):**注意:'ab'预计所有回复的大小相等。如果有可能你的输出大小不同,你应该忽略“失败的请求”,因为“ab”会认为它们失败。 – Anne 2011-12-12 22:14:21

3

使用的tcpdump

打开数量2终端/壳窗口或只使用屏幕。

在第一个窗口,使用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" 

你应该能够monito从目前的所有数据段通过眼球或grep'ing结果。

+0

我得到 'tcpdump的:IOCTL:没有这样的设备' 尝试消息时须藤tcpdump的 – 2009-10-03 08:32:07

+0

我你写做了什么,这是结果: - <! - 结束Quantcast标签 - > HTTP /1.0 200 OK 连接方式:关闭 X-Powered-by:PHP/5.2.6 内容类型:text/html 我应该如何解释这个结果? – 2009-10-03 17:21:02

+0

Tomaszs:您将不得不更改您正在运行的任何* nix OS的NIC设备标识符。 Mac上的en0,Linux上的eth0等。 HTTP/1.0 200 OK表示Web服务器找到了请求的资源和返回的内容。页面成功! 您只需阅读myfile2.txt的内容即可查看故障发生的位置。 – 2009-10-06 22:02:02

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将失败,长度错误,因为输出长一个字符。

相关问题