How do I plot a histogram of response times from an ApacheBench output file using GNUPlot?

StackOverflow https://stackoverflow.com/questions/20356741

  •  28-08-2022
  •  | 
  •  

문제

I am running some benchmarking against a website I'm building and would like to produce graphs of the response times. Here's my ApacheBench usage:

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

This gives me a TSV file with data like so:

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

I'd like to convert this data to a histogram with quantity on the Y axis and response time (ttime) on the X axis.

My plot script is below but all I'm getting is an empty (zero byte) jpeg file.

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

set style fill solid border

plot 'foo.tsv' using 5
exit

How can I generate this histogram?


Bonus question. I realise this data might lead to many data points with one or two hits, so how can I round the ttime to, say, the nearest 10ms to give me fewer data points with more hits each?

도움이 되었습니까?

해결책 2

Several things:

  1. If you want to output a jpg file, you must use set terminal jpeg first. But in any case I would suggest you to use the pngcairo terminal, if you need a bitmap image.

  2. The tsv uses tabs as column separator. By default gnuplot uses any white space character as separator, in which case the fifth column is always 2013. So use set datafile separator '\t'.

  3. In order to have some binning, you must use smooth frequency with an appropriate binning function, which bins your x-values. As y-values I use 1, so that smooth frequency just counts up.

  4. Possibly you must skip the first line of your data file with every ::1.

  5. In your case I would use boxes plotting style:

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'

다른 팁

copy this into your .p file.

touch foo.p   
gedit foo.p  

now paste this data into that file and save it,

 # 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:"

now generate the plot file of the foo.p by ::

    gnuplot foo.p

I've summarized everything from this thread on this script:

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

Just chmod +x if necessary and run with ./fileName

I have developed a more complete set of helper scripts for apachebench results plotting, including merging of multiple test results, you can check them out here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top