Skip to content

Instantly share code, notes, and snippets.

@mloberg mloberg/gist:3099019
Created Jul 12, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.