Skip to content

Instantly share code, notes, and snippets.

@dlsniper
Last active December 12, 2015 03:28
Show Gist options
  • Save dlsniper/4707496 to your computer and use it in GitHub Desktop.
Save dlsniper/4707496 to your computer and use it in GitHub Desktop.
Simple benchmark for Symfony2

You should download each of the three versions of Symfony2 in /var/www/benchmark/sf2<X> where <X> is the minor version. Then

chmod +x benchmark.sh
sudo ./benchmark.sh

AB output for each run will be found in /var/www/benchmark/results/

Note

This was tested only with Ubuntu 12.10, your folders/URLs may vary

Also, I didn't want to push this to hardware limits as this shouldn't be a question of how many but rather how fast. If it's fast enough, the rest will follow.

Sleeps are there to allow for your hardware/CPU to catch its breath, this really is not a hardware test :)

#!/bin/bash
benchmarkPath="/var/www/benchmark"
benchmarkURLPrefix="http://localhost/benchmark"
if [ "$(id -u)" != "0" ]; then
echo "Sorry, you are not root."
exit 1
fi
if [ ! -d "${benchmarkPath}" ]; then
echo "Can't seem to find ${benchmarkPath}"
exit 1
fi
mkdir -p "${benchmarkPath}/results"
echo "Running benchmark...";
for sfId in $(find ${benchmarkPath} -maxdepth 1 -mindepth 1 -type d -iname 'sf2*')
do
sfId=$(basename ${sfId})
url="${benchmarkURLPrefix}/${sfId}/web/app.php"
sfCachePath="${benchmarkPath}/${sfId}/app/cache/prod"
sfLogPath="${benchmarkPath}/${sfId}/app/logs/prod.log"
for runId in {1..5}
do
echo "Stopping Apache"
service apache2 stop
echo "Clearing Apache log files..."
echo "" > /var/log/apache2/access.log
echo "" > /var/log/apache2/error.log
echo "Clearing Symfony2 files..."
rm -rf ${sfCachePath}
echo "" > ${sfLogPath}
sleep 10
echo "Starting Apache"
service apache2 start
echo "Perform warm-up for Symfony cache"
wget ${url} -O /dev/null
sleep 10
echo "URL: ${url} run: ${runId}/5"
ab -c 10 -n 100000 ${url} >> ${benchmarkPath}/results/sf2${sfId}.run${runId}.txt
echo "Log file: ${benchmarkPath}/results/sf2${sfId}.run${runId}.txt"
sleep 60
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment