sysbench安装及说明
1.1sysbench介绍
sysbench是一个模块化、支持多平台安装运行的,多线程的基准测试工具,sysbench不仅用来测试数据为的性能,也可以测试运行数据库的服务器的性能。
oltp测试主要是结合了lua脚本,不需要修改源码,通过自定义lu脚本就可以实现不同业务类型的测试。
主要有以下几种方式的测试:
cpu基准测试;
磁盘I/O基准测试;
内存连续读写性能测试;
测试互斥锁性能 ;
测试顺序读写性能 ;
数据库性能OLTP基准测试;
- ne transaction processing联机事务处理过程也称为面向交易的处理过程,其基本特征是前台的用户数据可以立即传送到计算中心进行处理,并在很短的时间 内给出处理结果,是对用户操作快速响应的方式之一。
1.2 在centos 7安装:
# curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench
1.3 sysbench参数说明
$ sysbench --help
Usage:
sysbench [options]... [testname] [command]
Commands implemented by most tests: prepare run cleanup help
sysbench 压测需要 3 个步骤:
prepare(准备数据) -> run(运行测试) -> cleanup(清理数据)
General options:
--threads=N #创建测试线程的数量,默认值为 1
--events=N #限制事件的总数量,0 表示不限制,默认值为 0
--time=N #限制总共执行多长时间,单位是秒,默认是 10
--forced-shutdown=STRING #超过--time 后,等待多长时间强制关闭,单位是秒,默认 off
--thread-stack-size=SIZE #每个线程的堆大小,默认是 64k
--rate=N #平均事务率,0 表示不限制
--report-interval=N #定期报告统计数据的时间间隔,单位秒,默认为 0,表示不显示中间报告。
--report-checkpoints=[LIST,...] #转储完整的统计信息并在指定的时间点重置所有计数器。默认为关闭
--config-file=FILENAME #可以把命令参数写到一个文件中,指定这个文件
--tx-rate=N #该参数弃用,改为 --rate [0]
--max-requests=N #该参数弃用,改为--events [0]
--max-time=N #该参数弃用,改为 --time [0]
--num-threads=N #该参数弃用,改为 --threads [1]
mysql options:
--mysql-host=[LIST,...] # MySQL 服务器地址 ,默认 localhost
--mysql-port=[LIST,...] # MySQL 服务器端口 ,默认 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-compression[=on|off] #是否使用压缩,默认为 off
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
- sbench使用说明
sysbench压测mysql有三个步骤:prepare—>run—>cleanup
- #准备数据
[root@controller sysbench]# sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password='' --mysql-db=test --db-driver=mysql --tables=20 --table-size=50000 --threads=32 prepare
# **--table-size=50000 每张表有多少行数据**
测试:
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password='' --mysql-db=test --db-driver=mysql --tables=10 --table-size=10000 --threads=32 --report-interval=10 --time=120 run
输出结果如下:
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 32
Report intermediate results every 10 second(s)
Initializing random number generator from current time
Initializing worker threads...
Threads started!
[ 10s ] thds: 32 tps: 167.85 qps: 3393.06 (r/w/o: 2379.97/674.19/338.90) lat (ms,95%): 292.60 err/s: 0.00 reconn/s: 0.00
[ 80s ] thds: 32 tps: 224.09 qps: 4478.81 (r/w/o: 3133.37/897.36/448.08) lat (ms,95%): 189.93 err/s: 0.00 reconn/s: 0.00
[ 90s ] thds: 32 tps: 207.20 qps: 4144.37 (r/w/o: 2900.85/829.01/414.51) lat (ms,95%): 227.40 err/s: 0.00 reconn/s: 0.00
[ 100s ] thds: 32 tps: 193.20 qps: 3864.87 (r/w/o: 2705.18/773.29/386.40) lat (ms,95%): 267.41 err/s: 0.00 reconn/s: 0.00
[ 110s ] thds: 32 tps: 221.40 qps: 4427.63 (r/w/o: 3101.75/883.09/442.79) lat (ms,95%): 200.47 err/s: 0.00 reconn/s: 0.00
[ 120s ] thds: 32 tps: 200.10 qps: 4005.51 (r/w/o: 2802.41/802.90/400.20) lat (ms,95%): 248.83 err/s: 0.00 reconn/s: 0.00
SQL statistics:
queries performed:
read: 345366 # 读总数
write: 98676 # 写总数(update,insert,delete语句数量)
other: 49338 #除去dql,dml之外的操作
total: 493380 #全部总数
transactions: 24669 (205.34 per sec.)# tps总事务数
queries: 493380 (4106.82 per sec.)# qps总读写数
ignored errors: 0 (0.00 per sec.)#忽略的错误数
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 120.1348s #指定压测执行完的总时间
total number of events: 24669 # 发生的总事件数(和tps相同)
Latency (ms):
min: 5.31 #最小耗时
avg: 155.75 #平均耗时
max: 2119.39 # 最大耗时
95th percentile: 240.02 #95%平均耗时(在压测是最主要的是看这一项)
sum: 3842312.84 # 总响应时间
Threads fairness:
events (avg/stddev): 770.9062/6.60
execution time (avg/stddev): 120.0723/0.03
清理数据:
[root@controller sysbench]# sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password='' --mysql-db=test --db-driver=mysql --tables=10 --table-size=10000 --threads=32 cleanup
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Dropping table 'sbtest1'...
Dropping table 'sbtest2'...
Dropping table 'sbtest3'...
Dropping table 'sbtest4'...
Dropping table 'sbtest5'...
Dropping table 'sbtest6'...
Dropping table 'sbtest7'...
Dropping table 'sbtest8'...
Dropping table 'sbtest9'...
Dropping table 'sbtest10'...
腾讯云mysql测试表:
> TPS:每秒的事务数,是指客户机向服务器发送请求,服务器做出响应的过程。当客户机发起请求开始计时直到服务器做出响应结束,完成一个事务。
[root@controller sysbench]# sysbench fileio help
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
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 文件操作模式同步、异步或者 mmap,{sync,async,mmap}默认 [sync]
--file-async-backlog=N 每个线程对应的异步操作数,默认 [128]
--file-extra-flags=[LIST,...] 打开文件时使用的标志列表,有 {sync,dsync,direct} []
--file-fsync-freq=N 执行 fsync()函数的频率,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]
磁盘IO压测数据需要经过三个阶段:prepare(准备测试文件 ) --> run --> cleanup
准备阶段:创建4个文件,每个文件在512M。
[root@controller sysbench]# sysbench fileio --file-num=4 --file-total-size=2G prepare
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
4 files, 524288Kb each, 2048Mb 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
2147483648 bytes written in 7.98 seconds (256.66 MiB/sec)
- 测试随机读性能:
[root@controller sysbench]# sysbench fileio --time=180 --events=100000 --threads=1 --file-num=4 --file-total-size=2G --file-io-mode=sync --file-test-mode=rndrd --file-block-size=16384 run
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
Extra file open flags: (none)
4 files, 512MiB each
2GiB total file size
Block size 16KiB
Number of IO requests: 100000
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: 6147.09
writes/s: 0.00
fsyncs/s: 0.00 # 每秒内存向磁盘中同步的数量
Throughput:
read, MiB/s: 96.05
written, MiB/s: 0.00
General statistics:
total time: 16.2644s
total number of events: 100000
Latency (ms):
min: 0.00
avg: 0.16
max: 15.41
95th percentile: 0.46
sum: 16092.22
Threads fairness:
events (avg/stddev): 100000.0000/0.00
execution time (avg/stddev): 16.0922/0.00
3 测试随机读写:
[root@controller sysbench]# sysbench fileio --time=180 --events=100000 --threads=1 --file-num=4 --file-total-size=2G --file-io-mode=sync --file-test-mode=rndrw --file-block-size=16384 run
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
Threads started!
File operations:
reads/s: 3004.88
writes/s: 2003.22
fsyncs/s: 200.42
Throughput:
read, MiB/s: 46.95
written, MiB/s: 31.30
General statistics:
total time: 19.1978s
total number of events: 100000
Latency (ms):
min: 0.00
avg: 0.19
max: 232.44
95th percentile: 0.80
sum: 19015.35
Threads fairness:
events (avg/stddev): 100000.0000/0.00
execution time (avg/stddev): 19.0154/0.00
查看压测cpu的参数:
$ sysbench cpu help
sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2)
cpu options:
--cpu-max-prime=N 产生最大素数限制,默认为[10000]
[root@controller sysbench]# sysbench cpu --time=300 --threads=4 run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 4
Initializing random number generator from current time
Prime numbers limit: 10000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 773.76 # 每秒创建events的数量
General statistics:
total time: 300.0018s-- 执行的总时长
total number of events: 232132 # 总共创建的events数量
Latency (ms):
min: 1.04
avg: 5.16
max: 309.46
95th percentile: 36.24# 95%events执行时间
sum: 1198185.99
Threads fairness:
events (avg/stddev): 58033.0000/100.95
execution time (avg/stddev): 299.5465/0.12
[root@controller sysbench]# sysbench memory --time=300 --threads=4 run
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 4
Initializing random number generator from current time
Running memory speed test with the following options:
block size: 1KiB
total size: 102400MiB
operation: write
scope: global
Initializing worker threads...
Threads started!
Total operations: 104857600 (3638904.18 per second)
102400.00 MiB transferred (3553.62 MiB/sec)
General statistics:
total time: 28.8132s
total number of events: 104857600
Latency (ms):
min: 0.00
avg: 0.00
max: 82.02
95th percentile: 0.00
sum: 51511.44
Threads fairness:
events (avg/stddev): 26214400.0000/0.00
execution time (avg/stddev): 12.8779/0.49