Linux下 安装ab测试工具
$ yum -y install httpd-tools
$ ab -n 1 -c 1 http://localhost:18002/
$ ab -H 'authenticate: 111' -n 1 -c 1 http://192.168.0.4:18002/lottery
请求URL要使用双引号括起来,否则ab无法识别&符号
-n:总请求次数(最小默认为1)
-c:并发次数(最小默认为1且不能大于总请求次数,如:100个请求,10个并发,实际就是1人请求10次)
-p:post参数文档路径(-p和-T参数要配合使用)
-T:header头内容类型(此处切记是大写英文字母T)
$ ab -H 'authenticate: 111' -n 1 -c 1 -p ab_post.json -T application/json http://192.168.0.246:8092/lottery
{
"scence":"room",
"scence_id":605021,
"times":1
}
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
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).....done
Server Software:
Server Hostname: localhost
Server Port: 18002
#请求的资源
Document Path: /
#文档返回的长度,不包括相应的头
Document Length: 5 bytes
#并发数 等于 -c 设置的值
Concurrency Level: 10
#总请求时长
Time taken for tests: 0.073 seconds
#总请求数 等于 -n 设置的值
Complete requests: 10
#失败的请求数
Failed requests: 0
#错误
Write errors: 0
#总共传输数据量
Total transferred: 2780 bytes
HTML transferred: 50 bytes
#平均每秒的请求数,重要指标:相当于LR中的每秒事务数,后面的括号中mean表示这是一个平均值
Requests per second: 137.41 [#/sec] (mean)
#平均每个请求消耗的时间,重要指标:LR中的平均事务响应时间
Time per request: 72.773 [ms] (mean)
#上面的请求除以并发数,即服务器平均请求响应时间 在并发量为1时 用户等待时间相同
Time per request: 7.277 [ms] (mean, across all concurrent requests)
#平均每秒多少K,即传输速率
Transfer rate: 37.31 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 8 36 20.8 41 65
Waiting: 7 36 20.9 41 65
Total: 8 36 20.8 41 65
Percentage of the requests served within a certain time (ms)
50% 41 #50%的请求都在41ms内完成
66% 48
75% 54
80% 59
90% 65
95% 65
98% 65
99% 65
100% 65 (longest request)