1.5.1 sysbench使用介绍(待整理成自己的环境的结果)


转载:http://www.unixfbi.com/522.html

一、sysbench 介绍

sysbench 是一个模块化、支持多平台安装运行,多线程的基准测试工具,sysbench,不仅用来测试数据库的性能,也可以测试运行数据库的服务器的性能。
sysbench,不仅用来测试数据库的性能,也可以测试运行数据库的服务器的性能。
oltp 测试主要是结合了 lua 脚本,不需要修改源码,通过自定义 lua 脚本就可以实现不同业务类型的测试。

主要有以下几种方式的测试:
cpu 基准测试
磁盘 I/O 基准测试
内存连续读写性能测试
测试互斥锁性能
测试顺序读写性能
数据库性能 OLTP 基准测试

什么是 OLTP?
On-Line Transaction Processing 联机事务处理过程(OLTP)
也称为面向交易的处理过程,其基本特征是前台接收的用户数据可以立即传送到计算中心进行处理,并在很短的时间内给出处理结果,是对用户操作快速响应的方式之一。

二、sysbench 安装和部分参数介绍

1.安装 sysbench

在 centos7 上

# curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench

  

2.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

  

三、sysbench 使用说明

sysbench 压测 MySQL 有三个步骤:prepare --> run --> cleanup
我们都是使用 sysbench 自带的 lua 脚本来压测 MySQL

1.压测 MySQL

使用 oltp_read_write.lua 脚本压测 MySQL
准备阶段:

mysql -uroot -pllill2018 -e "create database sbtest;" -S /tmp/mysql3308.sock
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=172.16.17.123 --mysql-port=3308  --mysql-user=root --mysql-password='llill2018' --mysql-socket=/tmp/mysql3308.sock --mysql-db=sbtest --db-driver=mysql --tables=20 --table-size=5000000  --threads=32  prepare

  

测试阶段:

sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=172.16.17.123 --mysql-port=3308  --mysql-user=root --mysql-password='llill2018' --mysql-socket=/tmp/mysql3308.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=10000  --threads=32  --report-interval=10 --time=120 run

  

输出结果如下:

sysbench 1.0.14 (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: 266.21 qps: 5355.17 (r/w/o: 3753.19/1066.56/535.43) lat (ms,95%): 186.54 err/s: 0.00 reconn/s: 0.00 [ 20s ] thds: 32 tps: 279.40 qps: 5590.16 (r/w/o: 3914.18/1116.99/559.00) lat (ms,95%): 127.81 err/s: 0.00 reconn/s: 0.00 [ 30s ] thds: 32 tps: 273.60 qps: 5470.54 (r/w/o: 3829.26/1094.09/547.19) lat (ms,95%): 144.97 err/s: 0.00 reconn/s: 0.00 [ 40s ] thds: 32 tps: 258.20 qps: 5169.85 (r/w/o: 3620.43/1033.01/516.40) lat (ms,95%): 248.83 err/s: 0.00 reconn/s: 0.00 [ 50s ] thds: 32 tps: 281.80 qps: 5627.48 (r/w/o: 3936.89/1127.20/563.40) lat (ms,95%): 127.81 err/s: 0.00 reconn/s: 0.00 [ 60s ] thds: 32 tps: 279.50 qps: 5595.15 (r/w/o: 3917.53/1118.41/559.20) lat (ms,95%): 127.81 err/s: 0.00 reconn/s: 0.00 [ 70s ] thds: 32 tps: 278.30 qps: 5565.72 (r/w/o: 3895.85/1113.38/556.49) lat (ms,95%): 132.49 err/s: 0.00 reconn/s: 0.00 [ 80s ] thds: 32 tps: 262.40 qps: 5254.69 (r/w/o: 3679.89/1049.90/524.90) lat (ms,95%): 223.34 err/s: 0.00 reconn/s: 0.00 [ 90s ] thds: 32 tps: 277.50 qps: 5541.91 (r/w/o: 3877.80/1109.20/554.90) lat (ms,95%): 139.85 err/s: 0.00 reconn/s: 0.00 [ 100s ] thds: 32 tps: 276.20 qps: 5522.59 (r/w/o: 3864.99/1105.50/552.10) lat (ms,95%): 137.35 err/s: 0.00 reconn/s: 0.00 [ 110s ] thds: 32 tps: 282.40 qps: 5643.40 (r/w/o: 3949.30/1128.90/565.20) lat (ms,95%): 123.28 err/s: 0.00 reconn/s: 0.00 [ 120s ] thds: 32 tps: 275.30 qps: 5514.88 (r/w/o: 3862.76/1101.62/550.51) lat (ms,95%): 153.02 err/s: 0.00 reconn/s: 0.00 SQL statistics: queries performed: read: 461174 #读总数 write: 131764 #写总数(update、insert、delete 语句数量) other: 65882 #其他操作总数(SELECT、INSERT、UPDATE、DELETE 之外的操作,例如 COMMIT 等) total: 658820 #全部总数 transactions: 32941 (274.10 per sec.) #TPS,总事务数(每秒事务数) queries: 658820 (5482.05 per sec.) #QPS,读写总数(每秒读写次数) ignored errors: 0 (0.00 per sec.) #忽略的错误数 reconnects: 0 (0.00 per sec.) General statistics: total time: 120.1753s #--time 指定的压测时间; total number of events: 32941 #总发生事件数,一般与 transactions 相同; Latency (ms): min: 11.51 #最小耗时 avg: 116.63 #平均耗时 max: 515.65 #最大耗时 95th percentile: 144.97 # 95%平均耗时 sum: 3841840.74 #总响应时间 Threads fairness: events (avg/stddev): 1029.4062/5.26 execution time (avg/stddev): 120.0575/0.04 

清除数据:

$ sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=192.168.199.229 --mysql-port=3306 --mysql-user=root --mysql-password='unixfbi' --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=10000 --threads=32 prepare 

2.压测磁盘 IO

$ sysbench fileio help  
sysbench 1.0.14 (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] 

sysbench 的 file 测试需要也是 prepare、run 和 cleanup 三个阶段。 prepare 是准备阶段,产生需要的测试文件,run 是测试阶段,cleanup 是清理测试产生的文件。
例如,创建 4 个文件,总共大小 2G 的测试:
准备阶段:

# sysbench fileio --file-num=4 --file-total-size=2G prepare 

执行完成后会在当前目录下生成 test_file.0-4 总共 4 个文件。每个文件大小为 512M,总共 2G 大小。
输出结果:

sysbench 1.0.14 (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 12.91 seconds (158.59 MiB/sec). 

下面进行 180 秒测试,线程数 1 个,随机数请求 100000000 次,随机读性能。
执行测试:

# sysbench fileio --time=180 --events=100000000 --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.14 (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: 100000000 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! File operations: reads/s: 153.62 #每秒读次数 writes/s: 102.41 #每秒写次数 fsyncs/s: 10.23 #每秒从内存向磁盘同步的次数 Throughput: #吞吐量 read, MiB/s: 2.40 written, MiB/s: 1.60 General statistics: total time: 180.0377s total number of events: 47942 Latency (ms): min: 0.00 avg: 3.75 max: 362.37 95th percentile: 10.09 sum: 179980.36 Threads fairness: events (avg/stddev): 47942.0000/0.00 execution time (avg/stddev): 179.9804/0.00 

IOPS = reads/s + writes/s
清除测试产生的文件:

# sysbench fileio  --file-num=4 --file-total-size=2G cleanup 

3.对 CPU 压测

查看压测 CPU 都有哪些参数:

$ sysbench cpu help
sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) cpu options: --cpu-max-prime=N 产生最大素数限制,默认为[10000] 

例如:

# sysbench cpu --time=300 --threads=4 run sysbench 1.0.14 (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: 4500.61 #每秒创建 events 数量 General statistics: total time: 300.0009s # --time 执行测试的时间 total number of events: 1350193 #总共创建的 events 数量 Latency (ms): min: 0.86 #最小执行时间 avg: 0.89 #平均执行时间 max: 14.88 #最大执行时间 95th percentile: 0.89 #95% events 执行时间 sum: 1199686.48 #总时间 Threads fairness: events (avg/stddev): 337548.2500/360.93 execution time (avg/stddev): 299.9216/0.01 

4.内存压测

$ sysbench memory help
sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) memory options: --memory-block-size=SIZE #内存块大小,默认 [1K] --memory-total-size=SIZE 传输数据的总大小[100G] --memory-scope=STRING 内存访问范围,参数{global,local},默认为 [global] --memory-hugetlb[=on|off] 是否从 HugeTLB pool 分配内存,默认为 [off] --memory-oper=STRING 内存操作类型 {read, write, none} 默认为[write] --memory-access-mode=STRING 内存访问模式 {seq,rnd} 默认为[seq] 

参考文档:

https://github.com/akopytov/sysbench
http://www.cnblogs.com/Aiapple/p/5705415.html
http://www.ywnds.com/?p=10111
https://blog.csdn.net/zyzzxycj/article/details/79555660
https://blog.csdn.net/qq_42000667/article/details/79949291
https://baike.baidu.com/item/OLTP/5019563?fr=aladdin
https://www.jianshu.com/p/9823b4aa445a
https://baike.baidu.com/item/IOPS/3105194
http://www.cnblogs.com/muahao/p/6340343.html
http://www.cnblogs.com/muahao/p/6340343.html

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM