Skip to content

Instantly share code, notes, and snippets.

@japaz
Created June 7, 2012 14:53
Show Gist options
  • Save japaz/2889219 to your computer and use it in GitHub Desktop.
Save japaz/2889219 to your computer and use it in GitHub Desktop.
Web Server Stress Testing with Curl
%{url_effective},%{http_code},%{content_type},%{time_total},%{time_connect},%{time_starttransfer},%{size_download}\n
#!/bin/bash
# from http://www.abcseo.com/tech/ezstress
# kill all subshell processes
killall() {
kill $(ps | grep '/sh$' | tr -s ' \t' ',' | cut -d',' -f 2) > /dev/null 2>&1
exit
}
shuf_urllist() {
cat urllist.txt | while read f ; do printf "%05d %s\n" "$(( $RANDOM % 100000 ))" "$f"; done | sort -n | cut -c7-
}
trap killall INT TERM EXIT
# check we have the number of users, iterations and output file for results
if [[ $# -ne 4 ]]
then
echo "Usage: $0 <users to run> <iterations> <time in seconds: -1 for ever> <output file>"
exit 1
fi
users=$1
iterations=$2
time=$3
file=$4
if [[ $time -eq -1 ]]
then
echo "running with $users user for $iterations iterations"
else
echo "running with $useris user for $iterations iterations and maximum time $time seconds"
fi
# start users as sub processes
echo -n "started " > $file
date >> $file
for ((j=1;j<=$users;j++))
do
(
echo "starting user $j"
for ((i=1;i<=$iterations;i++))
do
echo $PID
shuf_urllist | while read url
do
curl -s --max-time 30 -e "EzStress Tool User $i" -o /dev/null -w @logformat.txt --url $url >> $file
seconds=$(( $RANDOM %10 ))
sleep $seconds
done
done
)&
done
if [[ $time -eq -1 ]]
then
wait
else
sleep $time
killall
fi
echo -n "done " >> $file
date >> $file
http://lv236:81/portal/site/bdenred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment