Simple script to test website performance
This script is basically a simple wrapper around ab (apache bench), it's only value add is running a bunch of tests in a row, parsing out just the requests per second and caclulating an average across all runs. Simple script for a simple benchmark. The script doesn't verify the sanity of arguments provided to it, so if you're not sure, just use the command line in the example -- 100 reqs with concurrency of 50 -- good enough for a quick and dirty benchmark.
Example command line:
ak@hawk:~$ sudo ./ab.sh 10 100 50 http://giantdorks.org/
Output:
==================================================================
Results
==================================================================
site .......... http://giantdorks.org/
requests ...... 100
concurrency ... 50
------------------------------------------------------------------
run 1: 4028.36 reqs/sec
run 2: 4234.42 reqs/sec
run 3: 4280.27 reqs/sec
run 4: 4270.77 reqs/sec
run 5: 4080.47 reqs/sec
run 6: 4197.80 reqs/sec
run 7: 2265.78 reqs/sec
run 8: 4194.45 reqs/sec
run 9: 3858.47 reqs/sec
run 10: 4083.80 reqs/sec
------------------------------------------------------------------
average ....... 3949.46 requests/sec
see ab.giantdorks.org.log for details
Here's the script:
#!/bin/bash
if ! [ -x "$(type -P ab)" ]; then
echo "ERROR: script requires apache bench"
echo "For Debian and friends get it with 'apt-get install apache2-utils'"
echo "If you have it, perhaps you don't have permissions to run it, try 'sudo $(basename $0)'"
exit 1
fi
if [ "$#" -ne "4" ]; then
echo "ERROR: script needs four arguments, where:"
echo
echo "1. Number of times to repeat test (e.g. 10)"
echo "2. Total number of requests per run (e.g. 100)"
echo "3. How many requests to make at once (e.g. 50)"
echo "4. URL of the site to test (e.g. http://giantdorks.org/)"
echo
echo "Example:"
echo " $(basename $0) 10 100 50 http://giantdorks.org/"
echo
echo "The above will send 100 GET requests (50 at a time) to http://giantdorks.org. The test will be repeated 10 times."
exit 1
else
runs=$1
number=$2
concurrency=$3
site=$4
fi
log=ab.$(echo $site | sed -r 's|https?://||;s|/$||;s|/|_|g;').log
if [ -f $log ]; then
echo removing $log
rm $log
fi
echo "=================================================================="
echo " Results"
echo "=================================================================="
echo " site .......... $site"
echo " requests ...... $number"
echo " concurrency ... $concurrency"
echo "------------------------------------------------------------------"
for run in $(seq 1 $runs); do
ab -c$concurrency -n$number $site >> $log
echo -e " run $run: \t $(grep "^Requests per second" $log | tail -1 | awk '{print$4}') reqs/sec"
done
avg=$(awk -v runs=$runs '/^Requests per second/ {sum+=$4; avg=sum/runs} END {print avg}' $log)
echo "------------------------------------------------------------------"
echo " average ....... $avg requests/sec"
echo
echo "see $log for details"
3 Comments
1. Gregorio Ramirez replies at 10th May 2012, 10:14 am :
Thanks, the script works well. Do you have any tips on ab testing? Dos and dont’s?
2. Christian replies at 26th July 2012, 11:20 pm :
Nice, thanks for this. Great script.
3. RASG replies at 19th March 2015, 8:07 am :
very nice!!
thanks for posting
Leave a comment