48

我今天才开始使用 AB。阅读一些关于新的 AB 教程,并考虑尝试对我的站点进行负载测试。

使用它几次后,我收到了大量失败的请求。你能解释一下失败的请求是什么意思吗?我该如何针对这个问题进行更多调查?

样本 AB 结果:

-jailshell-3.2$ ab -n500 -c10 http://www.tweeting.tv/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 www.tweeting.tv (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 500 requests


Server Software:        Apache
Server Hostname:        www.tweeting.tv
Server Port:            80

Document Path:          /index.php
Document Length:        242861 bytes

Concurrency Level:      10
Time taken for tests:   97.846330 seconds
Complete requests:      500
Failed requests:        481
   (Connect: 0, Length: 481, Exceptions: 0)
Write errors:           0
Non-2xx responses:      2
Total transferred:      121214449 bytes
HTML transferred:       121003283 bytes
Requests per second:    5.11 [#/sec] (mean)
Time per request:       1956.927 [ms] (mean)
Time per request:       195.693 [ms] (mean, across all concurrent requests)
Transfer rate:          1209.78 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0 1503 1675.5      1    9036
Processing:   130  393 285.1    319    2382
Waiting:       92  244 226.3    192    2180
Total:        153 1896 1726.2   1121   10374

Percentage of the requests served within a certain time (ms)
  50%   1121
  66%   3308
  75%   3355
  80%   3375
  90%   3451
  95%   3603
  98%   4163
  99%   9315
 100%  10374 (longest request)

注意我正在使用 Hostgator Linux 共享服务器。

4

3 回答 3

81

这是动态页面的问题,因为 Content-Length 在请求之间可能会有所不同。将 ab 与此类页面一起使用时,您需要使用该-l选项。

-l              Accept variable document length (use this for dynamic pages)
于 2015-02-10T15:45:48.640 回答
44

失败的请求都基于长度 - 即与所述字节数不完全匹配的响应数。这将是由于动态内容(例如广告等)每次都提供不同的服务,因此无需担心。

于 2011-07-29T23:06:30.547 回答
8

马丁是对的。更有帮助的是,我对我们的生产服务器进行了快速 curl:

{user@staging:~}$ for i in `seq 1 10`; do curl -sk https://app.copperegg.com/login >    /tmp/lb$i.txt ; done
{user@staging:~}$ wc /tmp/lb*
   74   239  3316 /tmp/lb1.txt
   74   239  3324 /tmp/lb10.txt
   74   239  3320 /tmp/lb2.txt
   74   239  3316 /tmp/lb3.txt
   74   239  3316 /tmp/lb4.txt
   74   239  3316 /tmp/lb5.txt
   74   239  3320 /tmp/lb6.txt
   74   239  3316 /tmp/lb7.txt
   74   239  3316 /tmp/lb8.txt
   74   239  3316 /tmp/lb9.txt
  740  2390 33176 total
{user@staging:~}$ diff /tmp/lb1.txt /tmp/lb10.txt  
7c7
<   var g_time_offset = new Date().getTime() - 1318965621000;
---
>   var g_time_offset = new Date().getTime() - 1318965622000;
15c15
< <meta name="csrf-token" content="bi9pgbUoUQLOwB3V8fT1E40sV06x4914ybLSvnfEeeg="/>
---
> <meta name="csrf-token" content="GL&#47;RRZCf2Zk&#47;AQzRgEW2U4Iv3htD1hodt2qfp4jwIxQ="/>
23c23
<   <form accept-charset="UTF-8" action="/authenticate" id="loginForm" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="bi9pgbUoUQLOwB3V8fT1E40sV06x4914ybLSvnfEeeg=" /></div>
---
>   <form accept-charset="UTF-8" action="/authenticate" id="loginForm" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="GL/RRZCf2Zk/AQzRgEW2U4Iv3htD1hodt2qfp4jwIxQ=" /></div>
{user@staging:~}$ diff /tmp/lb1.txt /tmp/lb2.txt 
7c7
<   var g_time_offset = new Date().getTime() - 1318965621000;
---
>   var g_time_offset = new Date().getTime() - 1318965622000;
9,10c9,10
< <link href="/stylesheets/application.css?1318747862" media="screen" rel="stylesheet" type="text/css" />
< <script src="/javascripts/cache/application.js?1318747811" type="text/javascript"></script>
---
> <link href="/stylesheets/application.css?1318747582" media="screen" rel="stylesheet" type="text/css" />
> <script src="/javascripts/cache/application.js?1318747448" type="text/javascript"></script>
15c15
< <meta name="csrf-token" content="bi9pgbUoUQLOwB3V8fT1E40sV06x4914ybLSvnfEeeg="/>
---
> <meta name="csrf-token" content="BMZKKUZ3WFhQrCIewQ81VuArEtUp8gc6ccr0Wi3&#47;sqE="/>
23c23
<   <form accept-charset="UTF-8" action="/authenticate" id="loginForm" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="bi9pgbUoUQLOwB3V8fT1E40sV06x4914ybLSvnfEeeg=" /></div>
---
>   <form accept-charset="UTF-8" action="/authenticate" id="loginForm" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="BMZKKUZ3WFhQrCIewQ81VuArEtUp8gc6ccr0Wi3/sqE=" /></div>
{user@staging:~}$ 

请注意,我们看到了一个“内容”字符串,其中包含一个漂亮丑陋的字符串。请注意,“/”字符在“form”行中,但在“meta”行中,它被替换为“/”。这解释了我的请求长度之间的 4 或 8 个字符的差异。

令人恼火的是 apachebench 不能聪明地解释这一点,但至少我们可以看到原因。

于 2011-10-18T19:30:30.897 回答