如何使用GNUPlot从ApacheBench输出文件中绘制响应时间的直方图?

时间:2013-12-03 16:40:06

标签: gnuplot histogram apachebench

我正在针对我正在构建的网站运行一些基准测试,并希望生成响应时间的图表。这是我的ApacheBench用法:

> ab -n 100 -c 10 -g foo.tsv http://foo/

这给了我一个包含如下数据的TSV文件:

starttime                   seconds         ctime    dtime  ttime   wait
Tue Dec 03 16:24:53 2013    1386087893      2        413    415     367
Tue Dec 03 16:24:49 2013    1386087889      1        468    469     452
Tue Dec 03 16:24:54 2013    1386087894      9        479    488     446
Tue Dec 03 16:24:49 2013    1386087889      1        497    498     437
Tue Dec 03 16:24:54 2013    1386087894      33       465    498     458
Tue Dec 03 16:24:53 2013    1386087893      1        507    508     506
Tue Dec 03 16:24:51 2013    1386087891      0        544    544     512

我想将此数据转换为Y轴上的数量和X轴上的响应时间(ttime)的直方图。

我的剧情剧本如下,但我得到的是一个空的(零字节)jpeg文件。

clear
reset
set output "out.jpg"
# Select histogram data
set style data histogram

set style fill solid border

plot 'foo.tsv' using 5
exit

如何生成此直方图?


奖金问题。我意识到这些数据可能导致许多数据点有一次或两次点击,那么如何将ttime舍入到最接近的10ms以便为每个点数更多的数据点提供更少的数据点?

4 个答案:

答案 0 :(得分:5)

将其复制到.p文件中。

touch foo.p   
gedit foo.p  

现在将此数据粘贴到该文件中并保存,

 # output as png image
 set terminal png

 # save file to "benchmark.png"
 set output "benchmark.png"

 # graph a title
 set title "ab -n 100 -c 10 -g foo.tsv http://foo/"

 # nicer aspect ratio for image size
 set size 1,0.7

 # y-axis grid
 set grid y

 # x-axis label
 set xlabel "request"

 # y-axis label
 set ylabel "response time (ms)"

 # plot data from "foo.tsv" using column 9 with smooth sbezier lines
 plot "foo.tsv" using 9 smooth sbezier with lines title "server1:"

现在通过::

生成foo.p的绘图文件
    gnuplot foo.p

答案 1 :(得分:3)

有几件事:

  1. 如果要输出jpg文件,必须先使用set terminal jpeg。但无论如何,如果您需要位图图像,我建议您使用pngcairo终端。

  2. tsv使用制表符作为列分隔符。默认情况下,gnuplot使用任何空格字符作为分隔符,在这种情况下,第五列始终为2013。因此,请使用set datafile separator '\t'

  3. 为了进行一些分箱,您必须使用smooth frequency并使用适当的分箱功能,这会将您的x值加起来。作为y值,我使用1,因此smooth frequency只会计算在内。

  4. 您可能必须使用every ::1跳过数据文件的第一行。

  5. 在您的情况下,我会使用boxes绘图风格:

  6. set terminal pngcairo
    set output 'foo.png'
    set datafile separator '\t'
    set style fill solid border
    set boxwidth 8 absolute
    set yrange [0:*]
    bin(x) = 10*floor(x/10.0)
    plot 'foo.tsv' using (bin($5)):(1) every ::1 smooth frequency with boxes title 'ttime'
    

答案 2 :(得分:0)

我在这个剧本中总结了这个帖子的所有内容:

#!/bin/bash

#URL to test
URL_ATAQUE="http://foo.bar"
#Results file
FICH_RESULT="resultados.tsv"
#Plot
IMAGEN_RESULT="grafica.png"

echo -e "Executing bench on $URL_ATAQUE\nPlease, wait..."

#Sintaxis: 
#-n = Number of requests
#-c = simult. connections
#-g = output file
ab -n 5 -c 1 -g $FICH_RESULT $URL_ATAQUE

touch $FICH_RESULT

echo "set terminal png" > plot
echo "set output \"$IMAGEN_RESULT\"" >>plot
echo "set title \"$URL_ATAQUE\"" >>plot
echo "set size 1,0.7" >>plot
echo "set grid y" >> plot
echo "set xlabel \"Request\"" >> plot
echo "set ylabel \"Response time (ms)\"" >> plot
echo "plot \"$FICH_RESULT\" using 9 smooth sbezier with lines title \"server1:\"" >>plot

gnuplot plot

rm plot
rm $FICH_RESULT

gnome-open $IMAGEN_RESULT
#USE BELOW IF NOT IN GNOME
#xdg-open $IMAGEN_RESULT

如果需要,只需chmod + x并使用./fileName

运行

答案 3 :(得分:0)

我为apachebench结果绘图开发了一套更完整的帮助程序脚本,包括合并多个测试结果,您可以将它们检出here