Mysql sysbench 基准测试

sysbench 可以执行多种类型的基准测试,它不仅设计用来测试数据库的性能,也可以测试运行数据库的服务器的性能。实际上,Peter和Vadim最初设计这个工具是用来执行MySql性能测试的(尽管并不能完成所有的MySql基准测试)。

CPU 基准测试

该测试使用64位整数,测试计算素数直到某个最大值所需要的时间。

root@iZ9460e7nt4Z:~# 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:                          33.2198s
    total number of events:              10000
    total time taken by event execution: 33.2153
    per-request statistics:
         min:                                  3.23ms
         avg:                                  3.32ms
         max:                                 10.35ms
         approx.  95 percentile:               3.49ms

Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   33.2153/0.00

文件I/O基准测试

文件I/O基准测试可以测试系统在不同的I/O负载下的性能。这对于比较不同的硬盘驱动器、不同的RAID卡、不同的RAID模式,都很有帮助。可以根据测试结果来调整I/O子系统。文件I/O基准测试模拟了很多InnoDB的I/O特性。

测试的第一步是准备阶段,生成测试用到的数据文件,生成的数据文件至少要比内存大。如果文件中的数据能完全放入内存中,则操作系统缓存大部分的数据,导致测试结果无法体现I/O密集型的工作负载。
第二阶段就是运行阶段。
最后将测试文件清理:sysbench --test=fileio --file-total-size=10G cleanup

root@iZ9460e7nt4Z:~# sysbench --test=fileio --file-total-size=10G prepare
sysbench 0.4.12:  multi-threaded system evaluation benchmark

128 files, 81920Kb each, 10240Mb total
Creating files for the test...
root@iZ9460e7nt4Z:~# sysbench --test=fileio --file-total-size=10G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
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, 80Mb each
10Gb 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:  198780 Read, 132520 Write, 424045 Other = 755345 Total Read 3.0331Gb  Written 2.0221Gb  Total transferred 5.0552Gb  (17.254Mb/sec) 1104.28 Requests/sec executed

Test execution summary:
    total time:                          300.0151s
    total number of events:              331300
    total time taken by event execution: 138.7862
    per-request statistics:
         min:                                  0.00ms
         avg:                                  0.42ms
         max:                                118.33ms
         approx.  95 percentile:               1.09ms

Threads fairness:
    events (avg/stddev):           331300.0000/0.00
    execution time (avg/stddev):   138.7862/0.00

输出结果中包含了大量的信息。和I/O子系统密切相关的包括每秒请求数和总吞吐量。在上述例子中,每秒请求数是1104.28,吞吐量是17.254Mb/sec。另外,时间信息也非常有用,尤其是大约95%的时间分布。这些数据对于评估磁盘性能十分有用。

OLTP基准测试

OLTP基准测试模拟了一个简单的事务处理系统的工作负载。下面的例子使用的是一张超过百万行记录的表。

生成测试数据后,接下来运行测试,这个例子采用了8个并发线程,只读模式,测试时长60秒。

root@iZ9460e7nt4Z:~# sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password=  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@iZ9460e7nt4Z:~# sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password= --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:                            340424
        write:                           0
        other:                           48632
        total:                           389056
    transactions:                        24316  (405.22 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 340424 (5673.12 per sec.)
    other operations:                    48632  (810.45 per sec.)

Test execution summary:
    total time:                          60.0065s
    total number of events:              24316
    total time taken by event execution: 479.9112
    per-request statistics:
         min:                                  8.16ms
         avg:                                 19.74ms
         max:                                207.70ms
         approx.  95 percentile:              23.26ms

Threads fairness:
    events (avg/stddev):           3039.5000/25.65
    execution time (avg/stddev):   59.9889/0.00

如上所示,结果中包含了相当多的信息。其中最有价值的信息如下:

  • 总的事务数
  • 每秒事务数
  • 时间统计信息(最小、平均、最大响应时间,以及95%百分比响应时间)
  • 线程公平性统计信息(thread-fairness),用于表示模拟负载的公平性

参考内容

  • 高性能MySQL 2.5基准测试案例 第三版

你可能感兴趣的:(Mysql sysbench 基准测试)