Commit f5ca4077 authored by Dishon Merkhai's avatar Dishon Merkhai Committed by Daniel Black

MDEV-30839: Add new options to mini-benchmark and fixes

Add new options to mini-benchmark.sh so it is more useful, such as
`--log` to avoid output from `lscpu` and other commands being lost.

Also fix following errors:

- Fix if condition for the cycle count regression verdict. The condition
  checked if the cycle count was greater than 850 billion, but `$RESULT`
  is only 3 digits and represents the number of cycles in billions.

- Fix flamegraph width. The original width caused the flamegraph to be
  cut-off on most screen sizes in the browser.

- Fix ShellCheck warnings and suggestions.

- Fix condition to check if perf has permission to run on the system.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.
parent 8c5db7a1
...@@ -10,6 +10,18 @@ display_help() { ...@@ -10,6 +10,18 @@ display_help() {
echo "regressions." echo "regressions."
echo echo
echo "optional arguments:" echo "optional arguments:"
echo " --name STRING identifier for the benchmark, added to the "
echo " folder name and (if --log is set) the log file "
echo " --threads \"STRING\" quoted string of space-separated integers "
echo " representing the threads to run."
echo " example: --threads \"1 32 64 128\""
echo " default: \"1 2 4 8 16\""
echo " --duration INTEGER duration of each thread run in seconds"
echo " default: 60"
echo " --workload STRING sysbench workload to execute"
echo " default: oltp_read_write"
echo " --log logs the mini-benchmark stdout/stderr into the"
echo " benchmark folder."
echo " --perf measure CPU cycles and instruction count in for " echo " --perf measure CPU cycles and instruction count in for "
echo " sysbench runs" echo " sysbench runs"
echo " --perf-flamegraph record performance counters in perf.data.* and" echo " --perf-flamegraph record performance counters in perf.data.* and"
...@@ -17,6 +29,12 @@ display_help() { ...@@ -17,6 +29,12 @@ display_help() {
echo " -h, --help display this help and exit" echo " -h, --help display this help and exit"
} }
# Default parameters
BENCHMARK_NAME='mini-benchmark'
THREADS='1 2 4 8 16'
DURATION=60
WORKLOAD='oltp_read_write'
while : while :
do do
case "$1" in case "$1" in
...@@ -28,6 +46,31 @@ do ...@@ -28,6 +46,31 @@ do
display_version display_version
exit 0 exit 0
;; ;;
--name)
shift
BENCHMARK_NAME+='-'
BENCHMARK_NAME+=$1
shift
;;
--threads)
shift
THREADS=$1
shift
;;
--duration)
shift
DURATION=$1
shift
;;
--workload)
shift
WORKLOAD=$1
shift
;;
--log)
LOG=true
shift
;;
--perf) --perf)
PERF=true PERF=true
shift shift
...@@ -47,6 +90,13 @@ do ...@@ -47,6 +90,13 @@ do
esac esac
done done
# Save results of this run in a subdirectory so that they are not overwritten by
# the next run
TIMESTAMP="$(date -Iseconds)"
mkdir "$BENCHMARK_NAME-$TIMESTAMP"
cd "$BENCHMARK_NAME-$TIMESTAMP" || exit 1
(
# Check that the dependencies of this script are available # Check that the dependencies of this script are available
if [ ! -e /usr/bin/pgrep ] if [ ! -e /usr/bin/pgrep ]
then then
...@@ -62,6 +112,7 @@ fi ...@@ -62,6 +112,7 @@ fi
# If there are multiple processes, assume the last one is the actual server and # If there are multiple processes, assume the last one is the actual server and
# any potential other ones were just part of the service wrapper chain # any potential other ones were just part of the service wrapper chain
# shellcheck disable=SC2005
MARIADB_SERVER_PID="$(echo "$(pgrep -f mariadbd || pgrep -f mysqld)" | tail -n 1)" MARIADB_SERVER_PID="$(echo "$(pgrep -f mariadbd || pgrep -f mysqld)" | tail -n 1)"
if [ -z "$MARIADB_SERVER_PID" ] if [ -z "$MARIADB_SERVER_PID" ]
...@@ -102,12 +153,13 @@ then ...@@ -102,12 +153,13 @@ then
echo "Ensure the MariaDB Server debug symbols are installed" echo "Ensure the MariaDB Server debug symbols are installed"
for x in $(ldd /usr/sbin/mariadbd | grep -oE " /.* ") for x in $(ldd /usr/sbin/mariadbd | grep -oE " /.* ")
do do
rpm -q --whatprovides --qf '%{name}' $x | cut -d : -f 1 rpm -q --whatprovides --qf '%{name}' "$x" | cut -d : -f 1
done | sort -u > mariadbd-dependencies.txt done | sort -u > mariadbd-dependencies.txt
# shellcheck disable=SC2046 # shellcheck disable=SC2046
debuginfo-install -y mariadb-server $(cat mariadbd-dependencies.txt) debuginfo-install -y mariadb-server $(cat mariadbd-dependencies.txt)
if [ ! $(perf record echo "testing perf" > /dev/null 2>&1) ] perf record echo "testing perf" > /dev/null 2>&1
if [ $? -ne 0 ]
then then
echo "perf does not have permission to run on this system. Skipping." echo "perf does not have permission to run on this system. Skipping."
PERF="" PERF=""
...@@ -120,7 +172,8 @@ elif [ -e /usr/bin/perf ] ...@@ -120,7 +172,8 @@ elif [ -e /usr/bin/perf ]
then then
# If flamegraphs were not requested, log normal perf counters if possible # If flamegraphs were not requested, log normal perf counters if possible
if [ ! $(perf stat echo "testing perf" > /dev/null 2>&1) ] perf stat echo "testing perf" > /dev/null 2>&1
if [ $? -ne 0 ]
then then
echo "perf does not have permission to run on this system. Skipping." echo "perf does not have permission to run on this system. Skipping."
PERF="" PERF=""
...@@ -156,28 +209,23 @@ mariadb -e " ...@@ -156,28 +209,23 @@ mariadb -e "
CREATE USER IF NOT EXISTS sbtest@localhost; CREATE USER IF NOT EXISTS sbtest@localhost;
GRANT ALL PRIVILEGES ON sbtest.* TO sbtest@localhost" GRANT ALL PRIVILEGES ON sbtest.* TO sbtest@localhost"
sysbench oltp_read_write prepare --tables=20 --table-size=100000 | tee sysbench-prepare.log sysbench "$WORKLOAD" prepare --tables=20 --table-size=100000 | tee sysbench-prepare.log
sync && sleep 1 # Ensure writes were propagated to disk sync && sleep 1 # Ensure writes were propagated to disk
# Save results of this run in a subdirectory so that they are not overwritten by
# the next run
TIMESTAMP="$(date -Iseconds)"
mkdir "mini-benchmark-$TIMESTAMP"
cd "mini-benchmark-$TIMESTAMP" || exit 1
# Run benchmark with increasing thread counts. The MariaDB Server will be using # Run benchmark with increasing thread counts. The MariaDB Server will be using
# around 300 MB of RAM and mostly reading and writing in RAM, so I/O usage is # around 300 MB of RAM and mostly reading and writing in RAM, so I/O usage is
# also low. The benchmark will most likely be CPU bound to due to the load # also low. The benchmark will most likely be CPU bound to due to the load
# profile, and also guaranteed to be CPU bound because of being limited to a # profile, and also guaranteed to be CPU bound because of being limited to a
# single CPU with 'tasksel'. # single CPU with 'tasksel'.
for t in 1 2 4 8 16 for t in $THREADS
do do
# Prepend command with perf if defined # Prepend command with perf if defined
# Output stderr to stdout as perf outpus everything in stderr # Output stderr to stdout as perf outputs everything in stderr
$PERF $TASKSET_SYSBENCH sysbench oltp_read_write run --threads=$t --time=60 --report-interval=10 2>&1 | tee sysbench-run-$t.log # shellcheck disable=SC2086
$PERF $TASKSET_SYSBENCH sysbench "$WORKLOAD" run --threads=$t --time=$DURATION --report-interval=10 2>&1 | tee sysbench-run-$t.log
done done
sysbench oltp_read_write cleanup --tables=20 | tee sysbench-cleanup.log sysbench "$WORKLOAD" cleanup --tables=20 | tee sysbench-cleanup.log
# Store results from 4 thread run in a Gitlab-CI compatible metrics file # Store results from 4 thread run in a Gitlab-CI compatible metrics file
grep -oE '[a-z]+:[ ]+[0-9.]+' sysbench-run-4.log | sed -r 's/\s+/ /g' | tail -n 15 > metrics.txt grep -oE '[a-z]+:[ ]+[0-9.]+' sysbench-run-4.log | sed -r 's/\s+/ /g' | tail -n 15 > metrics.txt
...@@ -197,10 +245,10 @@ then ...@@ -197,10 +245,10 @@ then
# Final verdict based on cpu cycle count # Final verdict based on cpu cycle count
RESULT="$(grep -h -e cycles sysbench-run-*.log | sort -k 1 | awk '{s+=$1}END{print s}')" RESULT="$(grep -h -e cycles sysbench-run-*.log | sort -k 1 | awk '{s+=$1}END{print s}')"
if [ "$RESULT" -gt 850000000000 ] if [ "$RESULT" -gt 850 ]
then then
echo # Newline improves readability echo # Newline improves readability
echo "Benchmark exceeded 8.5 billion cpu cycles, performance most likely regressed!" echo "Benchmark exceeded 850 billion cpu cycles, performance most likely regressed!"
exit 1 exit 1
fi fi
fi fi
...@@ -216,12 +264,12 @@ if [ "$PERF_RECORD" == true ] ...@@ -216,12 +264,12 @@ if [ "$PERF_RECORD" == true ]
then then
for f in perf.data.* for f in perf.data.*
do do
perf script -i $f | stackcollapse-perf.pl | flamegraph.pl --width 3000 > $f.svg perf script -i "$f" | stackcollapse-perf.pl | flamegraph.pl --width 1800 > "$f".svg
done done
echo "Flamegraphs stored in folder mini-benchmark-$TIMESTAMP/" echo "Flamegraphs stored in folder $BENCHMARK_NAME-$TIMESTAMP/"
fi fi
# Fallback if CPU cycle count not availalbe: final verdict based on peak QPS # Fallback if CPU cycle count not available: final verdict based on peak QPS
RESULT="$(sort -k 9 -h sysbench-run-*.log | tail -n 1 | grep -oE "qps: [0-9]+" | grep -oE "[0-9]+")" RESULT="$(sort -k 9 -h sysbench-run-*.log | tail -n 1 | grep -oE "qps: [0-9]+" | grep -oE "[0-9]+")"
case $RESULT in case $RESULT in
''|*[!0-9]*) ''|*[!0-9]*)
...@@ -240,3 +288,6 @@ case $RESULT in ...@@ -240,3 +288,6 @@ case $RESULT in
fi fi
;; ;;
esac esac
# Record the output into the log file, if requested
) 2>&1 | ($LOG && tee "$BENCHMARK_NAME"-"$TIMESTAMP".log)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment