1.下载

yum -y install httpd-tools

2.命令参数

-n 执行的请求数量
-c 并发请求个数
-t 测试所进行的最大秒数
-w 以HTML表的格式输出结果
-p 包含了需要POST的数据的文件
-T POST数据所使用的Content-type头信息
-k 启用HTTP KeepAlive功能,即在一个HTTP会话中执行多个请求,默认时,不启用KeepAlive功能

3.命令示例

ab -n3000 -c100 https://www.oaroad.com/

4.ab性能指标

Document Path: /                            ###请求的资源
Document Length: 50679 bytes                ###文档返回的长度,不包括相应头
Concurrency Level: 3000                     ###并发个数
Time taken for tests: 30.449 seconds        ###总请求时间
Complete requests: 3000                     ###总请求数
Failed requests: 0                          ###失败的请求数
Write errors: 0
Total transferred: 152745000 bytes
HTML transferred: 152037000 bytes
Requests per second: 98.52 [#/sec] (mean)        ###平均每秒的请求数
Time per request: 30449.217 [ms] (mean)          ###平均每个请求消耗的时间
Time per request: 10.150 [ms] (mean, across all concurrent requests)     ###上面的请求除以并发数
Transfer rate: 4898.81 [Kbytes/sec] received                             ###传输速率

Connection Times (ms)
min mean[+/-sd] median max
Connect: 2 54 27.1 55 98
Processing: 51 8452 5196.8 7748 30361
Waiting: 50 6539 5432.8 6451 30064
Total: 54 8506 5210.5 7778 30436

Percentage of the requests served within a certain time (ms)
50% 7778                                        ###50%的请求都在7778Ms内完成
66% 11059
75% 11888
80% 12207
90% 13806
95% 18520
98% 24232
99% 24559
100% 30436 (longest request)