Skip to content

Instantly share code, notes, and snippets.

@mloberg
Created July 12, 2012 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mloberg/3099019 to your computer and use it in GitHub Desktop.
Save mloberg/3099019 to your computer and use it in GitHub Desktop.
Simple Load Test
#!/bin/sh
REQUEST="http://example.com"
NUM_REQ=100
CONCURENT=10
# Set up parallel processes (http://mlo.io/blog/2012/06/13/parallel-processes-in-bash.html)
mkfifo pipe
exec 3<>pipe
rm -rf pipe
i=0
while [[ "$i" -lt "$CONCURENT" ]]; do
{ sleep 5; echo >&3; } &
i=$(expr $i + 1)
done
PROCESSED=0
run_request() {
resp=$(curl -sL -w "%{http_code}" "$REQUEST" -o /dev/null)
if [[ "$resp" == "200" ]]; then
printf '.'
else
printf 'E'
fi
}
is_done() {
if [[ "$PROCESSED" -ge "$NUM_REQ" ]]; then
return 0
else
return 1
fi
}
while read; do
if [[ "$PROCESSED" -lt "$NUM_REQ" ]]; then
PROCESSED=$(expr $PROCESSED + 1)
if (run_request; echo >&3; is_done ); then
echo
echo "Done"
break
fi
fi
done <&3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment