1. 安装:sudo apt-install apache2-utils
(2)eg:(以并发1请求1次)
2. 用法
(1)基本参数:
- -n:共发起的请求数
- -c:每一次发送的请求数(并发数)
- -vn:当n>2时,可以显示发送的http请求头和响应的http头的内容。并且,n越大显示的内容会越全,比如,-v4。
比如:
ab-n10000 -c100 -v4 -H'Content-Type: application/json' -p'test.json' 'http://192.168.1.36:8080/vtboss/service/account',表示:以并发100连续请求100次。
ab -n1 -c1 -H'Content-Type: application/json' -p'test.json' 'http://192.168.1.36:8080/vtboss/service/account'
打印结果如下:
This is ApacheBench, Version 2.3 <$Revision: 655654$>
Copyright 1996 Adam Twiss, Zeus TechnologyLtd, http://www.zeustech.net/
Licensed to The Apache SoftwareFoundation, http://www.apache.org/
Benchmarking 192.168.1.36 (be patient).....done
Server Software: Apache-Coyote/1.1
Server Hostname: 192.168.1.36
Server Port: 8080
Document Path: /vtboss/service/account
Document Length: 49bytes
Concurrency Level: 1
Time taken for tests: 0.020seconds
Complete requests: 1
Failed requests: 0
Write errors: 0
Total transferred: 281bytes
Total POSTed: 421
HTML transferred: 49bytes
Requests per second: 49.98 [#/sec](mean)
Time per request: 20.008[ms] (mean)
Time per request: 20.008[ms] (mean, across all concurrent requests)
Transfer rate: 13.72[Kbytes/sec] received
20.55kb/s sent
34.26kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 1 0.0 1 1
Processing: 19 19 0.0 19 19
Waiting: 19 19 0.0 19 19
Total: 20 20 0.0 20 20
Copyright 1996 Adam Twiss, Zeus TechnologyLtd,
Licensed to The Apache SoftwareFoundation,
Benchmarking 192.168.1.36 (be patient).....done
Server Software:
Server Hostname:
Server Port:
Document Path:
Document Length:
Concurrency Level:
Time taken for tests:
Complete requests:
Failed requests:
Write errors:
Total transferred:
Total POSTed:
HTML transferred:
Requests per second:
Time per request:
Time per request:
Transfer rate:
Connection Times (ms)
Connect:
Processing:
Waiting:
Total:
ab -n1 -c1 -v4 -H'Content-Type: application/json' -p'test.json' 'http://192.168.1.36:8080/vtboss/service/account'
打印结果如下:
This is ApacheBench, Version 2.3 <$Revision: 655654$>
Copyright 1996 Adam Twiss, Zeus TechnologyLtd, http://www.zeustech.net/
Licensed to The Apache SoftwareFoundation, http://www.apache.org/
Benchmarking 192.168.1.36 (be patient)...INFO: POST header==
---
POST /vtboss/service/account HTTP/1.0
Content-length: 234
Content-type: text/plain
Content-Type: application/json
Host: 192.168.1.36:8080
User-Agent: ApacheBench/2.3
Accept: */*
---
LOG: header received:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=78D09B30C746498E328B1E3E BB40797E;Path=/vtboss
Content-Type: text/html;charset=UTF-8
Content-Length: 49
Date: Thu, 13 Nov 2014 09:30:26 GMT
Connection: close
{"id":0,"jsonrpc":"2.0","result":{"accounts":[]}}
LOG: Response code = 200
..done
Server Software: Apache-Coyote/1.1
Server Hostname: 192.168.1.36
Server Port: 8080
Document Path: /vtboss/service/account
Document Length: 49bytes
Concurrency Level: 1
Time taken for tests: 0.009seconds
Complete requests: 1
Failed requests: 0
Write errors: 0
Total transferred: 281bytes
Total POSTed: 421
HTML transferred: 49bytes
Requests per second: 107.72[#/sec] (mean)
Time per request: 9.283[ms] (mean)
Time per request: 9.283[ms] (mean, across all concurrent requests)
Transfer rate: 29.56[Kbytes/sec] received
44.29kb/s sent
73.85kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 1 0.0 1 1
Processing: 9 9 0.0 9 9
Waiting: 8 8 0.0 8 8
Total: 9 9 0.0 9 9
Copyright 1996 Adam Twiss, Zeus TechnologyLtd,
Licensed to The Apache SoftwareFoundation,
Benchmarking 192.168.1.36 (be patient)...INFO: POST header==
---
POST /vtboss/service/account HTTP/1.0
Content-length: 234
Content-type: text/plain
Content-Type: application/json
Host: 192.168.1.36:8080
User-Agent: ApacheBench/2.3
Accept: */*
---
LOG: header received:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=78D09B30C746498E328B1E3E
Content-Type: text/html;charset=UTF-8
Content-Length: 49
Date: Thu, 13 Nov 2014 09:30:26 GMT
Connection: close
{"id":0,"jsonrpc":"2.0","result":{"accounts":[]}}
LOG: Response code = 200
..done
Server Software:
Server Hostname:
Server Port:
Document Path:
Document Length:
Concurrency Level:
Time taken for tests:
Complete requests:
Failed requests:
Write errors:
Total transferred:
Total POSTed:
HTML transferred:
Requests per second:
Time per request:
Time per request:
Transfer rate:
Connection Times (ms)
Connect:
Processing:
Waiting:
Total:
(3)关注点
- 失败率
- 单个并发的平均响应时间