工具使用示例如下:

ab -n 1000 -c 50 http://localhost:8080/test

命令说明如下:

  • ab:ab命令;
  • n:总请求次数;
  • c:并发数

运行示例如下:

[root@localhost] ab -n 1000 -c 50 http://localhost:8080/test

This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:
Server Hostname: localhost
Server Port: 8080

Document Path: /test
Document Length: 4 bytes

Concurrency Level: 50
Time taken for tests: 0.792 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 136000 bytes
HTML transferred: 4000 bytes
Requests per second: 1262.90 [#/sec] (mean)
Time per request: 39.591 [ms] (mean)
Time per request: 0.792 [ms] (mean, across all concurrent requests)
Transfer rate: 167.73 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.7 0 12
Processing: 3 38 26.0 31 186
Waiting: 2 26 21.5 23 175
Total: 3 38 26.0 32 186

Percentage of the requests served within a certain time (ms)
50% 32
66% 36
75% 42
80% 44
90% 60
95% 85
98% 151
99% 156
100% 186 (longest request)

返回结果数据说明如下:

  • Concurrency Level: 并发量
  • Time taken for tests: 整个测试的时间
  • Complete requests: 完成的总请求数
  • Failed requests: 失败的请求数
  • Total transferred: 响应数据的总长度(包括http头信息和消息体数据)
  • HTML transferred: 响应数据中消息体数据的总和
  • Requests per second:吞吐率(计算方式为:Complete requests / Time taken for tests,也就是 完成的总请求数 / 整个测试的时间)
  • Time per request: 用户平均请求等待时间
  • Time per request: 服务器平均请求等待时间
  • Transfer rate: 单位时间内从服务器获取的数据长度(计算方式为:Total transferred / Time taken for tests, 也就是 响应数据的总长度(包括http头信息和消息体数据)/ 整个测试的时间)