Benutzer-Werkzeuge

Webseiten-Werkzeuge


mysql_-_benchmark

Dies ist eine alte Version des Dokuments!


MySQL - Benchmark

mit vielen kleinen INSERTs

hiermit werden 10 Prozesse gestartet, von denen jeder 100000 Datensätze in eine Test-Tabelle schreibt:

> ~/bin/MySQL-Test.sh localhost 3306 10 100000
Es werden in 10 Tabellen jeweils 100000 Datensätze eingetragen.
Laufzeit: 28 Sekunden

hiermit werden 100 Prozesse gestartet, von denen jeder 10000 Datensätze in eine Test-Tabelle schreibt:

> ~/bin/MySQL-Test.sh localhost 3306 100 10000
Es werden in 100 Tabellen jeweils 10000 Datensätze eingetragen.
Laufzeit: 22 Sekunden

das ist nicht genau, aber es liefert Anhaltspunkte

~/bin/MySQL-Test.sh
#!/bin/sh
 
 
#==============================================================================#
 
#VERSION="v2022022200"          # universell umgebaut
VERSION="v2022022300"           # universell umgebaut
 
 
if [ "x${4}" = x ] ; then
        echo "${0} [Hostname] [Port] [Threads] [Inserts]"
        echo "${0} 127.0.0.1 3306 8 100000"
        echo "${0} localhost 3306 8 100000"
        exit 10
else
        MYSQL_HOST="${1}"
        MYSQL_PORT="${2}"
        THREADS="${3}"          # 2 4 5 6 7 8 16 32 64 128 256 512
        REQUESTS="${4}"         # 100000
fi
 
#==============================================================================#
 
#------------------------------------------------------------------------------#
 
MYSQL_USR=root                  # Voreinstellung: sbtest
MYSQL_PWD="$(echo Z2VoZWltCg== | base64 -d)"
MYSQL_DB=mytest                   # Voreinstellung: sbtest
 
echo "
START TRANSACTION;
DROP DATABASE IF EXISTS ${MYSQL_DB};
CREATE DATABASE IF NOT EXISTS ${MYSQL_DB};
COMMIT;
" | mysql -h${MYSQL_HOST} -P${MYSQL_PORT} -u${MYSQL_USR} -p${MYSQL_PWD}
 
#------------------------------------------------------------------------------#
 
#set -x
 
START_ZEIT="$(date -u +'%s')"
 
for i in $(seq 1 ${THREADS})
do
        echo "
        START TRANSACTION;
        CREATE TABLE ${MYSQL_DB}.tabelle${i} (
        spalte01 VARCHAR(255) default NULL,
        PRIMARY KEY (spalte01)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
        COMMIT;
        " | mysql -h${MYSQL_HOST} -P${MYSQL_PORT} -u${MYSQL_USR} -p${MYSQL_PWD} ${MYSQL_DB}
        echo "SELECT * FROM ${MYSQL_DB}.tabelle${i};" | mysql -h${MYSQL_HOST} -P${MYSQL_PORT} -u${MYSQL_USR} -p${MYSQL_PWD}
 
        (
        date > /tmp/${MYSQL_DB}.tabelle${i}
        for A in $(seq 1 ${REQUESTS})
        do
                echo "INSERT INTO  ${MYSQL_DB}.tabelle${i} (spalte01) VALUES ('${A}');"
        done | taskset --cpu-list 0-8 mysql -h${MYSQL_HOST} -P${MYSQL_PORT} -u${MYSQL_USR} -p${MYSQL_PWD} ${MYSQL_DB}
        rm -f /tmp/${MYSQL_DB}.tabelle${i}
        ) &
done
 
echo "Es werden in ${THREADS} Tabellen jeweils ${REQUESTS} Datensätze eingetragen."
#echo "echo \"SHOW PROCESSLIST;\" | mysql -h${MYSQL_HOST} -P${MYSQL_PORT} -u${MYSQL_USR} -p${MYSQL_PWD} -t"
 
WARTEN="$(ls /tmp/${MYSQL_DB}.tabelle* 2>/dev/null | wc -l)"
while [ 0 -lt ${WARTEN} ]
do
        WARTEN="$(ls /tmp/${MYSQL_DB}.tabelle* 2>/dev/null | wc -l)"
        sleep 0.2
done
 
STOP_ZEIT="$(date -u +'%s')"
echo "Laufzeit: $(echo "${START_ZEIT} ${STOP_ZEIT}" | awk '{print $2 - $1}') Sekunden"

sysbench

Sysbench ist ungeeignet um die Leistung einer bestehenden Datenbank zu testen!

Anwendungsbeispiel

Leistungsdaten der Datenbank ermitteln:

~/bin/MySQL-Benchmark.sh

Ergebnisse ansehen:

less /tmp/sysbench_*.log

Am Ende sollte man die Datenbank wieder löschen,
zum Beispiel so:

echo "DROP DATABASE test;" | mysql -P3306 -uroot -pgeheim

ab Ubuntu 18.04 LTS

~/bin/MySQL-Benchmark.sh
#!/bin/sh
 
 
#==============================================================================#
 
VERSION="v2021041400"           # universell umgebaut
 
 
if [ "x${2}" = x ] ; then
        echo "${0} [Hostname] [Port]"
        echo "${0} 127.0.0.1 3306"
        exit 10
else
        MYSQL_HOST="${1}"
        MYSQL_PORT="${2}"
fi
 
#==============================================================================#
 
#------------------------------------------------------------------------------#
 
MYSQL_USR=root                  # Voreinstellung: sbtest
MYSQL_PWD="$(echo Z2VoZWltCg== | base64 -d)"
MYSQL_DB=test                   # Voreinstellung: sbtest
MAX_REQUESTS=10000
MAX_TIME=120
 
DIE_TESTS="cpu memory threads mutex"
THREADS="2 4 6 8 16 32 64 128 256 512"
 
#------------------------------------------------------------------------------#
 
for TEST in ${DIE_TESTS}
do
        echo "================================================================================"
        for i in ${THREADS}
        do
                #AUSGABE="$(sysbench --num-threads=${i} --max-requests=${MAX_REQUESTS} --max-time=${MAX_TIME} --mysql-host=${MYSQL_HOST} --mysql-db=${MYSQL_DB} --mysql-port=${MYSQL_PORT} --mysql-user=${MYSQL_USR} --mysql-password=${MYSQL_PWD} --test=${TEST} run)"
                #echo "sysbench --threads=${i} --events=${MAX_REQUESTS} --time=${MAX_TIME} --mysql-host=${MYSQL_HOST} --mysql-db=${MYSQL_DB} --mysql-port=${MYSQL_PORT} --mysql-user=${MYSQL_USR} --mysql-password=${MYSQL_PWD} ${TEST} run"
                AUSGABE="$(sysbench --threads=${i} --events=${MAX_REQUESTS} --time=${MAX_TIME} --mysql-host=${MYSQL_HOST} --mysql-db=${MYSQL_DB} --mysql-port=${MYSQL_PORT} --mysql-user=${MYSQL_USR} --mysql-password=${MYSQL_PWD} ${TEST} run)"
 
                if [ "memory" = "${TEST}" ] ; then
                        echo "${AUSGABE}" | egrep '^### threads=| transferred ' | awk -F"[()]" -v threads=${i} -v test=${TEST} '{print test,"/",threads,"threads / transferred:",$2}'
                elif [ "threads" = "${TEST}" ] ; then
                        echo "${AUSGABE}" | egrep '^### threads=|execution time' | awk -v threads=${i} -v test=${TEST} '{gsub("/"," ");print test,"/",threads,"threads / execution time:",$(NF-1)}'
                else
                        #echo "${AUSGABE}" | egrep '^### threads=|approx.  95 percentile:' | awk -v threads=${i} -v test=${TEST} '{print test,"/",threads,"threads / Laufzeit von 95%:",$NF}'
                        echo "${AUSGABE}" | egrep '^### threads=|95th percentile:' | awk -v threads=${i} -v test=${TEST} '{print test,"/",threads,"threads / Laufzeit von 95%:",$NF}'
                fi
        done
done
# time /root/bin/MySQL-Benchmark.sh 127.0.0.1 3321
================================================================================
cpu / 2 threads / Laufzeit von 95%: 0.94
cpu / 4 threads / Laufzeit von 95%: 0.94
cpu / 6 threads / Laufzeit von 95%: 0.94
cpu / 8 threads / Laufzeit von 95%: 0.95
cpu / 16 threads / Laufzeit von 95%: 1.23
cpu / 32 threads / Laufzeit von 95%: 17.32
cpu / 64 threads / Laufzeit von 95%: 25.28
cpu / 128 threads / Laufzeit von 95%: 44.98
cpu / 256 threads / Laufzeit von 95%: 81.48
cpu / 512 threads / Laufzeit von 95%: 81.48
================================================================================
memory / 2 threads / transferred: 2951.27 MiB/sec
memory / 4 threads / transferred: 3677.08 MiB/sec
memory / 6 threads / transferred: 4221.30 MiB/sec
memory / 8 threads / transferred: 4687.99 MiB/sec
memory / 16 threads / transferred: 7318.17 MiB/sec
memory / 32 threads / transferred: 8103.36 MiB/sec
memory / 64 threads / transferred: 8237.30 MiB/sec
memory / 128 threads / transferred: 8200.69 MiB/sec
memory / 256 threads / transferred: 8223.93 MiB/sec
memory / 512 threads / transferred: 8310.27 MiB/sec
================================================================================
threads / 2 threads / execution time: 3.5541
threads / 4 threads / execution time: 1.9458
threads / 6 threads / execution time: 1.4515
threads / 8 threads / execution time: 2.1365
threads / 16 threads / execution time: 2.6424
threads / 32 threads / execution time: 3.6737
threads / 64 threads / execution time: 3.4397
threads / 128 threads / execution time: 5.3409
threads / 256 threads / execution time: 4.7104
threads / 512 threads / execution time: 4.4099
================================================================================
mutex / 2 threads / Laufzeit von 95%: 161.51
mutex / 4 threads / Laufzeit von 95%: 173.58
mutex / 6 threads / Laufzeit von 95%: 227.40
mutex / 8 threads / Laufzeit von 95%: 240.02
mutex / 16 threads / Laufzeit von 95%: 320.17
mutex / 32 threads / Laufzeit von 95%: 623.33
mutex / 64 threads / Laufzeit von 95%: 1213.57
mutex / 128 threads / Laufzeit von 95%: 2405.65
mutex / 256 threads / Laufzeit von 95%: 4768.67
mutex / 512 threads / Laufzeit von 95%: 9624.59
 
real    4m14,055s
user    35m38,690s
sys     2m50,152s

bis Ubuntu 16.04 LTS

SysBench arbeitet wie folgt:

  • mit dem MyISAM-Back-End (/usr/share/doc/sysbench/tests/db/oltp.lua)
  • ca. 140.000 Lesezugriffe
  • ca. 40.000 Schreibzugriffe (abschaltbar)
  • ca. 20.000 andere Zugriffe (z.B. DROP, DELETE)

Einstellungen vornehmen:

vi ~/bin/MySQL-Benchmark.cfg

Datenbank für den Test anlegen und vorberiten:

~/bin/MySQL-Benchmark_Vorbereitung.sh

Leistungsdaten der Datenbank ermitteln:

~/bin/MySQL-Benchmark.sh

Ergebnisse ansehen:

less /tmp/sysbench.log

Am Ende sollte man die Datenbank wieder löschen,
zum Beispiel so:

echo "DROP DATABASE test;" | mysql -P3306 -uroot -pgeheim
~/bin/MySQL-Benchmark.sh
#!/bin/sh
 
 
#==============================================================================#
 
VERSION="v2021041400"           # universell umgebaut
 
 
if [ "x${2}" = x ] ; then
        echo "${0} [Hostname] [Port]"
        echo "${0} 127.0.0.1 3306"
        exit 10
else
        MYSQL_HOST="${1}"
        MYSQL_PORT="${2}"
fi
 
#==============================================================================#
 
#------------------------------------------------------------------------------#
 
MYSQL_USR=root                  # Voreinstellung: sbtest
MYSQL_PWD="$(echo Z2VoZWltCg== | base64 -d)"
MYSQL_DB=test                   # Voreinstellung: sbtest
MAX_REQUESTS=10000
MAX_TIME=120
TESTS="cpu memory threads mutex"
 
#------------------------------------------------------------------------------#
 
for TEST in ${TESTS}
do
        echo "================================================================================"
        for i in 2 4 6 8 16 32 64 128 256 512
        do
                AUSGABE="$(sysbench --num-threads=${i} --max-requests=${MAX_REQUESTS} --max-time=${MAX_TIME} --mysql-host=${MYSQL_HOST} --mysql-db=${MYSQL_DB} --mysql-port=${MYSQL_PORT} --mysql-user=${MYSQL_USR} --mysql-password=${MYSQL_PWD} --test=${TEST} run)"
 
                if [ "memory" = "${TEST}" ] ; then
                        echo "${AUSGABE}" | egrep '^### threads=| transferred ' | awk -F"[()]" -v threads=${i} -v test=${TEST} '{print test,"/",threads,"threads / transferred:",$2}'
                elif [ "threads" = "${TEST}" ] ; then
                        echo "${AUSGABE}" | egrep '^### threads=|execution time' | awk -v threads=${i} -v test=${TEST} '{gsub("/"," ");print test,"/",threads,"threads / execution time:",$(NF-1)}'
                else
                        echo "${AUSGABE}" | egrep '^### threads=|approx.  95 percentile:' | awk -v threads=${i} -v test=${TEST} '{print test,"/",threads,"threads / Laufzeit von 95%:",$NF}'
                fi
        done
done
# time /root/bin/MySQL-Benchmark.sh 127.0.0.1 3320
================================================================================
cpu / 2 threads / Laufzeit von 95%: 1.80ms
cpu / 4 threads / Laufzeit von 95%: 1.80ms
cpu / 6 threads / Laufzeit von 95%: 1.28ms
cpu / 8 threads / Laufzeit von 95%: 1.51ms
cpu / 16 threads / Laufzeit von 95%: 2.07ms
cpu / 32 threads / Laufzeit von 95%: 17.50ms
cpu / 64 threads / Laufzeit von 95%: 33.50ms
cpu / 128 threads / Laufzeit von 95%: 41.50ms
cpu / 256 threads / Laufzeit von 95%: 69.83ms
cpu / 512 threads / Laufzeit von 95%: 61.54ms
================================================================================
memory / 2 threads / transferred: 1755.38 MB/sec
memory / 4 threads / transferred: 2646.58 MB/sec
memory / 6 threads / transferred: 2517.85 MB/sec
memory / 8 threads / transferred: 2739.69 MB/sec
memory / 16 threads / transferred: 1703.85 MB/sec
memory / 32 threads / transferred: 1787.66 MB/sec
memory / 64 threads / transferred: 1798.00 MB/sec
memory / 128 threads / transferred: 1734.30 MB/sec
memory / 256 threads / transferred: 1767.17 MB/sec
memory / 512 threads / transferred: 1767.09 MB/sec
================================================================================
threads / 2 threads / execution time: 4.1759
threads / 4 threads / execution time: 2.3417
threads / 6 threads / execution time: 2.2158
threads / 8 threads / execution time: 3.5415
threads / 16 threads / execution time: 4.4740
threads / 32 threads / execution time: 5.3136
threads / 64 threads / execution time: 8.6983
threads / 128 threads / execution time: 9.3741
threads / 256 threads / execution time: 8.6209
threads / 512 threads / execution time: 8.5981
================================================================================
mutex / 2 threads / Laufzeit von 95%: 10000000.00ms
mutex / 4 threads / Laufzeit von 95%: 10000000.00ms
mutex / 6 threads / Laufzeit von 95%: 10000000.00ms
mutex / 8 threads / Laufzeit von 95%: 10000000.00ms
mutex / 16 threads / Laufzeit von 95%: 10000000.00ms
mutex / 32 threads / Laufzeit von 95%: 718.57ms
mutex / 64 threads / Laufzeit von 95%: 1218.04ms
mutex / 128 threads / Laufzeit von 95%: 2271.56ms
mutex / 256 threads / Laufzeit von 95%: 4583.28ms
mutex / 512 threads / Laufzeit von 95%: 9164.94ms
 
real    10m18.639s
user    29m43.736s
sys     85m16.524s

/home/http/wiki/data/attic/mysql_-_benchmark.1645612754.txt · Zuletzt geändert: von manfred