Skip to content

Instantly share code, notes, and snippets.

@garethrees
Last active January 14, 2024 23:21
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save garethrees/7356890 to your computer and use it in GitHub Desktop.
Save garethrees/7356890 to your computer and use it in GitHub Desktop.
Graphing apache benchmark results with gnuplot
# Output to a jpeg file
set terminal jpeg size 1280,720
# Set the aspect ratio of the graph
set size 1, 1
# The file to write to
set output "timeseries.jpg"
# The graph title
set title "Benchmark testing"
# Where to place the legend/key
set key left top
# Draw gridlines oriented on the y axis
set grid y
# Specify that the x-series data is time data
set xdata time
# Specify the *input* format of the time data
set timefmt "%s"
# Specify the *output* format for the x-axis tick labels
set format x "%S"
# Label the x-axis
set xlabel 'seconds'
# Label the y-axis
set ylabel "response time (ms)"
# Tell gnuplot to use tabs as the delimiter instead of spaces (default)
set datafile separator '\t'
# Plot the data
plot "out.dat" every ::2 using 2:5 title 'response time' with points
$ ab -n 1000 -c 10 -g out.dat http://example.com/
@hpwxf
Copy link

hpwxf commented Jun 19, 2018

I suggest you rescale x time value to 0 using the following command at the beginning (nb 'set data separator' has been moved to the beginning)

# Tell gnuplot to use tabs as the delimiter instead of spaces (default)
set datafile separator '\t'
# First stats file to extract min time value
# (must be done before setting that x will be a time data series)
stats "out.dat" every ::2 using 2 prefix "A"

and a final plot using

# Plot the data with an x-origin at 0
plot "out.dat" every ::2 using ($2-A_min):5 title 'response time' with points

@hpwxf
Copy link

hpwxf commented Jun 19, 2018

I suggest another proposal to counter-balance not ordered in ab data.

# Tell gnuplot to use tabs as the delimiter instead of spaces (default)
set datafile separator '\t'

# output as png image
set terminal png

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

# The graph title
set title "HTTP Benchmark"

# Where to place the legend/key
set key right bottom

# x-axis label
set xlabel "seconds"
set grid x
set logscale x

# y-axis label
set ylabel "% of completed requests"
set grid y
set format y '%2.0f%%'

stats "out.dat" every ::2 using 5 prefix "A"
# data must be sort according to their value (default order has a bias due to late request are obviously long)
# column 9 in sort is equivalent to 5 with a tabulated separated data
plot '<(tail -n +2 out.dat | sort -n -k 9)' every ::2 using 5:(100*$0/A_records) smooth sbezier with lines t '% of request done before time'

@ahoulgrave
Copy link

Seconds are not looking ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment