Created
July 9, 2015 18:58
-
-
Save cirocosta/de576304f1432fad5b3a to your computer and use it in GitHub Desktop.
naive http server stress tester using cURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#### Default Configuration | |
CONCURRENCY=4 | |
REQUESTS=100 | |
ADDRESS="http://localhost:8080/" | |
show_help() { | |
cat << EOF | |
Naive Stress Test with cURL. | |
Usage: ./stress-test.sh [-a ADDRESS] [-c CONCURRENCY] [-r REQUESTS] | |
Params: | |
-a address to be tested. | |
Defaults to localhost:8080 | |
-c conccurency: how many process to spawn | |
Defaults to 1 | |
-r number of requests per process | |
Defaults to 10 | |
-h show this help text | |
Example: | |
$ ./stress-test.sh -c 4 -p 100 (400 requests to localhost:8080) | |
EOF | |
} | |
#### CLI | |
while getopts ":a:c:r:h" opt; do | |
case $opt in | |
a) | |
ADDRESS=$OPTARG | |
;; | |
c) | |
CONCURRENCY=$OPTARG | |
;; | |
r) | |
REQUESTS=$OPTARG | |
;; | |
h) | |
show_help | |
exit 0 | |
;; | |
\?) | |
show_help >&2 | |
echo "Invalid argument: $OPTARG" &2 | |
exit 1 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
#### Main | |
for i in `seq 1 $CONCURRENCY`; do | |
curl -s "$ADDRESS?[1-$REQUESTS]" & pidlist="$pidlist $!" | |
done | |
# Execute and wait | |
FAIL=0 | |
for job in $pidlist; do | |
echo $job | |
wait $job || let "FAIL += 1" | |
done | |
# Verify if any failed | |
if [ "$FAIL" -eq 0 ]; then | |
echo "SUCCESS!" | |
else | |
echo "Failed Requests: ($FAIL)" | |
fi | |
Nice script, small tip : add trap "kill 0" SIGINT
at the top to make sure that all curl requests are killed off if you cancel the stress test
Created a custom version that accepts different http methods and body request https://github.com/rodrigorodrigues/quarkus-vs-springboot-reactive-rest-api/blob/master/naive-stress-test.sh
./naive-stress-test.sh -c 1 -r 1 \
-a localhost:8080/api/companies \
-X POST \
-H "Authorization: bearer XXXX" \
-H "Content-Type: application/json" \
-d '{"name": "test curl - #INCREMENT_TIMESTAMP", "activated": true}'
Cheers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like gist still doesn't support pull-requests. These changes were helpful to me, maybe you could add them too?
https://gist.github.com/jddonovan/c423c7e5bc008df3c4b8e1424fefd504/revisions
Without /dev/null, it would output html sporadically.
Cheers!