Skip to content

Instantly share code, notes, and snippets.

@davlgd
Last active November 14, 2021 08:40
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 davlgd/e7997df58eb637608e7c3f5e55855e8e to your computer and use it in GitHub Desktop.
Save davlgd/e7997df58eb637608e7c3f5e55855e8e to your computer and use it in GitHub Desktop.
Redis benchmark script
#!/bin/bash
REQUEST=5000000
SIZE=3
if [ $1 == "--help" ]
then
echo "Usage : ./rb.sh [requests] [block]"
echo
echo " requests : how many to use during performance testing (default : 5000000) "
echo " block : size in bytes, 1k, 4k or 100k (default : 3) "
echo
echo "Redis Benchmark from David Legrand distributed under MIT Licence"
echo "Script testing Redis server latency & performance."
echo
echo "Examples :"
echo
echo " ./rb.sh"
echo " ./rb.sh 4k"
echo " ./rb.sh 1000000 100k"
echo
exit 0
fi
[[ $1 -gt 3 ]] && REQUEST=$1
[[ $1 == "1k" || $2 == "1k" ]] && SIZE=1024
[[ $1 == "4k" || $2 == "4k" ]] && SIZE=4096
[[ $1 == "100k" || $2 == "100k" ]] && SIZE=102400
clear
echo "Memory bandwidth : $(sudo dmidecode -t 17 -q | grep -m 1 "Configured Memory Speed: [0-9]" | awk '{print substr($0, index($0,$4))}')"
echo "Requests number : $REQUEST"
echo "Block size : $SIZE bytes"
echo "Server latency : $(redis-cli --latency -i 15 --raw | awk '{print $3}') ms"
echo
redis-cli FLUSHALL > /dev/null
for PIPE in 1 2 4 8 16 32 64 128 256 512
do
if [[ ($1 == "100k" || $2 == "100k") && $PIPE -gt 8 ]]
then
exit 0
else
if [ $PIPE -gt 1 ]
then
LENGTH=$((30 + ${#PIPE}))
echo "Performances - PIPELINING ($PIPE) :"
for (( i=1; i<=$LENGTH; i++ )); do echo -n -; done
echo
else
echo "Performances"
echo "------------"
fi
sudo redis-benchmark -q -t get,set -n $REQUEST -d $SIZE -P $PIPE
redis-cli FLUSHALL > /dev/null
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment