#!/bin/bash target="root@mouse" site="http://test.mouse/" #site="http://test.mouse/install.php?profile=default" out="$1" if [ -z "$out" ]; then printf "Pass path/to/filename for report as first argument\n" exit fi environments="prefork_mod_php itk_mod_php worker_suexec_fcgid prefork_suphp worker_suphp" function create_environment() { env="$1" if [ "$env" = "prefork_mod_php" ]; then ssh "$target" "a2dissite test.mouse.suexec.fcgid test.mouse.itk; a2ensite test.mouse" ssh "$target" "aptitude install -y apache2-mpm-prefork libapache2-mod-php5; a2dismod suphp; a2enmod php5;" fi if [ "$env" = "prefork_suphp" ]; then ssh "$target" "a2dissite test.mouse.suexec.fcgid test.mouse.itk; a2ensite test.mouse" ssh "$target" "aptitude install -y apache2-mpm-prefork; a2enmod suphp; a2dismod php5" fi if [ "$env" = "worker_suphp" ]; then ssh "$target" "a2dissite test.mouse.suexec.fcgid test.mouse.itk; a2ensite test.mouse" ssh "$target" "aptitude install -y apache2-mpm-worker; a2enmod suphp; a2dismod php5" fi if [ "$env" = "worker_suexec_fcgid" ]; then ssh "$target" "a2ensite test.mouse.suexec.fcgid; a2dissite test.mouse.itk test.mouse" ssh "$target" "aptitude install -y apache2-mpm-worker; a2dismod suphp; a2dismod php5" fi if [ "$env" = "itk_mod_php" ]; then ssh "$target" "a2ensite test.mouse.itk; a2dissite test.mouse.suexec.fcgid test.mouse" ssh "$target" "aptitude install -y apache2-mpm-itk libapache2-mod-php5; a2dismod suphp; a2enmod php5" fi ssh "$target" "/etc/init.d/apache2 restart" } function get_load() { load=$(ssh $target "w" | grep "load average:" | awk {'print $8}' | tr -d ,) } function benchmark() { env="$1" get_load printf "load pre test: %s (%s)\n" "$load" "$env" >> "$temp/load" tests="1:1 20:5 50:10 70:10" for test in $tests; do echo "Sleeping 30 seconds" sleep 30 requests=$(printf "%s" "$test" | cut -d: -f1) concurrent=$(printf "%s" "$test" | cut -d: -f2) ab -n "$requests" -c "$concurrent" "$site" | egrep "(Requests per second|across all concurrent requests)" | while read line; do if [[ "$line" =~ "Requests" ]]; then ext="r.p.s" else ext="t.p.r" fi printf "%s : %s\n" "$line" "$env" >> "$temp/$test.$ext" done done get_load printf "load post test: %s (%s)\n" "$load" "$env" >> "$temp/load" } temp=$(mktemp -d) for env in $environments; do printf "Creating environment %s\n" "$env" create_environment $env; printf "Sleeping for 120 seconds to give server a chance to settle down\n" sleep 120 printf "Benchmarking...\n" benchmark $env done # print report head "$temp/"* > $out rm -rf "$temp" printf "\n" printf "Report saved: %s\n" "$out" printf "\n"