Apache自带的性能测试工具ab的使用

上一篇 / 下一篇  2011-12-13 13:27:51 / 个人分类:软件测试工具

51Testing软件测试网EkwUM

1 概述
3L_9o)E$\vA#i0ab(ApacheBench)是
Apache自带的超文本传输协议(HTTP)性能测试工具。 其设计意图是描绘当前所安装的Apache的执行性能, 主要是显示你安装的Apache每秒可以处理多少个请求。

dH$qz,fo)C[%td051Testing软件测试网9\ A| BY v

2 使用
`-H"Z;f?&B02.1 安装51Testing软件测试网SO:m*K5WIO9e'o8]
Apache服务器套件自带ab,只要安装Apache即可,无需另行安装ab。ab位于%ApacheHome%/bin目录下(“%ApacheHome%”为Aapche安装路径),你也可以把ab.exe文件copy出来,独立使用。

w2w[LOq/_051Testing软件测试网 Xv l"uWKQd

2.2 参数列表51Testing软件测试网A j6S&Pvg
C:\>ab51Testing软件测试网k\upq*H7P j
ab: wrong number of arguments
~:c~F2@0Usage: ab [options] [http://]hostname[:port]/path
V'l{#p5X(F0Options are:
6W^-Fk Bb%e t x0-n requests Number of requests to perform51Testing软件测试网T:D(HG|
-c concurrency Number of multiple requests to make51Testing软件测试网0VkT,v O['w.b
-t timelimit Seconds to max. wait for responses51Testing软件测试网:`0ik"~^(F2[e
-p postfile File containing data to POST51Testing软件测试网^~8\UEY0s*Vq
-T content-type Content-type header for POSTing51Testing软件测试网m~OEO{] o-wJ)G
-v verbosity How much troubleshooting info to print51Testing软件测试网$r c8r6Y'f
-w Print out results in HTML tables
4A6n'K O4` qV*a0-i Use HEAD instead of GET51Testing软件测试网#K*\\[UG7gT
-x attributes String to insert as table attributes51Testing软件测试网_}\ d1Vi
-y attributes String to insert as tr attributes
yEN6a:H0-z attributes String to insert as td or th attributes
F7bs k dgX r0-C attribute Add cookie, eg. 'Apache=1234. (repeatable)51Testing软件测试网(@:D id1HZc2j)M|9a
-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
O&W }wT*m0Inserted after all normal header lines. (repeatable)51Testing软件测试网 G)q xl'r/@9A%p
-A attribute Add Basic WWW Authentication, the attributes51Testing软件测试网h5V3E(M eI5z
are a colon separated username and password.
f"P#LID&k E1v*k(]0-P attribute Add Basic Proxy Authentication, the attributes51Testing软件测试网,~i*D8u"|
are a colon separated username and password.
.c'Q qKM0-X proxy:port Proxyserver and port number to use51Testing软件测试网Y1^ B'_Kb7\"?E
-V Print version number and exit51Testing软件测试网t]IHe{
-k Use HTTP KeepAlive feature51Testing软件测试网3oB-j^$w`
-d Do not show percentiles served table.51Testing软件测试网:c-V*P!c ^i|
-S Do not show confidence estimators and warnings.51Testing软件测试网4X2mPNjctHa
-g filename Output collected data to gnuplot format file.
tC4pYAV8bn0-e filename Output CSV file with percentages served51Testing软件测试网'aLk$D3G,Pp IV
-h Display usage information (this message)

&X ?1w)ah;@C0

]5n_p3ij*Ry7f0* 中文的列表可以查看Apache手册中文版。
BO5@_oM d.~j1U0以上参数最常用的是-n 在测试会话中所执行的请求个数;和-c 一次同时产生的并发请求个数。

OUFkK2X051Testing软件测试网ZH&?d}O

2.3 实例51Testing软件测试网%z*B}9G sS
假设我们要测试一个PHP论坛
系统,其中一个性能测试用例是:“同时处理50个并发请求并运行 1000 次index.php 首页”,我们可以在cmd shell中输入 ab -n 1000 -c 50http://172.16.11.180:88/bbs/index.php,运行结束后,ab会自动显示测试结果,如下:

(Q(WH*?q051Testing软件测试网/q[&yQoy,Ko5A N

E:\Webser\Apache2\bin>ab -n 1000 -c 50http://172.16.11.180:88/bbs/index.php
y,Ye c,LM6v n0This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.051Testing软件测试网ZA Zu7q pU5I4fl
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,
http://www.zeustech.net/51Testing软件测试网*_W\ S2L
Copyright (c) 1998-2002 The Apache Software Foundation,http://www.apache.org/

+FI;P hU9En S U u0

%}8Ux A~ Eg:_ d:G0Benchmarking 172.16.11.180 (be patient)
ds nG]0Completed 100 requests51Testing软件测试网_'Ck0x#a7m]Q-D1gl
Completed 200 requests51Testing软件测试网6e#MO Q X'O$c X0F|a {
Completed 300 requests
da+JF#n5L!@0Completed 400 requests
1R5{Ng1tDf U2m0Completed 500 requests51Testing软件测试网9F9xLR7n8l
Completed 600 requests51Testing软件测试网6i uf%M DF
Completed 700 requests
c'm Zb h0Completed 800 requests
?^#dvhv+| nS0Completed 900 requests51Testing软件测试网5\f!W |+q-B@+b
Finished 1000 requests
51Testing软件测试网$n,y W0|2a!_I

51Testing软件测试网2n.h9L$} \\!j1g0oV

ServerSoftware: Apache
)D*P8GM|-BTG}0Server Hostname: 172.16.11.180
3P%EZ~$j}7Q0Server Port: 88

F z"t+k(lh;H051Testing软件测试网{1d+Rt A6V

Document Path: /bbs/index.php
6`?"Jg{+^0Document Length: 36962 bytes
51Testing软件测试网1}RQD0|4g1ZBT9~

51Testing软件测试网_8KA)~$S ]1V/o%}

Concurrency Level: 5051Testing软件测试网j3gvL1F
Time taken for tests: 262.515625 seconds51Testing软件测试网0f;`,K0`-\&P(}
Complete requests: 1000
"aDvV.ot2i ol&W0Failed requests: 198
7hx7u_P,J(\m0(Connect: 0, Length: 198, Exceptions: 0)
K)Q^.LB'u7V0Write errors: 051Testing软件测试网E_.N7`O
Total transferred: 37408432 bytes
#\}d8YH^H0HTML transferred: 36967364 bytes
)X [{Am~A~o@0Requests per second: 3.81 [#/sec] (mean)
JsaX%[oL1c0Time per request: 13125.781 [ms] (mean)
2s hq8R8gjI2^0Time per request: 262.516 [ms] (mean, across all concurrent requests)
{Jf#i%Q k` Kgh0Transfer rate: 139.16 [Kbytes/sec] received
51Testing软件测试网/OCt3eg[

51Testing软件测试网o}~`&?z){f

Connection Times (ms)51Testing软件测试网v#E(A&cn g$d:y Z#p[
min mean[+/-sd] median max51Testing软件测试网5X zax^ ]J+d3N3G
Connect: 0 1 4.5 0 15
X4W9A?m3{0Processing: 297 12818 2427.6 12921 3057851Testing软件测试网'Q3{{ S0pRcAa$C
Waiting: 281 12801 2427.6 12906 3056251Testing软件测试网du0q8}E o7k P.z
Total: 312 12820 2427.5 12921 30578
51Testing软件测试网7K,~d'j;UV:|

51Testing软件测试网2hJ|.`3I3B.F

Percentage of the requests served within a certain time (ms)51Testing软件测试网IH-x$k.GT[ Oo
50% 12921
q%X|v _;D066% 1320351Testing软件测试网%zt.i)Q&qS}2h rd
75% 1345351Testing软件测试网_"FCYF)d,p
80% 1354651Testing软件测试网 A9[-i/n#Z
90% 13781
c.Qan0VTB095% 1415651Testing软件测试网%mhS;J-^V
98% 1475051Testing软件测试网Y}%a [W/tj(dN
99% 1832851Testing软件测试网[5Y"A]G k5pN%x
100% 30578 (longest request)

B0Y0@4ma&u|d0

E%Lwl+a!{i2L.e0以上结果指出,在并发50个请求的情况下,完成1000次的访问请求,共花了262.515秒,这个程序每秒可处理3.81个请求。

b9p8_2t#[)IJ8U"p0

,Y'i'_H H i1[;I4p/N;N02.4 问题51Testing软件测试网,dH"}4jQGx)z
在实际使用中,我发现-c 参数,即一次同时产生的并发请求个数最多设置成64,大于等于65就会报错,不知道为什么。
|p3o1r |I0
51Testing软件测试网eAEc4mah


TAG:

amyxiaojun的个人空间 引用 删除 amyxiaojun   /   2012-03-29 13:13:28
1
 

评分:0

我来说两句

Open Toolbar