Skip to content

Instantly share code, notes, and snippets.

@lavoiesl
Last active October 21, 2017 00:15
Show Gist options
  • Save lavoiesl/7536567 to your computer and use it in GitHub Desktop.
Save lavoiesl/7536567 to your computer and use it in GitHub Desktop.
Sysbench wrapper for several tests of sysbench
#!/usr/bin/env bash
# Sysbench wrapper for several tests of sysbench
# Scales with number of processors, works on mac and linux
#
# @link https://gist.github.com/lavoiesl/7536567
#
# wget https://gist.github.com/lavoiesl/7536567/raw/sysbench.sh -O - 2>/dev/null | bash
#
# Requires http://sysbench.sourceforge.net/
# Example output:
#
# TEST,THREADS,ARGS,TIME,EVENTS
# cpu,1,--cpu-max-prime=20000,10.0004,3866
# cpu,16,--cpu-max-prime=20000,10.0029,44192
# threads,64,--thread-yields=1000 --thread-locks=4,10.0792,4315
# mutex,1,,0.1457,1
# mutex,16,,0.3133,16
# fileio,1,--file-total-size=1G --file-test-mode=seqrd,10.0001,3173687
# fileio,16,--file-total-size=1G --file-test-mode=seqrd,10.0003,872910
# fileio,1,--file-total-size=1G --file-test-mode=rndrw,10.0001,573257
# fileio,16,--file-total-size=1G --file-test-mode=rndrw,10.0004,732223
#
# Total time: 46.0551s
if ! hash sysbench 2>/dev/null; then
echo "Missing sysbench: http://sysbench.sourceforge.net/" 2>&1
exit 1
fi
cpu_count() {
if hash nproc 2>/dev/null; then
nproc
elif hash sysctl 2>/dev/null; then
sysctl hw.ncpu | awk '{print $2}'
else
echo 1
fi
}
cpu="$(cpu_count)"
total_time=0.0
total_events=0
run_test() {
test=$1
shift
threads=$1
shift
args="$@"
echo -n "$test,$threads,$args,"
sysbench --num-threads=$threads $test $args prepare >/dev/null 2>/dev/null
sysbench --num-threads=$threads $test $args run > test.out
sysbench --num-threads=$threads $test $args cleanup >/dev/null 2>/dev/null
seconds=$(grep 'total time:' test.out | grep --color=never -oE '[0-9\.]+')
events=$(grep 'total number of events:' test.out | grep --color=never -oE '[0-9\.]+')
echo "${seconds},${events}"
total_time=$( echo "$total_time + $seconds" | bc )
total_events=$( echo "$total_events + $events" | bc )
}
run_test_multi() {
test=$1
shift
args="$@"
run_test $test 1 $args
if [[ "$cpu" -gt 1 ]]; then
run_test $test $cpu $args
fi
}
dir=$(mktemp -d /tmp/sysbench.XXXX)
cd $dir
echo "TEST,THREADS,ARGS,TIME,EVENTS"
run_test_multi cpu --cpu-max-prime=20000
run_test threads 64 --thread-yields=1000 --thread-locks=4
run_test_multi mutex
run_test_multi fileio --file-total-size=1G --file-test-mode=seqrd
run_test_multi fileio --file-total-size=1G --file-test-mode=rndrw
echo
echo "Total time: ${total_time}s"
cd
rm -R $dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment