Skip to content

Instantly share code, notes, and snippets.

@allgood2386
Last active December 14, 2015 19:18
Show Gist options
  • Save allgood2386/5135147 to your computer and use it in GitHub Desktop.
Save allgood2386/5135147 to your computer and use it in GitHub Desktop.
figuring out ab testing
#!/bin/bash
# This script will run a series of ab benchmarks and print them out to a files directory in a drupal site with the -w
# flag for easy web browser reading.
# Example usage:
# ./thisScript.sh -u 'ourpassword:todev' -d http://somedomain.com -o dir/towrite/to -f 'index/ something.php /content/node/xxxx'
while getopts u:d:o:f: option
do
case "${option}"
in
u) USER=${OPTARG};;
d) DOMAIN=${OPTARG};;
o) OUTDIR=${OPTARG};;
f) FILES=${OPTARG};;
esac
done
for FILE in "$FILES"
do
TARGETDOM=$DOMAIN\/$FILES\/
TARGETFILE=sed -e 's/\//\./g' $TARGETDOM
if [ ! -f $OUTDIR/$FILES.perf.html]; then
touch $OUTDIR/$FILES.perf.html
if [$? == 1]; then
echo 'Cannot create a file at the set path. Check file permissions or setsudo bit.'
exit 1
fi
fi
for i in 1 2 4 8 16 20 25
do
#todo: do set on the file output here, we need to replace / with . so that file names will work.
ab -A "$USER" -w -n 1000 -c $i $TARGETDOM >> $TARGETFILE.perf.html
echo "Writing to $OUTDIR/$FILES.perf.html"
done
done
@cpanayides
Copy link

Take $2 in as a filename instead of the site itself, have the user-generated file contain one item to check per line.

you can then change your script to read:

for i in cat $2;
do ab -A '$1' -w -n 1000 '$i' >> $3;
done

verify my syntax, this is really hack-ey. i removed the -c 1 because that's redundant, default is one at a time and the for loop causes it to run once per line in the file

@cpanayides
Copy link

if [$? == 1]

@cpanayides
Copy link

Try this:

for i in $2
do
touch $3.$i.html
if [$? ==1]
then
echo 'Cannot create a file at the set pach. Check file permissions or setsudo bit '
exit
else
ab -A '$1' -w -n 1000 -c 1 $i >> $3.$i.html
ab -A '$1' -w -n 1000 -c 2 $i >> $3.$i.html
ab -A '$1' -w -n 1000 -c 4 $i >> $3.$i.html
ab -A '$1' -w -n 1000 -c 8 $i >> $3.$i.html
ab -A '$1' -w -n 1000 -c 16 $i >> $3.$i.html
ab -A '$1' -w -n 1000 -c 20 $i >> $3.$i.html
ab -A '$1' -w -n 1000 -c 30 $i >> $3.$i.html
ab -A '$1' -w -n 1000 -c 40 $i >> $3.$i.html
fi
done

@joshuakfarrar
Copy link

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