简介
sysbench是一个模块化的、跨平台、多线程基准测试工具。
github地址:https://github.com/akopytov/sysbench/blob/master/README.md#general-command-line-options
它主要包括以下几种方式的测试:
fileio - File I/O test
cpu - CPU performance test
memory - Memory functions speed test
threads - Threads subsystem performance test
mutex - Mutex performance test
安装
mac 环境安装
brew install sysbench
其它环境安装详见github:https://github.com/akopytov/sysbench/blob/master/README.md#general-command-line-options
测试
fileio测试
➜ ~ sysbench fileio help
sysbench 1.0.17 (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-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]
--file-test-mode参数
- seqwr:顺序写入
- seqrewr:顺序重写
- seqrd:顺序读取
- rndrd:随机读取
- rndwr:随机写入
- rndrw:随机读取/写入
生成测试文件
sysbench --file-total-size=1G fileio prepare
128 files, 8192Kb each, 1024Mb total Creating files for the test... Extra file open flags: (none)
开始测试
sysbench --file-total-size=1G --file-test-mode=rndrw --time=300 --max-requests=0 fileio run
Threads started! File operations: reads/s: 77.33 writes/s: 51.55 fsyncs/s: 165.00 Throughput: read, MiB/s: 1.21 written, MiB/s: 0.81 General statistics: total time: 300.2152s total number of events: 88099 Latency (ms): min: 0.00 avg: 3.40 max: 733.80 95th percentile: 17.01 sum: 299724.17 Threads fairness: events (avg/stddev): 88099.0000/0.00 execution time (avg/stddev): 299.7242/0.00
清理测试文件
sysbench fileio help
sysbench 1.0.17 (using bundled LuaJIT 2.1.0-beta2) Removing test files...
mysql测试
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]
生成测试数据
sysbench --db-driver=mysql --mysql-user=root --mysql-password=root --mysql-db=test --range_size=100 --table_size=10000 --tables=2 --threads=1 --events=0 --time=60 --rand-type=uniform /usr/local/Cellar/sysbench/1.0.17/share/sysbench/oltp_read_only.lua prepare
运行测试数据
sysbench --db-driver=mysql --mysql-user=root --mysql-password=root --mysql-db=test --range_size=100 --table_size=10000 --tables=2 --threads=1 --events=0 --time=60 --rand-type=uniform /usr/local/Cellar/sysbench/1.0.17/share/sysbench/oltp_read_only.lua run
清理测试数据
sysbench --db-driver=mysql --mysql-user=root --mysql-password=root --mysql-db=test --range_size=100 --table_size=10000 --tables=2 --threads=1 --events=0 --time=60 --rand-type=uniform /usr/local/Cellar/sysbench/1.0.17/share/sysbench/oltp_read_only.lua cleanup
数据库地址/用户/密码等替换成自己的,oltp_read_only.lua在sysbench安装目录下
➜ ~ sysbench --db-driver=mysql --mysql-user=root --mysql-password=root --mysql-db=test --range_size=100 --table_size=10000 --tables=2 --threads=1 --events=0 --time=60 --rand-type=uniform /usr/local/Cellar/sysbench/1.0.17/share/sysbench/oltp_read_only.lua prepare
sysbench 1.0.17 (using bundled LuaJIT 2.1.0-beta2)
Creating table 'sbtest1'...
Inserting 10000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 10000 records into 'sbtest2'
Creating a secondary index on 'sbtest2'...
➜ ~ sysbench --db-driver=mysql --mysql-user=root --mysql-password=root --mysql-db=test --range_size=100 --table_size=10000 --tables=2 --threads=1 --events=0 --time=60 --rand-type=uniform /usr/local/Cellar/sysbench/1.0.17/share/sysbench/oltp_read_only.lua run
sysbench 1.0.17 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Initializing worker threads...
Threads started!
SQL statistics:
queries performed:
read: 416822
write: 0
other: 59546
total: 476368
transactions: 29773 (495.23 per sec.)
queries: 476368 (7923.71 per sec.)
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 60.1157s
total number of events: 29773
Latency (ms):
min: 1.48
avg: 2.01
max: 6.25
95th percentile: 2.39
sum: 59955.50
Threads fairness:
events (avg/stddev): 29773.0000/0.00
execution time (avg/stddev): 59.9555/0.00
➜ ~ sysbench --db-driver=mysql --mysql-user=root --mysql-password=root --mysql-db=test --range_size=100 --table_size=10000 --tables=2 --threads=1 --events=0 --time=60 --rand-type=uniform /usr/local/Cellar/sysbench/1.0.17/share/sysbench/oltp_read_only.lua cleanup
sysbench 1.0.17 (using bundled LuaJIT 2.1.0-beta2)
Dropping table 'sbtest1'...
Dropping table 'sbtest2'...
参考:https://blog.csdn.net/kikajack/article/details/79977108