AB测试与结果绘图

最近在排查问题过程中,使用ab工具对一个线上系统做了一个简单压测。ab工具是Apache 出的一个http压测工具,具体使用可以参考网上很多教程,简单的使用如下:

ab -n 1000 -c 10 www.baidu.com/

输出:

Benchmarking www.google.com (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:        gws
Server Hostname:        www.google.com
Server Port:            80

Document Path:          /
Document Length:        384 bytes

Concurrency Level:      10
Time taken for tests:   4.295 seconds
Complete requests:      1000
Failed requests:        0
Non-2xx responses:      1000
Total transferred:      1074000 bytes
HTML transferred:       384000 bytes
Requests per second:    232.84 [#/sec] (mean)
Time per request:       42.948 [ms] (mean)
Time per request:       4.295 [ms] (mean, across all concurrent requests)
Transfer rate:          244.21 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       15   17   0.7     17      20
Processing:    22   26   6.6     25     129
Waiting:       22   26   6.6     25     128
Total:         37   43   6.7     42     145

Percentage of the requests served within a certain time (ms)
  50%     42
  66%     43
  75%     43
  80%     44
  90%     44
  95%     46
  98%     48
  99%     56
 100%    145 (longest request)

ab工具还可以将每个请求的耗时情况详细地输出到文件中,用于绘图直观表达:

ab -n 1000 -c 10 -g plot.dat www.baidu.com/

输出结果保存在plot.dat中。plot.dat文件中有六列,分别是
1. starttime 请求时间
2. seconds 请求时间戳
3. ctime 就是Connect时间,即tcp连接建立时间
4. dtime 就是Processing时间,即请求处理时间
5. ttime 就是total时间,即请求总耗时
6. wait 就是请求等待时间

使用gnuplot绘制plot.dat文件中到数据

先写一个绘图脚本gnuplot.script

# 设置输出结果为png图片
set terminal png size 600, 400
# 绘图保存在gnuplot.png中
set output 'gnuplot.png'
# 设置x坐标轴数据类型
set xdata time
# 时间数据格式
set timefmt "%s"
# 时间显示格式
set format x "%M %S"
set datafile separator "\t"
set xlabel 'time elapse(min second)'
set ylabel 'latancy(ms)'

plot "plot.dat" every ::2 using 2:6 with points

最后运行:

gunplot gunplot.script

生成gnuplot.png文件,copy到桌面系统上查看。

你可能感兴趣的:(工具使用)