1. ab
- Date:
2018-08-29
1.1. 命令格式
- 命令格式:
ab [options] [http[s]://]hostname[:port]/path
1.2. 所属用户
- 命令路径:
/usr/bin/ab
- 需要权限:
普通用户权限即可执行
1.3. 使用指导
- 作用:
ab命令是Apache的Web服务器的性能测试工具,它可以测试安装Web服务器每秒种处理的HTTP请求。
ab命令是软件包 httpd-tools 提供的工具。
小技巧
- 查看方法:
yum provides */ab
1.4. 参数
参数及参数作用:
- -n requests
用于指定压力测试总共的执行次数。如果没有指定这个参数默认是请求1次。
示例:
1[user@centos6 ~]$ ab http://www.baidu.com/index.html
2This is ApacheBench, Version 2.3 <$Revision: 655654 $>
3Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4Licensed to The Apache Software Foundation, http://www.apache.org/
5
6Benchmarking www.baidu.com (be patient).....done
7
8
9Server Software: BWS/1.1--------------------提供服务的软件
10Server Hostname: www.baidu.com--------------主机名
11Server Port: 80-------------------------端口
12
13Document Path: /index.html----------------压力测试的页面
14Document Length: 118719 bytes---------------页面大小
15
16Concurrency Level: 1--------------------------并发,这个默认是1
17Time taken for tests: 0.107 seconds--------------测试耗时
18Complete requests: 1--------------------------完成的请求次数
19Failed requests: 0--------------------------请求失败次数
20Write errors: 0--------------------------写错误的次数
21Total transferred: 119670 bytes---------------共传输的字节数
22HTML transferred: 118719 bytes---------------传输html页面字符串,应该等于页面大小乘以请求的次数
23Requests per second: 9.34 [#/sec] (mean)--------每秒请求次数
24Time per request: 107.099 [ms] (mean)--------每次请求耗时
25Time per request: 107.099 [ms] (mean, across all concurrent requests)
26Transfer rate: 1091.19 [Kbytes/sec] received
27
28Connection Times (ms)
29 min mean[+/-sd] median max
30Connect: 17 17 0.0 17 17
31Processing: 90 90 0.0 90 90
32Waiting: 18 18 0.0 18 18
33Total: 107 107 0.0 107 107
34
35[user@centos6 ~]$ ab -n 10 http://www.baidu.com/index.html
36This is ApacheBench, Version 2.3 <$Revision: 655654 $>
37Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
38Licensed to The Apache Software Foundation, http://www.apache.org/
39
40Benchmarking www.baidu.com (be patient).....done
41
42
43Server Software: BWS/1.1
44Server Hostname: www.baidu.com
45Server Port: 80
46
47Document Path: /index.html
48Document Length: 118227 bytes
49
50Concurrency Level: 1
51Time taken for tests: 1.107 seconds
52Complete requests: 10
53Failed requests: 9
54(Connect: 0, Receive: 0, Length: 9, Exceptions: 0)
55Write errors: 0
56Total transferred: 1194133 bytes
57HTML transferred: 1184545 bytes
58Requests per second: 9.03 [#/sec] (mean)
59Time per request: 110.693 [ms] (mean)
60Time per request: 110.693 [ms] (mean, across all concurrent requests)
61Transfer rate: 1053.50 [Kbytes/sec] received
62
63Connection Times (ms)
64 min mean[+/-sd] median max
65Connect: 16 18 1.6 17 22
66Processing: 73 93 9.9 91 105
67Waiting: 18 18 0.6 19 19
68Total: 95 110 8.9 109 122
69WARNING: The median and mean for the waiting time are not within a normal deviation
70 These results are probably not that reliable.
71
72Percentage of the requests served within a certain time (ms)
7350% 109
7466% 109
7575% 121
7680% 122
7790% 122
7895% 122
7998% 122
8099% 122
81100% 122 (longest request)
- -c concurrency
用于指定压力测试的并发数。默认并发是1。
示例:
1[user@centos6 ~]$ ab -n 100 https://zzjlogin.github.io/index.html
2This is ApacheBench, Version 2.3 <$Revision: 655654 $>
3Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4Licensed to The Apache Software Foundation, http://www.apache.org/
5
6Benchmarking zzjlogin.github.io (be patient).....done
7
8
9Server Software: GitHub.com
10Server Hostname: zzjlogin.github.io
11Server Port: 443
12SSL/TLS Protocol: TLSv1/SSLv3,ECDHE-RSA-AES128-GCM-SHA256,2048,128
13
14Document Path: /index.html
15Document Length: 65452 bytes
16
17Concurrency Level: 1-------------------------并发为1
18Time taken for tests: 139.671 seconds-----------默认并发是1,所以100次请求耗时较长
19Complete requests: 100
20Failed requests: 0
21Write errors: 0
22Total transferred: 6611663 bytes
23HTML transferred: 6545200 bytes
24Requests per second: 0.72 [#/sec] (mean)-------并发为1,所以每秒请求数也比较小
25Time per request: 1396.714 [ms] (mean)
26Time per request: 1396.714 [ms] (mean, across all concurrent requests)
27Transfer rate: 46.23 [Kbytes/sec] received
28
29Connection Times (ms)
30 min mean[+/-sd] median max
31Connect: 608 690 33.4 693 749
32Processing: 596 706 78.2 693 1063
33Waiting: 200 229 11.9 230 257
34Total: 1205 1396 93.0 1391 1785
35
36Percentage of the requests served within a certain time (ms)
3750% 1391
3866% 1416
3975% 1429
4080% 1440
4190% 1478
4295% 1572
4398% 1750
4499% 1785
45100% 1785 (longest request)
46
47[user@centos6 ~]$ ab -n 100 -c20 https://zzjlogin.github.io/index.html
48This is ApacheBench, Version 2.3 <$Revision: 655654 $>
49Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
50Licensed to The Apache Software Foundation, http://www.apache.org/
51
52Benchmarking zzjlogin.github.io (be patient).....done
53
54
55Server Software: GitHub.com
56Server Hostname: zzjlogin.github.io
57Server Port: 443
58SSL/TLS Protocol: TLSv1/SSLv3,ECDHE-RSA-AES128-GCM-SHA256,2048,128
59
60Document Path: /index.html
61Document Length: 65452 bytes
62
63Concurrency Level: 20-----------------------并发是参数设置的20
64Time taken for tests: 8.678 seconds------------总耗时,并发为20,所以耗时更短
65Complete requests: 100
66Failed requests: 0
67Write errors: 0
68Total transferred: 6611703 bytes------------共传输的数据
69HTML transferred: 6545200 bytes------------html总传输的页面大小,和并发为1时相同
70Requests per second: 11.52 [#/sec] (mean)-----因为并发为20,所以比并发为1时每秒请求次数更多了。
71Time per request: 1735.534 [ms] (mean)
72Time per request: 86.777 [ms] (mean, across all concurrent requests)
73Transfer rate: 744.06 [Kbytes/sec] received
74
75Connection Times (ms)
76 min mean[+/-sd] median max
77Connect: 716 751 24.9 747 811
78Processing: 711 746 53.6 735 1001
79Waiting: 236 245 4.0 245 254
80Total: 1437 1497 60.0 1487 1756
81
82Percentage of the requests served within a certain time (ms)
8350% 1487
8466% 1494
8575% 1502
8680% 1529
8790% 1553
8895% 1680
8998% 1725
9099% 1756
91100% 1756 (longest request)
- -t timelimit
等待响应的最大时间(单位:秒)。默认情况下没有时间限制
示例:
1[user@centos6 ~]$ ab -n 100 -t 1 https://zzjlogin.github.io/index.html
2This is ApacheBench, Version 2.3 <$Revision: 655654 $>
3Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4Licensed to The Apache Software Foundation, http://www.apache.org/
5
6Benchmarking zzjlogin.github.io (be patient)
7Finished 1 requests
8
9
10Server Software: GitHub.com
11Server Hostname: zzjlogin.github.io
12Server Port: 443
13SSL/TLS Protocol: TLSv1/SSLv3,ECDHE-RSA-AES128-GCM-SHA256,2048,128
14
15Document Path: /index.html
16Document Length: 65452 bytes
17
18Concurrency Level: 1
19Time taken for tests: 1.727 seconds
20Complete requests: 1--------------------------设置等待时间1秒,发现请求100次,成功请求只有1次
21Failed requests: 0
22Write errors: 0
23Total transferred: 66117 bytes
24HTML transferred: 65452 bytes
25Requests per second: 0.58 [#/sec] (mean)
26Time per request: 1727.304 [ms] (mean)
27Time per request: 1727.304 [ms] (mean, across all concurrent requests)
28Transfer rate: 37.38 [Kbytes/sec] received
29
30Connection Times (ms)
31 min mean[+/-sd] median max
32Connect: 801 801 0.0 801 801
33Processing: 926 926 0.0 926 926
34Waiting: 414 414 0.0 414 414
35Total: 1726 1726 0.0 1726 1726
36
37[user@centos6 ~]$ ab -n 100 -t 1 http://192.168.1.1/webpages/login.html
38This is ApacheBench, Version 2.3 <$Revision: 655654 $>
39Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
40Licensed to The Apache Software Foundation, http://www.apache.org/
41
42Benchmarking 192.168.1.1 (be patient)
43Finished 81 requests
44
45
46Server Software:
47Server Hostname: 192.168.1.1
48Server Port: 80
49
50Document Path: /webpages/login.html
51Document Length: 73974 bytes
52
53Concurrency Level: 1
54Time taken for tests: 1.004 seconds
55Complete requests: 81-----------------------局域网测试,请求100次,设置超时时间1秒,最后成功81次
56Failed requests: 0
57Write errors: 0
58Total transferred: 6007851 bytes
59HTML transferred: 5991894 bytes
60Requests per second: 80.65 [#/sec] (mean)
61Time per request: 12.399 [ms] (mean)
62Time per request: 12.399 [ms] (mean, across all concurrent requests)
63Transfer rate: 5841.67 [Kbytes/sec] received
64
65Connection Times (ms)
66 min mean[+/-sd] median max
67Connect: 1 1 0.1 1 1
68Processing: 10 11 0.7 11 15
69Waiting: 1 1 0.5 1 5
70Total: 11 12 0.7 12 16
71
72Percentage of the requests served within a certain time (ms)
7350% 12
7466% 12
7575% 13
7680% 13
7790% 13
7895% 14
7998% 14
8099% 16
81100% 16 (longest request)
- -b windowsize
TCP发送/接收的缓冲大小(单位:字节,bytes)。
示例:
1[user@centos6 ~]$ ab -n 10 -b 100 https://zzjlogin.github.io/index.html
2This is ApacheBench, Version 2.3 <$Revision: 655654 $>
3Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4Licensed to The Apache Software Foundation, http://www.apache.org/
5
6Benchmarking zzjlogin.github.io (be patient).....done
7
8
9Server Software: GitHub.com
10Server Hostname: zzjlogin.github.io
11Server Port: 443
12SSL/TLS Protocol: TLSv1/SSLv3,ECDHE-RSA-AES128-GCM-SHA256,2048,128
13
14Document Path: /index.html
15Document Length: 65452 bytes--------------测试页面比设置的值大,这个测试大几倍
16
17Concurrency Level: 1
18Time taken for tests: 119.578 seconds----------因为请求的只能接收100bytes,所以每个页面需要分多次传,所以耗时更长。
19Complete requests: 10
20Failed requests: 0
21Write errors: 0
22Total transferred: 661170 bytes
23HTML transferred: 654520 bytes
24Requests per second: 0.08 [#/sec] (mean)
25Time per request: 11957.845 [ms] (mean)
26Time per request: 11957.845 [ms] (mean, across all concurrent requests)
27Transfer rate: 5.40 [Kbytes/sec] received
28
29Connection Times (ms)
30 min mean[+/-sd] median max
31Connect: 1081 1210 105.9 1205 1484
32Processing: 10441 10747 242.3 10785 11174
33Waiting: 431 470 24.7 480 506
34Total: 11554 11957 243.3 11951 12407
35
36Percentage of the requests served within a certain time (ms)
3750% 11951
3866% 11978
3975% 12127
4080% 12213
4190% 12407
4295% 12407
4398% 12407
4499% 12407
45100% 12407 (longest request)
46[user@centos6 ~]$ ab -n 10 -b 10000 https://zzjlogin.github.io/index.html
47This is ApacheBench, Version 2.3 <$Revision: 655654 $>
48Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
49Licensed to The Apache Software Foundation, http://www.apache.org/
50
51Benchmarking zzjlogin.github.io (be patient).....done
52
53
54Server Software: GitHub.com
55Server Hostname: zzjlogin.github.io
56Server Port: 443
57SSL/TLS Protocol: TLSv1/SSLv3,ECDHE-RSA-AES128-GCM-SHA256,2048,128
58
59Document Path: /index.html
60Document Length: 65452 bytes
61
62Concurrency Level: 1
63Time taken for tests: 22.891 seconds------------这个设置的缓存接收范围比较大,所以耗时较短
64Complete requests: 10
65Failed requests: 0
66Write errors: 0
67Total transferred: 661170 bytes
68HTML transferred: 654520 bytes
69Requests per second: 0.44 [#/sec] (mean)
70Time per request: 2289.149 [ms] (mean)
71Time per request: 2289.149 [ms] (mean, across all concurrent requests)
72Transfer rate: 28.21 [Kbytes/sec] received
73
74Connection Times (ms)
75 min mean[+/-sd] median max
76Connect: 673 748 36.2 764 783
77Processing: 1447 1541 97.2 1530 1767
78Waiting: 227 245 11.3 246 262
79Total: 2130 2288 119.7 2290 2539
80
81Percentage of the requests served within a certain time (ms)
8250% 2290
8366% 2298
8475% 2307
8580% 2418
8690% 2539
8795% 2539
8898% 2539
8999% 2539
90100% 2539 (longest request)
- -p postfile
发送POST请求时需要上传的文件,此外还必须设置-T参数。
示例:
1
- -u putfile
发送PUT请求时需要上传的文件,此外还必须设置-T参数。
示例:
1
- -T content-type
用于设置Content-Type请求头信息,例如:application/x-www-form-urlencoded,默认值为text/plain。
示例:
1
- -v verbosity
指定打印帮助信息的冗余级别。默认是1
4是打印头信息,3是打印相应状态码(例如200、404),2是打印警告和通知信息
示例:
1[user@centos6 ~]$ ab -v 3 https://zzjlogin.github.io/index.html
2This is ApacheBench, Version 2.3 <$Revision: 655654 $>
3Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4Licensed to The Apache Software Foundation, http://www.apache.org/
5
6Benchmarking zzjlogin.github.io (be patient)...INFO: POST header ==
7---
8GET /index.html HTTP/1.0
9Host: zzjlogin.github.io
10User-Agent: ApacheBench/2.3
11Accept: */*
12
13省略下面输出内容
- -w
以HTML表格形式打印结果。默认表宽两列,背景为白色。
示例:
1[user@centos6 ~]$ ab -w https://zzjlogin.github.io/index.html
2<p>
3This is ApacheBench, Version 2.3 <i><$Revision: 655654 $></i><br>
4Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>
5Licensed to The Apache Software Foundation, http://www.apache.org/<br>
6</p>
- -i
使用HEAD请求代替GET请求。
示例:
1[user@centos6 ~]$ ab -i https://zzjlogin.github.io/index.html
2This is ApacheBench, Version 2.3 <$Revision: 655654 $>
3Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4Licensed to The Apache Software Foundation, http://www.apache.org/
5
6Benchmarking zzjlogin.github.io (be patient).....done
7
8
9Server Software: GitHub.com
10Server Hostname: zzjlogin.github.io
11Server Port: 443
12SSL/TLS Protocol: TLSv1/SSLv3,ECDHE-RSA-AES128-GCM-SHA256,2048,128
13
14Document Path: /index.html
15Document Length: 0 bytes
16
17Concurrency Level: 1
18Time taken for tests: 0.956 seconds
19Complete requests: 1
20Failed requests: 0
21Write errors: 0
22Total transferred: 665 bytes
23HTML transferred: 0 bytes
24Requests per second: 1.05 [#/sec] (mean)
25Time per request: 956.310 [ms] (mean)
26Time per request: 956.310 [ms] (mean, across all concurrent requests)
27Transfer rate: 0.68 [Kbytes/sec] received
28
29Connection Times (ms)
30 min mean[+/-sd] median max
31Connect: 722 722 0.0 722 722
32Processing: 235 235 0.0 235 235
33Waiting: 234 234 0.0 234 234
34Total: 956 956 0.0 956 956
- -x <table>-attributes
插入字符串作为table标签的属性。-y插入字符串作为tr标签的属性。
示例:
1[user@centos6 ~]$ ab -w https://zzjlogin.github.io/index.html
2<p>
3This is ApacheBench, Version 2.3 <i><$Revision: 655654 $></i><br>
4Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>
5Licensed to The Apache Software Foundation, http://www.apache.org/<br>
6</p>
7<p>
8..done
9
10
11<table >
12下面内容略
13
14[user@centos6 ~]$ ab -x test https://zzjlogin.github.io/index.html
15<p>
16This is ApacheBench, Version 2.3 <i><$Revision: 655654 $></i><br>
17Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>
18Licensed to The Apache Software Foundation, http://www.apache.org/<br>
19</p>
20<p>
21..done
22
23
24<table test>
25下面内容略
- -y attributes
插入字符串作为tr标签的属性。
示例:
1
- -z attributes
插入字符串作为td标签的属性。
示例:
1
- -C attributes
添加cookie信息,例如:”Apache=1234”(可以重复该参数选项以添加多个)。
cookie格式:name=value,这种名称和值成对出现。
示例:
1
- -H attributes
添加任意的请求头,请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)。
值时冒号分割的键值对,例如:
Accept-Encoding: gzip或者Accept-Encoding: zip/zop;8bit示例:
1
- -A auth-username:password
添加一个基本的网络认证信息,用户名和密码之间用英文冒号隔开。
示例:
- -P proxy-auth-username:password
添加一个基本的代理认证信息,用户名和密码之间用英文冒号隔开。
示例:
1
- -X proxy:port
指定使用的代理服务器和端口号,例如:”126.10.10.3:88”。
示例:
1
- -V
打印版本号并退出。
示例:
1
- -k
使用HTTP的KeepAlive特性。
示例:
1
- -d
不显示百分比。
示例:
1
- -S
不显示预估和警告信息。
示例:
1
- -g filename
输出结果信息到gnuplot格式的文件中。
示例:
1
- -e filename
输出结果信息到CSV格式的文件中。
示例:
1
- -r
指定接收到错误信息时不退出程序。
- -h
显示用法信息,其实就是ab -help。
- -Z ciphersuite
指定加密组件,可以参考openssl
- -f protocol
使用指定的SSL/TLS 协议(SSL2, SSL3, TLS1, or ALL)
1.5. 参考实例
1[root@zzjlogin ~]# ab -c 1000 -n 1000 http://www.baidu.com/index.html
2This is ApacheBench, Version 2.3 <$Revision: 655654 $>
3Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4Licensed to The Apache Software Foundation, http://www.apache.org/
5
6Benchmarking www.baidu.com (be patient)
7Completed 100 requests
8Completed 200 requests
9Completed 300 requests
10apr_socket_recv: Connection refused (111)
11Total of 309 requests completed
1[root@zzjlogin ~]# ab -n 1000 -c 1000 http://192.168.161.132/index.html
2This is ApacheBench, Version 2.3 <$Revision: 655654 $>
3Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4Licensed to The Apache Software Foundation, http://www.apache.org/
5
6Benchmarking 192.168.161.132 (be patient)
7Completed 100 requests
8Completed 200 requests
9Completed 300 requests
10Completed 400 requests
11Completed 500 requests
12Completed 600 requests
13Completed 700 requests
14Completed 800 requests
15Completed 900 requests
16Completed 1000 requests
17Finished 1000 requests
18
19
20Server Software: nginx/1.14.0
21Server Hostname: 192.168.161.132
22Server Port: 80
23
24Document Path: /index.html
25Document Length: 612 bytes
26
27Concurrency Level: 1000
28Time taken for tests: 0.072 seconds
29Complete requests: 1000
30Failed requests: 0
31Write errors: 0
32Total transferred: 845000 bytes
33HTML transferred: 612000 bytes
34Requests per second: 13810.63 [#/sec] (mean)
35Time per request: 72.408 [ms] (mean)
36Time per request: 0.072 [ms] (mean, across all concurrent requests)
37Transfer rate: 11396.47 [Kbytes/sec] received
38
39Connection Times (ms)
40 min mean[+/-sd] median max
41Connect: 0 24 2.4 24 29
42Processing: 16 20 2.7 20 27
43Waiting: 0 17 4.8 18 27
44Total: 25 44 1.6 44 47
45
46Percentage of the requests served within a certain time (ms)
4750% 44
4866% 44
4975% 45
5080% 46
5190% 46
5295% 47
5398% 47
5499% 47
55100% 47 (longest request)