ab是Apache自带的HTTP压力测试工具,全称是 ApacheBench ,同微软的WAST、惠普的LoadRunner、QALoad等比起来,它要方便易用得多
ab是Apache的一个安装组件,所以需要下载Apache安装后才能使用,该命令位于Apache安装目录下的bin文件夹中
ab是专门用于HTTP Server的benchmark testing,可以同时模拟多个并发请求 ab的设计意图是描绘当前所安装的Apache的执行性能,主要是显示所安装的Apache每秒可以处理多少个请求
ab不像LR那么强大,但它足够轻便,若只是在开发过程中想检查一下某个模块的响应情况,或者做一些场景比较简单的测试,ab是个不错的选择
至少不用花费很多时间去学习LR中的那些复杂的功能,就更别说那License的价格了
下面简单介绍下它的用法
查询版本:[ab -V](注意这里是大写的V)
[Jadyer@Jadyer-RHEL63 ~]$ ab -V
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
查询参数:[ab -v](注意这里是小写的v)
01
[Jadyer
@Jadyer
-RHEL63 ~]$ ab -v
02
ab: option requires an argument -- v
03
ab: wrong number of arguments
04
Usage: ab [options] [http[s]:
07
-n requests Number of requests to perform
09
-c concurrency Number of multiple requests to make
11
-t timelimit Seconds to max. wait
for
responses
12
-b windowsize Size of TCP send/receive buffer, in bytes
14
-p postfile File containing data to POST. Remember also to set -T
15
-u putfile File containing data to PUT. Remember also to set -T
17
-T content-type Content-type header
for
POSTing, eg.
18
'application/x-www-form-urlencoded'
19
Default is
'text/plain'
21
-v verbosity How much troubleshooting info to print
23
-w Print out results in HTML tables
25
-i Use HEAD instead of GET
27
-x attributes String to insert as table attributes
29
-y attributes String to insert as tr attributes
31
-z attributes String to insert as td or th attributes
33
-C attribute Add cookie, eg. 'Apache=
1234
. (repeatable)
35
-H attribute Add Arbitrary header line, eg.
'Accept-Encoding: gzip'
36
Inserted after all normal header lines. (repeatable)
38
-A attribute Add Basic WWW Authentication, the attributes
39
are a colon separated username and password.
42
-P attribute Add Basic Proxy Authentication, the attributes
43
are a colon separated username and password.
45
-X proxy:port Proxyserver and port number to use
47
-V Print version number and exit
49
-k Use HTTP KeepAlive feature
51
-d Do not show percentiles served table.
53
-S Do not show confidence estimators and warnings.
56
-g filename Output collected data to gnuplot format file.
59
-e filename Output CSV file with percentages served
60
-r Don't exit on socket receive errors.
62
-h Display usage information (
this
message)
63
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
64
-f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)
测试网站:[ab -n 1000 -c 10 http://192.168.8.35:9000/noCardNoPasswordSign]
-n表示总共发送的请求数 -c表示每次并发的请求数 使用ab测试时,其支持的最大并发数是没有限制的,但实际值要取决于Linux允许每个进程打开的最大文件数,即[ulimit -n]
01
[Jadyer
@Jadyer
-RHEL63 ~]$ ab -n
1000
-c
10
https:
02
This is ApacheBench, Version
2.3
<$Revision:
655654
$>
03
Copyright
1996
Adam Twiss, Zeus Technology Ltd, http:
04
Licensed to The Apache Software Foundation, http:
06
Benchmarking epay.
10010
.com (be patient)
07
Completed
100
requests
08
Completed
200
requests
09
Completed
300
requests
10
Completed
400
requests
11
Completed
500
requests
12
Completed
600
requests
13
Completed
700
requests
14
Completed
800
requests
15
Completed
900
requests
16
Completed
1000
requests
17
Finished
1000
requests
21
Server Software: Apache-Coyote/
1.1
23
Server Hostname: epay.
10010
.com
26
SSL/TLS Protocol: TLSv1/SSLv3,DHE-RSA-AES256-SHA,
2048
,
256
31
Document Length:
0
bytes
36
Time taken
for
tests:
26.121
seconds
38
Complete requests:
1000
42
Non-2xx responses:
1001
44
Total transferred:
299299
bytes
46
HTML transferred:
0
bytes
48
Requests per second:
38.28
[#/sec] (mean)
50
Time per request:
261.206
[ms] (mean)
52
Time per request:
26.121
[ms] (mean, across all concurrent requests)
56
Transfer rate:
11.19
[Kbytes/sec] received
60
min mean[+/-sd] median max
61
Connect:
85
222
101.0
205
1224
62
Processing:
12
38
23.4
34
151
63
Waiting:
12
37
23.5
33
151
64
Total:
144
259
100.9
244
1268
71
Percentage of the requests served within a certain time (ms)
80
100
%
1268
(longest request)
获取网站信息
[Jadyer@Jadyer-RHEL63 ~]$ curl -Is https://epay.10010.com/
HTTP/1.1 302 Moved Temporarily
Date: Tue, 06 Nov 2012 17:52:13 GMT
Server: Apache-Coyote/1.1
Location: http://epay.10010.com/404.jsp
Content-Type: text/vnd.wap.wml;chartset=gbk;charset=GBK
Set-Cookie: JSESSIONID=9DDBCA78C7FEF4ABECD070E744CE926C; Path=/
http://www.open-open.com/lib/view/open1353735993699.html