sysbench è una suite di benchmark che ti consente di avere rapidamente un'idea delle prestazioni del sistema, il che è importante se prevedi di eseguire un database sotto carico intenso. Questo articolo spiega come confrontare le prestazioni di CPU, file IO e MySQL con sysbench.
1 Installazione di sysbench
Su Debian/Ubuntu, sysbench può essere installato come segue:
sudo apt-get install sysbench
Su CentOS e Fedora, può essere installato dal repository EPEL.
Aggiungi repository EPEL:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum -y install epel-release
yum -y update
Quindi installa sysbench con yum:
yum install sysbench
Ottieni una panoramica delle opzioni di sysbench
Dai un'occhiata a
man sysbench
per saperne di più sui suoi parametri.
Ora eseguirò tre semplici test di base che ti dicono di più sulle prestazioni della CPU, sulle prestazioni di I/O dei file e sulle prestazioni di MySQL.
2 benchmark CPU
Puoi confrontare le prestazioni della tua CPU come segue:
sysbench --test=cpu --cpu-max-prime=20000 run
[email protected]:~# sysbench --test=cpu --cpu-max-prime=20000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Doing CPU performance benchmark
Threads started!
Done.
Maximum prime number checked in CPU test: 20000
Test execution summary:
total time: 23.8724s
total number of events: 10000
total time taken by event execution: 23.8716
per-request statistics:
min: 2.31ms
avg: 2.39ms
max: 6.39ms
approx. 95 percentile: 2.44ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 23.8716/0.00
[email protected]:~#
Vedi molti numeri, il più importante è il tempo totale:
tempo totale: 23,8724 secondi
Ovviamente, devi confrontare i benchmark su più sistemi per sapere quanto valgono questi numeri.
3 Benchmark IO file
Per misurare le prestazioni di I/O del file, dobbiamo prima creare un file di test che sia molto più grande della tua RAM (perché altrimenti, il sistema utilizzerà la RAM per la memorizzazione nella cache che altera i risultati del benchmark) - 150 GB è un buon valore:
sysbench --test=fileio --file-total-size=150G prepare
Successivamente, possiamo eseguire il benchmark:
sysbench --test=fileio --file-total-size=150G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
[email protected]:~# sysbench --test=fileio --file-total-size=150G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
sysbench: /usr/lib/libmysqlclient.so.18: no version information available (required by sysbench)
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Initializing random number generator from timer.
Extra file open flags: 0
128 files, 1.1719Gb each
150Gb total file size
Block size 16Kb
Number of random requests for random IO: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Threads started!
Time limit exceeded, exiting...
Done.
Operations performed: 600 Read, 400 Write, 1186 Other = 2186 Total
Read 9.375Mb Written 6.25Mb Total transferred 15.625Mb (53.316Kb/sec)
3.33 Requests/sec executed
Test execution summary:
total time: 300.0975s
total number of events: 1000
total time taken by event execution: 158.7611
per-request statistics:
min: 0.01ms
avg: 158.76ms
max: 2596.96ms
approx. 95 percentile: 482.29ms
Threads fairness:
events (avg/stddev): 1000.0000/0.00
execution time (avg/stddev): 158.7611/0.00
[email protected]:~#
Il numero importante è il valore Kb/sec:
Leggi 9,375 Mb Scritto 6,25 Mb Totale trasferito 15,625 Mb (53,316 Kb/sec)
Dopo il benchmark, puoi eliminare il file di prova da 150 GB dal sistema:
sysbench --test=fileio --file-total-size=150G cleanup
4 benchmark MySQL
Per misurare le prestazioni di MySQL, creiamo prima una tabella di test nel test del database con 1.000.000 di righe di dati:
sysbench --test=oltp --oltp-table-size=1000000 --db-driver=mysql --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword prepare
[email protected]:~# sysbench --test=oltp --oltp-table-size=1000000 --db-driver=mysql --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark
No DB drivers specified, using mysql
Creating table 'sbtest'...
Creating 1000000 records in table 'sbtest'...
[email protected]:~#
Sostituisci la parola yourrootsqlpassword con la tua password di root MySQL nel comando precedente. Fai lo stesso nei comandi successivi.
Successivamente, puoi eseguire il benchmark MySQL come segue:
sysbench --test=oltp --oltp-table-size=1000000 --db-driver=mysql --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
[email protected]:~# sysbench --test=oltp --oltp-table-size=1000000 --db-driver=mysql --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 8
Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 7 times)
Done.
OLTP test statistics:
queries performed:
read: 2253860
write: 0
other: 321980
total: 2575840
transactions: 160990 (2683.06 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 2253860 (37562.81 per sec.)
other operations: 321980 (5366.12 per sec.)
Test execution summary:
total time: 60.0024s
total number of events: 160990
total time taken by event execution: 479.3419
per-request statistics:
min: 0.81ms
avg: 2.98ms
max: 3283.40ms
approx. 95 percentile: 4.62ms
Threads fairness:
events (avg/stddev): 20123.7500/63.52
execution time (avg/stddev): 59.9177/0.00
[email protected]:~#
Il numero importante è il valore delle transazioni al secondo:
transazioni: 160990 (2683,06 per sec.)
Per ripulire il sistema in seguito (ovvero rimuovere la tabella di test), eseguire:
sysbench --test=oltp --db-driver=mysql --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword cleanup
5 link
- sysbench:http://sysbench.sourceforge.net/