sysbench是一个模块化、跨平台、多线程基准测试工具,主要用于测试不同系统参数下的数据库负载情况,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。sysbench主要用于以下性能测试:
file I/O performance (文件I / O性能)
scheduler performance (调度性能)
memory allocation and transfer speed (内存分配和传输速度)
POSIX threads implementation performance (POSIX线程执行绩效)
database server performance (OLTP benchmark) (数据库服务器性能)
[root@andriy ~]# sysbench
Missing required command argument.
Usage: #使用方法
sysbench [general-options]... --test= [test-options]... command
General options: #通用选项
--num-threads=N number of threads to use [1] #创建测试线程的数目。默认为1.
--max-requests=N limit for total number of requests [10000] #请求的最大数目。默认为10000,0代表不限制。
--max-time=N limit for total execution time in seconds [0] #最大执行时间,单位是s。默认是0,不限制。
--forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off] #超过max-time强制中断。默认是off。
--thread-stack-size=SIZE size of stack per thread [32K] #每个线程的堆栈大小。默认是32K。
--init-rng=[on|off] initialize random number generator [off] #在测试开始时是否初始化随机数发生器。默认是off。
--test=STRING test to run #指定测试项目名称。
--debug=[on|off] print more debugging info [off] #是否显示更多的调试信息。默认是off。
--validate=[on|off] perform validation checks where possible [off] #在可能情况下执行验证检查。默认是off。
--help=[on|off] print help and exit #帮助信息。
--version=[on|off] print version and exit #版本信息。
Compiled-in tests: #测试项目
fileio - File I/O test #IO
cpu - CPU performance test #CPU
memory - Memory functions speed test #内存
threads - Threads subsystem performance test #线程
mutex - Mutex performance test #互斥性能测试
oltp - OLTP test # 数据库,事务处理
Commands: prepare:测试前准备工作; run:正式测试 cleanup:测试后删掉测试数据 help version
See 'sysbench --test= help' for a list of options for each test. #查看每个测试项目的更多选项列表
root@db2:~# sysbench --test=oltp help
sysbench 0.4.12: multi-threaded system evaluation benchmark
oltp options:
--oltp-test-mode=STRING 执行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。默认是complex
--oltp-reconnect-mode=STRING 重新连接模式{session(不使用重新连接。每个线程断开只在测试结束),transaction(在每次事务结束后重新连接),query(在每个SQL语句执行完重新连接),random(对于每个事务随机选择以上重新连接模式)}。默认是session
--oltp-sp-name=STRING 存储过程的名称。默认为空
--oltp-read-only=[on|off] 只读模式。Update,delete,insert语句不可执行。默认是off
--oltp-skip-trx=[on|off] 省略begin/commit语句。默认是off
--oltp-range-size=N 查询范围。默认是100
--oltp-point-selects=N number of point selects [10]
--oltp-simple-ranges=N number of simple ranges [1]
--oltp-sum-ranges=N number of sum ranges [1]
--oltp-order-ranges=N number of ordered ranges [1]
--oltp-distinct-ranges=N number of distinct ranges [1]
--oltp-index-updates=N number of index update [1]
--oltp-non-index-updates=N number of non-index updates [1]
--oltp-nontrx-mode=STRING 查询类型对于非事务执行模式{select, update_key, update_nokey, insert, delete} [select]
--oltp-auto-inc=[on|off] AUTO_INCREMENT是否开启。默认是on
--oltp-connect-delay=N 在多少微秒后连接数据库。默认是10000
--oltp-user-delay-min=N 每个请求最短等待时间。单位是ms。默认是0
--oltp-user-delay-max=N 每个请求最长等待时间。单位是ms。默认是0
--oltp-table-name=STRING 测试时使用到的表名。默认是sbtest
--oltp-table-size=N 测试表的记录数。默认是10000
--oltp-dist-type=STRING 分布的随机数{uniform(均匀分布),Gaussian(高斯分布),special(空间分布)}。默认是special
--oltp-dist-iter=N 产生数的迭代次数。默认是12
--oltp-dist-pct=N 值的百分比被视为'special' (for special distribution)。默认是1
--oltp-dist-res=N ‘special’的百分比值。默认是75
General database options:
--db-driver=STRING 数据库类型,指定数据库驱动程序('help' to get list of available drivers)
--db-ps-mode=STRING 数据库预处理模式{auto, disable} [auto]
Compiled-in database drivers:
mysql - MySQL driver
mysql options:
--mysql-host=[LIST,...] MySQL server host [localhost]
--mysql-port=N MySQL server port [3306]
--mysql-socket=STRING MySQL socket
--mysql-user=STRING MySQL user [sbtest]
--mysql-password=STRING MySQL password []
--mysql-db=STRING MySQL database name [sbtest]
--mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]
--mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} [auto]
--mysql-ssl=[on|off] use SSL connections, if available in the client library [off]
--myisam-max-rows=N max-rows parameter for MyISAM tables [1000000]
--mysql-create-options=STRING additional options passed to CREATE TABLE []
[root@andriy ~]# sysbench cpu --threads=1 --time=20 run
sysbench 1.0.6 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Prime numbers limit: 10000
Initializing worker threads...
Threads started!
General statistics:
total time: 20.0001s
total number of events: 14330
Latency (ms):
min: 1.31
avg: 1.39
max: 2.37
95th percentile: 1.64
sum: 19985.58
Threads fairness:
events (avg/stddev): 14330.0000/0.00
execution time (avg/stddev): 19.9856/0.00
[root@andriy ~]# sysbench memory help
sysbench 0.4.12: multi-threaded system evaluation benchmark
memory options:
--memory-block-size=SIZE 测试时内存块大小。默认是1K
--memory-total-size=SIZE 传输数据的总大小。默认是100G
--memory-scope=STRING 内存访问范围{global,local}。默认是global
--memory-hugetlb=[on|off] 从HugeTLB池内存分配。默认是off
--memory-oper=STRING 内存操作类型。{read, write, none} 默认是write
--memory-access-mode=STRING存储器存取方式{seq,rnd} 默认是seq
[root@andriy ~]# sysbench memory --memory-block-size=4k --memory-total-size=10G --memory-oper=write --memory-access-mode=rnd run
sysbench 1.0.6 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Running memory speed test with the following options:
block size: 4KiB
total size: 10240MiB
operation: write
scope: global
Initializing worker threads...
Threads started!
Total operations: 2621440 (270394.47 per second)
10240.00 MiB transferred (1056.23 MiB/sec)
General statistics:
total time: 9.6905s
total number of events: 2621440
Latency (ms):
min: 0.00
avg: 0.00
max: 2.32
95th percentile: 0.00
sum: 8881.74
Threads fairness:
events (avg/stddev): 2621440.0000/0.00
execution time (avg/stddev): 8.8817/0.00
[root@andriy ~]# sysbench memory --memory-block-size=4K --memory-total-size=10G --memory-oper=read --memory-access-mode=rnd run
sysbench 1.0.6 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Running memory speed test with the following options:
block size: 4KiB
total size: 10240MiB
operation: read
scope: global
Initializing worker threads...
Threads started!
Total operations: 2621440 (318264.48 per second)
10240.00 MiB transferred (1243.22 MiB/sec)
General statistics:
total time: 8.2342s
total number of events: 2621440
Latency (ms):
min: 0.00
avg: 0.00
max: 1.87
95th percentile: 0.00
sum: 7440.21
Threads fairness:
events (avg/stddev): 2621440.0000/0.00
execution time (avg/stddev): 7.4402/0.00
[root@andriy ~]# sysbench threads help
sysbench 0.4.12: multi-threaded system evaluation benchmark
threads options:
--thread-yields=N 每个请求产生多少个线程。默认是1000
--thread-locks=N 每个线程的锁的数量。默认是8
[root@andriy ~]# sysbench threads --thread-yields=100 --thread-locks=4 run
sysbench 1.0.6 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Initializing worker threads...
Threads started!
General statistics:
total time: 10.0001s
total number of events: 305159
Latency (ms):
min: 0.03
avg: 0.03
max: 2.16
95th percentile: 0.04
sum: 9889.32
Threads fairness:
events (avg/stddev): 305159.0000/0.00
execution time (avg/stddev): 9.8893/0.00
[root@andriy ~]# sysbench fileio help
sysbench 0.4.12: multi-threaded system evaluation benchmark
fileio options:
--file-num=N 创建测试文件的数量。默认是128
--file-block-size=N 测试时文件块的大小。默认是16384(16K)
--file-total-size=SIZE 测试文件的总大小。默认是2G
--file-test-mode=STRING 文件测试模式{seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}
--file-io-mode=STRING 文件操作模式{sync(同步),async(异步),fastmmap(快速map映射),slowmmap(慢map映射)}。默认是sync
--file-extra-flags=STRING 使用额外的标志来打开文件{sync,dsync,direct} 。默认为空
--file-fsync-freq=N 执行fsync()的频率。(0 – 不使用fsync())。默认是100
--file-fsync-all=[on|off] 每执行完一次写操作就执行一次fsync。默认是off
--file-fsync-end=[on|off] 在测试结束时才执行fsync。默认是on
--file-fsync-mode=STRING 使用哪种方法进行同步{fsync, fdatasync}。默认是fsync
--file-merged-requests=N 如果可以,合并最多的IO请求数(0 – 表示不合并)。默认是0
--file-rw-ratio=N 测试时的读写比例。默认是1.5
1、顺序写
[root@andriy ~]# sysbench fileio --file-test-mode=seqwr --file-block-size=1M --file-extra-flags=direct --file-fsync-all=on run
sysbench 1.0.6 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Extra file open flags: 3
128 files, 16MiB each
2GiB total file size
Block size 1MiB
Calling fsync() after each write operation.
Using synchronous I/O mode
Doing sequential write (creation) test
Initializing worker threads...
Threads started!
File operations:
reads/s: 0.00
writes/s: 16.49
fsyncs/s: 16.49
Throughput:
read, MiB/s: 0.00
written, MiB/s: 16.49
General statistics:
total time: 10.0062s
total number of events: 165
Latency (ms):
min: 27.38
avg: 60.63
max: 507.11
95th percentile: 139.85
sum: 10003.61
Threads fairness:
events (avg/stddev): 165.0000/0.00
execution time (avg/stddev): 10.0036/0.00
2、顺序读:
[root@andriy mnt]# sysbench fileio --file-total-size=1G --file-test-mode=seqrd --num-threads=1 --file-num=16 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=1M run
sysbench 1.0.6 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Extra file open flags: 3
16 files, 64MiB each
1GiB total file size
Block size 1MiB
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing sequential read test
Initializing worker threads...
Threads started!
File operations:
reads/s: 93.75
writes/s: 0.00
fsyncs/s: 0.00
Throughput:
read, MiB/s: 93.75
written, MiB/s: 0.00
General statistics:
total time: 10.0029s
total number of events: 938
Latency (ms):
min: 3.05
avg: 10.66
max: 16.28
95th percentile: 13.70
sum: 9996.77
Threads fairness:
events (avg/stddev): 938.0000/0.00
execution time (avg/stddev): 9.9968/0.00
[root@andriy mnt]# sysbench fileio --file-test-mode=seqrd --file-block-size=1M --file-extra-flags=direct prepare #创建测试文件
3、随机写:
[root@andriy mnt]# sysbench fileio --file-test-mode=rndwr --file-block-size=4K --file-extra-flags=direct --file-fsync-all=on --time=20 run
sysbench 1.0.6 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Extra file open flags: 3
128 files, 16MiB each
2GiB total file size
Block size 4KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Calling fsync() after each write operation.
Using synchronous I/O mode
Doing random write test
Initializing worker threads...
Threads started!
File operations:
reads/s: 0.00
writes/s: 38.81
fsyncs/s: 38.81
Throughput:
read, MiB/s: 0.00
written, MiB/s: 0.15
General statistics:
total time: 20.1452s
total number of events: 782
Latency (ms):
min: 6.36
avg: 25.75
max: 2507.14
95th percentile: 39.65
sum: 20139.93
Threads fairness:
events (avg/stddev): 782.0000/0.00
execution time (avg/stddev): 20.1399/0.00
4、随机读:
[root@andriy mnt]# sysbench fileio --file-test-mode=rndrd --file-block-size=4K --file-extra-flags=direct --time=20 run
sysbench 1.0.6 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Extra file open flags: 3
128 files, 16MiB each
2GiB total file size
Block size 4KiB
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 read test
Initializing worker threads...
Threads started!
File operations:
reads/s: 856.66
writes/s: 0.00
fsyncs/s: 0.00
Throughput:
read, MiB/s: 3.35
written, MiB/s: 0.00
General statistics:
total time: 20.0007s
total number of events: 17136
Latency (ms):
min: 0.44
avg: 1.16
max: 37.94
95th percentile: 1.82
sum: 19963.44
Threads fairness:
events (avg/stddev): 17136.0000/0.00
execution time (avg/stddev): 19.9634/0.00
清除测试文件
[root@andriy mnt]# sysbench fileio --file-test-mode=seqrd --file-block-size=1M --file-extra-flags=direct cleanup