How to benchmark a webserver and save it as an image graph
Introduction
Sometimes you need to check how performant your webserver is when it comes to concurrent connections or high traffic. This script will benchmark one or many webservers and plot the results into an image.
Usage
Just save the script as benchmark.sh and run it. The script will ask you for one or more webservers to specify separated by comma.
Change tho total (how many connects to server) and concurrent (how many connects in parallel) variables if you need to.
The script
#!/bin/bash
# This script will benchmark one or many webservers and plot the results into an image.
total=1000
concurrent=10
#################################################################################
echo "Type the adresses of the webserver separated by comma followed by [ENTER]:"
while read webservers
do
what="$webservers"
if [ -z "${what}" ];
then
echo "You did not specify a webserver to benchmark!"
else
OIFS=$IFS
IFS=','
arr=$what
counter=0
echo "set terminal png" >> _temp.txt
echo "set output 'out.png'" >> _temp.txt
echo "set title 'Webserver Benchmark'" >> _temp.txt
echo "set size 1,1" >> _temp.txt
echo "set key left top" >> _temp.txt
echo "set grid y" >> _temp.txt
echo "set xlabel 'request'" >> _temp.txt
echo "set ylabel 'response time (ms)'" >> _temp.txt
plot="plot"
for x in $arr
do
echo "> Running benchmark for $x"
if [ "$counter" -gt 0 ];
then
plot=$plot","
fi
plot=$plot" 'benchmark_server_data_$counter.txt' using 10 smooth sbezier with lines title '$x'"
ab -n $total -c $concurrent -k -g benchmark_server_data_$counter.txt -H 'Accept-Encoding:gzip,deflate' $x
counter=$(( counter + 1 ))
done
IFS=$OIFS
echo $plot >> _temp.txt
gnuplot _temp.txt
rm _temp.txt
rm benchmark_server_data_*
exit
fi
done
Written by dhoffm
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#