5@v2eT?01 概述
\3rJ/mQY#h
[0ab(ApacheBench)是Apache自带的超文本传输协议(HTTP)性能测试工具。 其设计意图是描绘当前所安装的Apache的执行性能, 主要是显示你安装的Apache每秒可以处理多少个请求。51Testing软件测试网OK9C6@G(@[
51Testing软件测试网C1i9QL d.X2 使用51Testing软件测试网-](M zpd
2.1 安装51Testing软件测试网xapYLsP0R{
Apache服务器套件自带ab,只要安装Apache即可,无需另行安装ab。ab位于%ApacheHome%/bin目录下(“%ApacheHome%”为Aapche安装路径),你也可以把ab.exe文件copy出来,独立使用。
lxxk1kzR)E ?0I!S%_z;jd
U0v02.2 参数列表
&b2|O-u2I'o+N0C:\>ab51Testing软件测试网
{M$C-dQ'W
ab: wrong number of arguments
5c N9cTD|
|,v0Usage: ab [options] [http://]hostname[:port]/path
!zLz N5~a&s~0Options are:
%S5qH?0O2h
\DD8a$T0-n requests Number of requests to perform51Testing软件测试网}7\N.wLQ%rK/o
-c concurrency Number of multiple requests to make
9pJUP"j/SGF
GF0-t timelimit Seconds to max. wait for responses51Testing软件测试网i+N.Q+KM6\
-p postfile File containing data to POST
6yoX3\4b-YV0-T content-type Content-type header for POSTing
?(WB0jz'r0-v verbosity How much troubleshooting info to print
?:K,c;_%JEW6Cb6V*Z0-w Print out results in HTML tables51Testing软件测试网%KcoXj#ic?
-i Use HEAD instead of GET51Testing软件测试网{p@^U
ol fW
-x attributes String to insert as table attributes51Testing软件测试网,J+c!z$mki(D
-y attributes String to insert as tr attributes
jD0I;d8P
JM%F6fq+{0-z attributes String to insert as td or th attributes51Testing软件测试网:Q"R}Gv0~`
-C attribute Add cookie, eg. 'Apache=1234. (repeatable)
t#`$AW8_KQWJ0-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
/QTQ I#{s8Hn)E'Nk0Inserted after all normal header lines. (repeatable)51Testing软件测试网j1D2RyV9J
-A attribute Add Basic WWW Authentication, the attributes
8Dqw}WZP;R(t0are a colon separated username and password.51Testing软件测试网8MtUd5T
-P attribute Add Basic Proxy Authentication, the attributes51Testing软件测试网E5H!L&l/?J
are a colon separated username and password.51Testing软件测试网&?3b4~?xS9Z
-X proxy:port Proxyserver and port number to use51Testing软件测试网9E]$wy ?,bXX}'v2\e
-V Print version number and exit51Testing软件测试网SG8i)}&v g
{m*e
-k Use HTTP KeepAlive feature51Testing软件测试网P*{h3}9q'F*we
-d Do not show percentiles served table.51Testing软件测试网eUkDm
-S Do not show confidence estimators and warnings.
;y#l ELY5T0-g filename Output collected data to gnuplot format file.
rq!YI[3V E0-e filename Output CSV file with percentages served51Testing软件测试网 aGf:^S&dP\
-h Display usage information (this message)51Testing软件测试网'[8O9K|7n-A
8lm"e(ffeJ0* 中文的列表可以查看Apache手册中文版。51Testing软件测试网GwU8G;k
以上参数最常用的是-n 在测试会话中所执行的请求个数;和-c 一次同时产生的并发请求个数。
2`xfgLO&P~P0L Ardp.]'q|j02.3 实例
4U0p4e;[Q6DE
ncZ
U0假设我们要测试一个PHP论坛系统,其中一个性能测试用例是:“同时处理50个并发请求并运行 1000 次index.php 首页”,我们可以在cmd shell中输入 ab -n 1000 -c 50http://172.16.11.180:88/bbs/index.php,运行结束后,ab会自动显示测试结果,如下:
t6d*ZN:`#o9MM051Testing软件测试网
vdg!Q0s2m'~z
sE:\Webser\Apache2\bin>ab -n 1000 -c 50http://172.16.11.180:88/bbs/index.php51Testing软件测试网"y-@nm1q9xr
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.051Testing软件测试网2NW)nQ;ups
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,http://www.zeustech.net/
6_,?r,P
D^
o!|0Copyright (c) 1998-2002 The Apache Software Foundation,http://www.apache.org/
8J&eY*q6WoZH0:UQ_ k$Fw0Benchmarking 172.16.11.180 (be patient)51Testing软件测试网b,I.HG8_)P
Completed 100 requests
)^n"_m}8h/vQ]0Completed 200 requests51Testing软件测试网aM#U9X-s
z]EV
Completed 300 requests
ZM*g{(|\$`sKx7]0Completed 400 requests
fXKH D(k0Completed 500 requests51Testing软件测试网ow~7}3@ep*F
Completed 600 requests
8Q;h[WX5s0Completed 700 requests51Testing软件测试网)V8`/e.dM7}(I
k
Completed 800 requests
vJ!gU8m b,szS0Completed 900 requests51Testing软件测试网E }p+b Opl
Finished 1000 requests
.AW+jmb,DM051Testing软件测试网KM*Ev/UaC;LUizServerSoftware: Apache
;zbB2{Ai
Dd0Server Hostname: 172.16.11.18051Testing软件测试网#gH&CB(q-S
Server Port: 88
Te6w4o&eF+Aj05wZZlBg0Document Path: /bbs/index.php51Testing软件测试网e4aJY"K"h$j%m;R
Document Length: 36962 bytes
9tfE{)U0 oUWF&A6{0Concurrency Level: 5051Testing软件测试网t2ld?9L
Time taken for tests: 262.515625 seconds
%npT7i2e4Q0Complete requests: 100051Testing软件测试网 { [.H3Rr$CDC
Failed requests: 198
RALd'_;~A/[O0(Connect: 0, Length: 198, Exceptions: 0)51Testing软件测试网]"u7bSD?z7@
g
Write errors: 051Testing软件测试网 {-t_f9e D
Total transferred: 37408432 bytes51Testing软件测试网*n
}&X5]wy8di
HTML transferred: 36967364 bytes
!{4K'Mw BKN0Requests per second: 3.81 [#/sec] (mean)
3x;v#M
\z%r[;U0Time per request: 13125.781 [ms] (mean)51Testing软件测试网^ G5J;_?n x)\ tJ
Time per request: 262.516 [ms] (mean, across all concurrent requests)51Testing软件测试网1cY|qv
Transfer rate: 139.16 [Kbytes/sec] received51Testing软件测试网1^3nx.oyD
51Testing软件测试网C&X2rL0b|9WL;IConnection Times (ms)51Testing软件测试网#D)i7tNgGb)L
min mean[+/-sd] median max51Testing软件测试网+fhaF+}a\YQ
Connect: 0 1 4.5 0 15
B6j?#hKVcR0Processing: 297 12818 2427.6 12921 30578
5[4M}|wd`0Waiting: 281 12801 2427.6 12906 3056251Testing软件测试网iDb9aK1z(X\
S h
Total: 312 12820 2427.5 12921 3057851Testing软件测试网*l#}'X
F*\+_
C.A [
I ev|9\g+F0Percentage of the requests served within a certain time (ms)
:[2zT\Jx050% 1292151Testing软件测试网-B+m\2} Y8{
66% 1320351Testing软件测试网{ k0O1T#k$A,`
75% 1345351Testing软件测试网dj5V4q$^z1}
80% 1354651Testing软件测试网7Hv0`5j
XHG]r
90% 13781
RmV+PAL095% 1415651Testing软件测试网)Ns$[T%x
O#\
98% 1475051Testing软件测试网T"il])|eS7R
99% 18328
o/@{%L(P9U s/a0100% 30578 (longest request)51Testing软件测试网ZF?6QQ
/U/x_ |5Jn&l9j0以上结果指出,在并发50个请求的情况下,完成1000次的访问请求,共花了262.515秒,这个程序每秒可处理3.81个请求。51Testing软件测试网]W
aGQ^%N0u
51Testing软件测试网C1F
@p
J
br
z+D2.4 问题
a@} D
o1T8ln Y0在实际使用中,我发现-c 参数,即一次同时产生的并发请求个数最多设置成64,大于等于65就会报错,不知道为什么。51Testing软件测试网1S%`1u!u"X
51Testing软件测试网Ur0{
uPW_p;yR