概述
AB(ApacheBench)用来做http的压力测试。
ubuntu里安装ab测试工具
sudo apt-get install apache2-utils
测试命令
最常用的测试命令如下:
ab -n 100 -c 10 http://192.168.188.6:8080/distributeLock
-n表示请求数,-c表示并发数
带自定义header请求:
ab -n 1 -c 1 -H "Pragma:no-cache" http://192.168.188.6:8080/distributeLock
-H带header请求
模拟post请求
ab -n 1 -c 1 -p 'post.txt' -T 'application/x-www-form-urlencoded' http://192.168.188.6:8080/distributeLock2
-p 用来做post数据的文件,这里此文件保存在ab同级目录下
- T 设置content-type值
其它ab命令参数见官方网站.
测试结果分析
执行命令:
ab -n 100 -c 10 http://192.168.188.6:8080/distributeLock
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.188.6 (be patient).....done
// web服务器的信息
Server Software:
Server Hostname: 192.168.188.6
Server Port: 8080
Document Path: /distributeLock // 请求的URL
Document Length: 14 bytes // http响应正文长度
Concurrency Level: 10 // 并发请求数
Time taken for tests: 0.153 seconds //整个测试持续的时间
Complete requests: 100 // 完成的请求数
Failed requests: 0 //失败的请求数
Total transferred: 14700 bytes // 全部网络数据传输量
HTML transferred: 1400 bytes // 全部html正文数据量
Requests per second: 652.40 [#/sec] (mean) // 每秒请求数 == Complete requests / Time taken for tests
Time per request: 15.328 [ms] (mean) // 用户平均请求等待时间 == Time taken for tests / (Complete requests /Concurrency Level)
Time per request: 1.533 [ms] (mean, across all concurrent requests) // 服务器平均请求处理时间 == Time taken for tests / Complete requests
Transfer rate: 93.66 [Kbytes/sec] received //平均每秒网络上的流量 == Total transferred / Time taken for tests
// 连接的每个阶段花费的时间
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 4 2.9 3 10
Processing: 3 11 7.0 9 65
Waiting: 3 8 6.7 7 65
Total: 6 15 7.0 14 68
// 每个请求处理时间的分布情况
Percentage of the requests served within a certain time (ms)
50% 14
66% 15
75% 16
80% 17
90% 20
95% 22
98% 32
99% 68
100% 68 (longest request)