如何使用sysbench来对系统(CPU,文件IO,MySQL)进行基准测试
sysbench是一个基准套件,可让您快速获得有关系统性能的印象,如果您计划在密集负载下运行数据库,这一点非常重要。 本文介绍如何使用sysbench来标准化您的CPU,文件IO和MySQL性能。
我不会保证这将为您工作!
1安装sysbench
在Debian / Ubuntu上,sysbench可以安装如下:
apt-get install sysbench
看一眼
man sysbench
了解更多关于它的参数。
我现在将执行简单的三个基本测试,它们将更详细地介绍您的CPU性能,文件IO性能和MySQL性能。
2 CPU基准
您可以按照以下方式对您的CPU性能进行基准测试:
sysbench --test=cpu --cpu-max-prime=20000 run
root@server1:~# 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
root@server1:~#
你看到很多数字,最重要的是总时间:
总时间:23.8724s
当然,您必须比较多个系统中的基准,才能知道这些数字是值得的。
3文件IO基准
为了测量文件IO性能,我们首先需要创建一个比你的RAM大得多的测试文件(因为否则系统将使用RAM缓存哪些篡改器的基准测试结果) - 150GB是一个很好的价值:
sysbench --test=fileio --file-total-size=150G prepare
之后,我们可以运行基准:
sysbench --test=fileio --file-total-size=150G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
root@server1:~# 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
root@server1:~#
重要的数字是Kb / sec
值:
阅读9.375Mb写6.25Mb总转移15.625Mb(
53.316Kb / sec )
基准测试后,您可以从系统中删除150GB的测试文件:
sysbench --test=fileio --file-total-size=150G cleanup
4 MySQL基准
为了测量MySQL性能,我们首先在数据库测试
中创建一个具有1,000,000行数据的测试表:
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword prepare
root@server1:~# sysbench --test=oltp --oltp-table-size=1000000 --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'...
root@server1:~#
之后,您可以运行MySQL基准如下:
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
root@server1:~# sysbench --test=oltp --oltp-table-size=1000000 --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
root@server1:~#
重要的数字是每秒的交易值:
交易:160990(2683.06 per sec。)
要清理系统(即删除测试表),请运行:
sysbench --test=oltp --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword cleanup
5链接
- sysbench: http : //sysbench.sourceforge.net/