Minor cleanup of bench.sh

* Check for `ab` and `curl` dependencies at the start
* Replace backticks with $() in bench()
* Print number of requests with thousands sep in info()
master
Nicolas Favre-Felix 1 year ago
parent 9a29a85a94
commit 6057a162f7
No known key found for this signature in database
GPG Key ID: C04E7AA8B6F73372

@ -1,4 +1,19 @@
#!/bin/bash #!/bin/bash
# check if ab and curl are installed
deps_ok=1
if [[ ! $(which ab) ]]; then
>&2 echo "ApacheBench (ab) is needed to run this benchmark."
deps_ok=0
fi
if [[ ! $(which curl) ]]; then
>&2 echo "curl is needed to run this benchmark."
deps_ok=0
fi
if [[ $deps_ok -eq 0 ]]; then
exit 1
fi
CLIENTS=100 CLIENTS=100
REQUESTS=100000 REQUESTS=100000
@ -9,7 +24,7 @@ PORT=$WEBDIS_PORT
[ -n $PORT ] && PORT=7379 [ -n $PORT ] && PORT=7379
info() { info() {
echo "Testing on $HOST:$PORT with $CLIENTS clients in parallel, for a total of $REQUESTS requests per benchmark." echo "Testing on $HOST:$PORT with $CLIENTS clients in parallel, for a total of $(printf "%'d" $REQUESTS) requests per benchmark."
} }
once() { once() {
@ -17,7 +32,7 @@ once() {
} }
bench() { bench() {
NUM=`ab -k -c $CLIENTS -n $REQUESTS http://$HOST:$PORT/$1 2>/dev/null | grep "#/sec" | sed -e "s/[^0-9.]//g"` NUM=$(ab -k -c $CLIENTS -n $REQUESTS http://$HOST:$PORT/$1 2>/dev/null | grep "#/sec" | sed -e "s/[^0-9.]//g")
echo -ne $NUM echo -ne $NUM
} }

Loading…
Cancel
Save