#!/bin/bash path=$1 servers=$2 special=$3 N=5000 step=100 steps=10 ports_boa=80 ports_thttpd=81 ports_cherokee=82 ports_lighttpd=83 ports_nginx6=84 ports_apache1=85 ports_apache2=86 ports_nginx5=88 ports_lightspeed=89 comms_boa=boa comms_thttpd=thttpd comms_cherokee=cherokee comms_lighttpd=lighttpd comms_nginx5=nginx comms_nginx6=nginx comms_apache1=apache comms_apache2=apache2 comms_lightspeed=lshttpd group=`date +'%s'`; dotests=1; if [ "$servers" == '' ] ; then servers='boa cherokee lighttpd nginx5 apache1 apache2 thttpd lightspeed'; fi; if [ ! $path ] ; then path='.'; fi; function benchmark { eval port=\$ports_$1; eval comm=\$comms_$1; echo "Testing $1 ($comm) on port $port, take $2"; if [ ! $port ] ; then echo '$1 ?????'; return; fi; #sleep 5; echo -n "Warm-up ... "; ab -d -S -n 100 -c 2 http://localhost:$port/index.html 2>&1 > /dev/null echo "done"; echo "Benchmark: "; for (( c = 0 ; c <= steps ; c++ )) ; do C=$(( $step * $c )) if (( $C == 0 )) ; then C=1; fi; echo -n "$1 $N $C "; make3tests; get_memory_info $comm; echo "$rps $memory"; echo "$1 $N $C $rps $memory" >> $path/test.$group.bm done; # for (( c = C ; c < C*2; c += step )) ; do # sleep 1; # get_memory_info $comm; # echo "$1 $N $c 0 $memory"; # echo "$1 $N $c 0 $memory" >> $path/test.$group.bm # done; } function get_memory_info { comm=$1; mem=`ps -eo comm,rss,vsize 2>&1|grep $comm|awk '{RSS += $2; VSIZE += $3} END {print RSS " " VSIZE}'`; rss=`echo "$mem"|cut -f 1`; vsz=`echo "$mem"|cut -f 2`; fre=`cat /proc/meminfo |awk '/MemFree/ {print $2}'`; memory="$rss $vsz $fre"; } function make3tests { for take in 1 2 3; do rps[$take]=`ab $special -d -S -n $N -c $C http://localhost:$port/index.html 2>&1 | awk '/Requests per second:/ {printf("%d", $4)};'`; done; rps=`echo -e ${rps[1]}"\n"${rps[2]}"\n"${rps[3]}|sort -n|tail -n 2|head -n 1`; } function init { echo $1; if (( $1 == 'boa' )) ; then /etc/init.d/boa start; else /etc/init.d/boa stop; sleep .2; killall -q boa ; fi; if (( $1 == 'thttpd' )) ; then /etc/init.d/thttpd start; else /etc/init.d/thttpd stop; sleep .2; killall -q thttpd ; fi; if (( $1 == 'cherokee' )) ; then /etc/init.d/cherokee start; else /etc/init.d/cherokee stop; sleep .2; killall -q cherokee ; fi; if (( $1 == 'lighttpd' )) ; then /etc/init.d/lighttpd start; else /etc/init.d/lighttpd stop; sleep .2; killall -q lighttpd ; fi; if (( $1 == 'nginx5' )) ; then /etc/init.d/nginx.0.5.35 start; else /etc/init.d/nginx.0.5.35 stop; sleep .2; killall -q nginx ; fi; # if (( $1 == 'nginx6' )) ; then /etc/init.d/nginx.0.6.21 start; else /etc/init.d/nginx.0.6.21 stop; sleep .2; killall -q nginx ; fi; if (( $1 == 'apache1' )) ; then /etc/init.d/apache start; else /etc/init.d/apache stop; sleep .2; killall -q apache ; fi; if (( $1 == 'apache2' )) ; then /etc/init.d/apache2 start; else /etc/init.d/apache2 stop; sleep .2; killall -q apache2 ; fi; if (( $1 == 'lightspeed' )) ; then /etc/init.d/lsws start; else /etc/init.d/lsws stop; sleep .2; killall -q lshttpd ; fi; } if (( $dotests != 0 )); then init 'kill-them-all' 2>&1 > /dev/null; for srv in $servers; do init $srv 2>&1 > /dev/null; benchmark $srv $i; done; fi;