Skip to content

Instantly share code, notes, and snippets.

@dadvir
Forked from james2doyle/bench.sh
Last active November 30, 2021 10:24
Show Gist options
  • Save dadvir/a7fa93bb674f9d9b689e3f477a82f761 to your computer and use it in GitHub Desktop.
Save dadvir/a7fa93bb674f9d9b689e3f477a82f761 to your computer and use it in GitHub Desktop.
A website benchmarking script using Apache ab. This script hits a target with requests and then generates a small report for each case.
#!/usr/bin/env bash
# if you are testing a base url, you need a trailing slash
SITE="http://example.com/"
OUTFILE=${1:-output.txt}
new_line() {
echo -e "" >>$OUTFILE
}
divider() {
echo -e "\n====================================================================\n" >>$OUTFILE
}
on_complete() {
echo "\n\nBench Completed." >>$OUTFILE
echo "\n\nBench Completed."
}
run_test() {
let "total = $1*$2"
echo "$1 concurrent user doing $2 page hits"
echo "$1 concurrent user doing $2 page hits" >>$OUTFILE
new_line
ab -l -r -n $total -c $2 -k -H "Accept-Encoding: gzip, deflate" $SITE >>$OUTFILE
divider
sleep 3
}
touch $OUTFILE
echo "Benching: $SITE"
echo "Benching: $SITE" >$OUTFILE
new_line
run_test 10 10
run_test 30 20
run_test 90 30
run_test 200 50
run_test 2000 50
on_complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment