You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.4 KiB
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
REQUESTS=100000
HOST=$WEBDIS_HOST
PORT=$WEBDIS_PORT
[ -n $HOST ] && HOST=127.0.0.1
[ -n $PORT ] && PORT=7379
info() {
echo "Testing on $HOST:$PORT with $CLIENTS clients in parallel, for a total of $(printf "%'d" $REQUESTS) requests per benchmark."
}
once() {
curl -q http://$HOST:$PORT/$1 1> /dev/null 2> /dev/null
}
bench() {
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
}
test_ping() {
echo -en "PING: "
bench "PING"
echo " requests/sec."
}
test_set() {
echo -en "SET(hello,world): "
bench "SET/hello/world"
echo " requests/sec."
}
test_get() {
echo -en "GET(hello): "
bench "GET/hello"
echo " requests/sec."
}
test_incr() {
once "DEL/hello"
echo -en "INCR(hello): "
bench "INCR/hello"
echo " requests/sec."
}
test_lpush() {
once "DEL/hello"
echo -en "LPUSH(hello,abc): "
bench "LPUSH/hello/abc"
echo " requests/sec."
}
test_lrange() {
echo -en "LRANGE(hello,$1,$2): "
bench "LRANGE/hello/$1/$2"
echo " requests/sec."
}
info
test_ping
test_set
test_get
test_incr
test_lpush
test_lrange 0 10
test_lrange 0 100