Mysql之基准测试测试工具sysbench

一、sysbench工具简介

sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。支持数据库MySQL/Oracle/PostgreSQL。
sysbench支持以下几种测试模式:
1、CPU运算性能
2、磁盘IO性能
3、线程子系统性能测试
4、内存分配及传输速度
5、mutex互斥性能测试
6、oltp OLTP测试

二、sysbench工具安装

1、博文示例环境

服务器操作系统为centos7.6
[test@testenv ~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

2、安装步骤

#curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
#sudo yum -y install sysbench
本文使用test用户安装,需要添加将test用户添加到sudo组中,添加方式如下
vim /etc/sudoers添加如下内容
#授权bdsc账户sudo权限
test ALL=(ALL) ALL #该方式sudo时需要输入密码
%test ALL=(ALL) ALL #授权bdsc用户组

3、其他环境安装

其他环境步骤参照官网提供的安装步骤
https://github.com/akopytov/sysbench

4、查看安装版本

[test@testenv ~]$ sysbench --version
sysbench 1.0.20

5、查看帮助

[test@testenv ~]$ sysbench --help
Usage:
sysbench [options]… [testname] [command]
 
Commands implemented by most tests: prepare run cleanup help
 
General options:
–threads=N number of threads to use [1]
–events=N limit for total number of events [0]
–time=N limit for total execution time in seconds [10]
–forced-shutdown=STRING number of seconds to wait after the --time limit before forcing shutdown, or ‘off’ to disable [off]
–thread-stack-size=SIZE size of stack per thread [64K]
–rate=N average transactions rate. 0 for unlimited rate [0]
–report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
–report-checkpoints=[LIST,…] dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []
–debug[=on|off] print more debugging info [off]
–validate[=on|off] perform validation checks where possible [off]
–help[=on|off] print help and exit [off]
–version[=on|off] print version and exit [off]
–config-file=FILENAME File containing command line options
–tx-rate=N deprecated alias for --rate [0]
–max-requests=N deprecated alias for --events [0]
–max-time=N deprecated alias for --time [0]
–num-threads=N deprecated alias for --threads [1]
 
Pseudo-Random Numbers Generator options:
–rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]
–rand-spec-iter=N number of iterations used for numbers generation [12]
–rand-spec-pct=N percentage of values to be treated as ‘special’ (for special distribution) [1]
–rand-spec-res=N percentage of ‘special’ values to use (for special distribution) [75]
–rand-seed=N seed for random number generator. When 0, the current time is used as a RNG seed. [0]
–rand-pareto-h=N parameter h for pareto distribution [0.2]

Log options:
–verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]
 
–percentile=N percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95]
–histogram[=on|off] print latency histogram in report [off]

General database options:

–db-driver=STRING specifies database driver to use (‘help’ to get list of available drivers) [mysql]
–db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
–db-debug[=on|off] print database-specific debug information [off]
 
Compiled-in database drivers:
mysql - MySQL driver
pgsql - PostgreSQL driver

mysql options:
–mysql-host=[LIST,…] MySQL server host [localhost]
–mysql-port=[LIST,…] MySQL server port [3306]
–mysql-socket=[LIST,…] MySQL socket
–mysql-user=STRING MySQL user [sbtest]
–mysql-password=STRING MySQL password []
–mysql-db=STRING MySQL database name [sbtest]
–mysql-ssl[=on|off] use SSL connections, if available in the client library [off]
–mysql-ssl-cipher=STRING use specific cipher for SSL connections []
–mysql-compression[=on|off] use compression, if available in the client library [off]
–mysql-debug[=on|off] trace all client library calls [off]
–mysql-ignore-errors=[LIST,…] list of errors to ignore, or “all” [1213,1020,1205]
–mysql-dry-run[=on|off] Dry run, pretend that all MySQL client API calls are successful without executing them [off]
 
pgsql options:
–pgsql-host=STRING PostgreSQL server host [localhost]
–pgsql-port=N PostgreSQL server port [5432]
–pgsql-user=STRING PostgreSQL user [sbtest]
–pgsql-password=STRING PostgreSQL password []
–pgsql-db=STRING PostgreSQL database name [sbtest]
 
Compiled-in tests:
fileio - File I/O test
cpu - CPU performance test
memory - Memory functions speed test
threads - Threads subsystem performance test
mutex - Mutex performance test
 
See ‘sysbench help’ for a list of options for each test.
 
至此sysbench安装成功

三、sysbench测试举例

在使用sysbench进行测试的时候,通常分为三个步骤prepare,run,cleanup阶段。

1、IO测试

1)、查看IO测试帮助

[test@testenv ~]$ sysbench fileio help
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
 
fileio options:
–file-num=N number of files to create [128]
–file-block-size=N block size to use in all IO operations [16384]
–file-total-size=SIZE total size of files to create [2G]
–file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
–file-io-mode=STRING file operations mode {sync,async,mmap} [sync]
–file-async-backlog=N number of asynchronous operatons to queue per thread [128]
–file-extra-flags=[LIST,…] list of additional flags to use to open files {sync,dsync,direct} []
–file-fsync-freq=N do fsync() after this number of requests (0 - don’t use fsync()) [100]
–file-fsync-all[=on|off] do fsync() after each write operation [off]
–file-fsync-end[=on|off] do fsync() at the end of test [on]
–file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
–file-merged-requests=N merge at most this number of IO requests if possible (0 - don’t merge) [0]
–file-rw-ratio=N reads/writes ratio for combined test [1.5]

2)、准备数据

[test@testenv ~]$ sysbench fileio --file-num=10 --file-total-size=10G prepare
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
 
10 files, 1048576Kb each, 10240Mb total
Creating files for the test…
Extra file open flags: (none)
Creating file test_file.0
Creating file test_file.1
Creating file test_file.2
Creating file test_file.3
Creating file test_file.4
Creating file test_file.5
Creating file test_file.6
Creating file test_file.7
Creating file test_file.8
Creating file test_file.9
10737418240 bytes written in 532.15 seconds (19.24 MiB/sec).

3)、随机读写测试

[test@testenv ~]$ sysbench fileio --file-num=10 --file-total-size=10G --file-block-size=16384 --file-test-mode=rndrw --file-io-mode=sync --file-extra-flags=direct --time=100 --threads=16 --report-interval=10 run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
 
Running the test with following options:
Number of threads: 16
Report intermediate results every 10 second(s)
Initializing random number generator from current time
 
 
Extra file open flags: directio
10 files, 1GiB each
10GiB total file size
Block size 16KiB
Number of IO requests: 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
Initializing worker threads…
 
Threads started!
 
[ 10s ] reads: 1.96 MiB/s writes: 1.32 MiB/s fsyncs: 20.98/s latency (ms,95%): 170.479
[ 20s ] reads: 1.55 MiB/s writes: 1.01 MiB/s fsyncs: 15.97/s latency (ms,95%): 223.344
[ 30s ] reads: 1.52 MiB/s writes: 1.03 MiB/s fsyncs: 16.00/s latency (ms,95%): 257.950
[ 40s ] reads: 1.66 MiB/s writes: 1.10 MiB/s fsyncs: 18.00/s latency (ms,95%): 231.534
[ 50s ] reads: 1.45 MiB/s writes: 0.96 MiB/s fsyncs: 15.01/s latency (ms,95%): 383.334
[ 60s ] reads: 1.66 MiB/s writes: 1.11 MiB/s fsyncs: 17.87/s latency (ms,95%): 211.599
[ 70s ] reads: 1.37 MiB/s writes: 0.93 MiB/s fsyncs: 15.09/s latency (ms,95%): 314.453
[ 80s ] reads: 1.50 MiB/s writes: 0.99 MiB/s fsyncs: 15.94/s latency (ms,95%): 253.346
[ 90s ] reads: 1.59 MiB/s writes: 1.07 MiB/s fsyncs: 17.10/s latency (ms,95%): 235.740
[ 100s ] reads: 1.41 MiB/s writes: 0.94 MiB/s fsyncs: 18.98/s latency (ms,95%): 404.611
 
File operations:
reads/s: 100.25
writes/s: 66.97
fsyncs/s: 18.29
 
Throughput:
read, MiB/s: 1.57
written, MiB/s: 1.05
 
General statistics:
total time: 100.0300s
total number of events: 18398
 
Latency (ms):
min: 0.00
avg: 86.91
max: 875.45
95th percentile: 235.74
sum: 1598906.67
 
Threads fairness:
events (avg/stddev): 1149.8750/36.94
execution time (avg/stddev): 99.9317/0.07

4)、顺序读写测试

[test@testenv ~]$ sysbench fileio --file-num=10 --file-total-size=10G --file-block-size=16384 --file-test-mode=seqrd --file-io-mode=sync --file-extra-flags=direct --time=100 --threads=16 --report-interval=10 run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
 
Running the test with following options:
Number of threads: 16
Report intermediate results every 10 second(s)
Initializing random number generator from current time
 
 
Extra file open flags: directio
10 files, 1GiB each
10GiB total file size
Block size 16KiB
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing sequential read test
Initializing worker threads…
 
Threads started!
 
[ 10s ] reads: 78.51 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 7.702
[ 20s ] reads: 75.76 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 7.985
[ 30s ] reads: 66.42 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 9.910
[ 40s ] reads: 67.91 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 8.581
[ 50s ] reads: 64.95 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 9.222
[ 60s ] reads: 63.65 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 9.389
[ 70s ] reads: 62.44 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 9.560
[ 80s ] reads: 61.09 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 10.460
[ 90s ] reads: 63.48 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 7.842
[ 100s ] reads: 60.58 MiB/s writes: 0.00 MiB/s fsyncs: 0.00/s latency (ms,95%): 9.222
 
File operations:
reads/s: 4254.50
writes/s: 0.00
fsyncs/s: 0.00
 
Throughput:
read, MiB/s: 66.48
written, MiB/s: 0.00
 
General statistics:
total time: 100.0457s
total number of events: 425651
 
Latency (ms):
min: 0.05
avg: 3.76
max: 241.01
95th percentile: 8.90
sum: 1599167.58
 
Threads fairness:
events (avg/stddev): 26603.1875/797.69
execution time (avg/stddev): 99.9480/0.02

5)、测试数据清理

[test@testenv ~]$ sysbench fileio --file-num=10 --file-total-size=10 cleanup
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
 
Removing test files…
[test@testenv ~]$ ll
total 51124
-rw-r–r--. 1 test test 48456670 Dec 10 14:11 db20201210.xingye_btms.sql
drwxr-xr-x. 3 test test 117 Aug 1 2019 meb-4.1.0-el7-x86-64bit
drwxrwxr-x. 6 test test 4096 Dec 15 10:56 mysql
-rw-r–r--. 1 test test 3883265 Dec 12 14:58 mysqlbackup.tar.gz

6)、测试结果解读

此测试在虚拟机内完成的测试,物理机为机械硬盘的台式机,测试结果为顺序读平均速度66.48MB/s,随机读速度为1.57MB/s,由此可见顺序读写和随机读写差距巨大。

2、CPU测试

[test@testenv ~]$ sysbench --test=cpu --cpu-max-prime=2000 run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
 
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
 
 
Prime numbers limit: 2000
 
Initializing worker threads…
 
Threads started!
 
CPU speed:
events per second: 8968.42
 
General statistics:
total time: 10.0002s
total number of events: 89703
 
Latency (ms):
min: 0.11
avg: 0.11
max: 1.14
95th percentile: 0.12
sum: 9977.42
 
Threads fairness:
events (avg/stddev): 89703.0000/0.00
execution time (avg/stddev): 9.9774/0.00

3、内存测试

[test@testenv ~]$ sysbench --test=memory --num-threads=16 --memory-block-size=8192 --memory-total-size=1G run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --num-threads is deprecated, use --threads instead
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
 
Running the test with following options:
Number of threads: 16
Initializing random number generator from current time
 
 
Running memory speed test with the following options:
block size: 8KiB
total size: 1024MiB
operation: write
scope: global
 
Initializing worker threads…
 
Threads started!
 
Total operations: 131072 (1819111.59 per second)
 
1024.00 MiB transferred (14211.81 MiB/sec)
 
 
General statistics:
total time: 0.0698s
total number of events: 131072
 
Latency (ms):
min: 0.00
avg: 0.00
max: 47.24
95th percentile: 0.00
sum: 219.70
 
Threads fairness:
events (avg/stddev): 8192.0000/0.00
execution time (avg/stddev): 0.0137/0.01

4、mutex测试

[test@testenv ~]$ sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --num-threads is deprecated, use --threads instead
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
 
Running the test with following options:
Number of threads: 16
Initializing random number generator from current time
 
 
Initializing worker threads…
 
Threads started!
 
 
General statistics:
total time: 0.1587s
total number of events: 16
 
Latency (ms):
min: 30.24
avg: 47.09
max: 81.41
95th percentile: 77.19
sum: 753.45
 
Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 0.0471/0.02

写在最后

本文博客演示实验的YUM安装,没有oltp测试选项,下次使用源码安装再进行验证是否可以进行OLTP测试,另外其他有博客说源码安装有MySQL测试的lua脚本可以进行mysql测试。敬请期待。。。

猜你喜欢

转载自blog.csdn.net/carefree2005/article/details/111377510