2

我正在对我正在构建的网站进行一些基准测试,并希望生成响应时间的图表。这是我的 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 四舍五入到最近的 10 毫秒,以便给我更少的数据点和更多的点击?

4

4 回答 4

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
于 2014-01-30T06:56:39.070 回答
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绘图风格:

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'
于 2013-12-03T19:42:13.583 回答
1

我已经在这个脚本上总结了这个线程的所有内容:

#!/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 运行

于 2015-06-01T10:25:27.287 回答
0

我为 apachebench 结果绘图开发了一套更完整的帮助脚本,包括合并多个测试结果,你可以在这里查看它们。

于 2020-07-08T04:53:49.043 回答