Skip to content

Instantly share code, notes, and snippets.

@bruntonspall
Created January 20, 2011 15:43
Show Gist options
  • Save bruntonspall/788067 to your computer and use it in GitHub Desktop.
Save bruntonspall/788067 to your computer and use it in GitHub Desktop.
How I run perf tests repeatably with records of what I did
#!/bin/bash
#Set Defaults
requests=${requests:=10}
threads=${threads:=1}
url=${url:=http://testserver/}
while getopts "r:t:u:h" Option
do
case $Option in
r ) requests=$OPTARG;;
t ) threads=$OPTARG;;
u ) url=$OPTARG;;
h ) help=1;;
* ) echo "Unimplemented option chosen.";;
esac
done
shift $(($OPTIND - 1))
if [ ${help:-0} -eq 1 ]; then
echo "Test Runner"
echo ""
echo "-r num Number of Requests"
echo "-t num Number of Threads"
echo "-u url Url to test"
echo ""
exit 1
fi
run=$(cat lastrun.txt)
((run+=1))
echo -n "Run Description: "
read description
mkdir $run
echo "Starting test run: $run" | tee -a $run/settings.txt
echo "Date: $(date)" | tee -a $run/settings.txt
echo "Description: $description" | tee -a $run/settings.txt
echo "Parameters:" | tee -a $run/settings.txt
echo " Requests: $requests" | tee -a $run/settings.txt
echo " Threads: $threads" | tee -a $run/settings.txt
echo " Url: $url" | tee -a $run/settings.txt
echo "" | tee -a $run/settings.txt
ssh root@testserver "service squid stop; rm -Rf /var/spool/squid/*; service squid start"
ab -n $requests -c $threads -e $run/data.csv -g $run/data.gnuplot $url | tee $run/ablog.txt
echo $run > lastrun.txt
git add lastrun.txt
git add $run
git commit -m "Executed run $run"
git push
@bruntonspall
Copy link
Author

Some nice features:

  1. Uses apachebench (only a single url, but that's fine for an ad-hoc test)
  2. Stores information about each test run in $run/settings.txt so I can go back and find out how many threads and requests i configured
  3. Automatically generates a new number for each run
  4. Adds and commits the results files into git and pushes, so I can plot them on my laptop easily
  5. Multiple ways of specifying options:
    threads=20 ./runtest.sh
    ./runtest.sh -t 20

Please note that apachebench is useful for testing throughput and concurrency, but because it hits only a single url repeatedly it should be blazingly fast with a cache.
Also remember to re-initialise things inbetween tests, note that we restart squid between tests

Hope it helps someone

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