sysbench是基于LuaJIT的可编写脚本的多线程基准测试工具。它最常用于数据库基准测试,但也可以用于创建不涉及数据库服务器的任意复杂的工作负载。
参考官方文档:https://github.com/akopytov/sysbench
sysbench支持一下性能测试:
- cpu:cpu性能测试
- memory:内存测试
- fileio:文件系统IO性能测试
- threads:基于多线程测试
- mutex:posix性能测试
- oltp_*.lua:OLTP样数据库基准测试的集合
centos安装方法
- 二进制安装
RHEL / CentOS:
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench
[root@bogon ~]# sysbench --version
sysbench 1.0.18
OLTP测试
TPS,QPS相关概念
QPS:Queries Per Second 查询量/秒,是一台服务器每秒能够相应的查询次数,是对一个特定的查询服务器在规定时间内所处理查询量多少的衡量标准
TPS : Transactions Per Second 是事务数/秒,是一台数据库服务器在单位时间内处理的事务的个数。
OLTP测试:
准备阶段:
sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=10000 --mysql-table-engine=innodb --oltp-tables-count=10 --mysql-user=sb_test --mysql-password=sb_test --mysql-port=3306 --mysql-host=10.xx.xx.xxx --mysql-db=sb_test --max-requests=0 --time=10 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on prepare
测试阶段:
命令如下:
sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=10000 --mysql-table-engine=innodb --oltp-tables-count=10 --mysql-user=sb_test --mysql-password=sb_test --mysql-port=3306 --mysql-host=10.xx.xx.xxx --mysql-db=sb_test --max-requests=0 --time=10 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on run
清理阶段:
sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=10000 --mysql-table-engine=innodb --oltp-tables-count=10 --mysql-user=sb_test --mysql-password=sb_test --mysql-port=3306 --mysql-host=10.xx.xx.xxx --mysql-db=sb_test --max-requests=0 --time=10 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on cleanup
参数详情
通过命令sysbench –help可以了解各参数的具体解释
--test=tests/db/oltp.lua (新版本已经弃用)表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
--threads:客户端的并发连接数
--time:测试执行的时间,单位是秒,该值不要太短,可以选择120
--report-interval:生成报告的时间间隔,单位是秒,如10
--oltp_tables_count=10 表示会生成 10 个测试表
--oltp-table-size=100000 表示每个测试表填充数据量为 100000
--mysql-engine-trx=STRING指定不同的存储引擎测试。
--oltp-test-mode=STRING测试类型:simple(简单select测试),complex(事务测试),nontrx(非事务测试),sp(存储过程) ;默认complex
--oltp-sp-name=STRING指定存储过程进行语句测试
--oltp-table-size=N指定表的记录大小,默认[10000]
--oltp-num-tables=N指定测试表的数量,默认1
--rand-init=on 表示每个测试表都是用随机数据来填充的
--file-num=N创建测试文件的数量,默认128个
--file-block-size=N block size大小,默认16K
--file-total-size=SIZE所有文件的总大小,默认2G
--file-test-mode=STRING测试类型 {seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)} --file-io-mode=STRING I/O模式,需要系统支持默认sync[sync(同步IO),async(异步IO),mmap()]
--file-async-backlog=N每个线程的异步操作队列数,默认128个,需要--file-io-mode=async;
--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []
--file-fsync-freq=N当请求数达到多少时执行fsync()刷新,默认100,0代表过程中不执行fsync()
--file-fsync-all=[on|off] 执行每一个写操作后执行fsync()刷新操作,默认关闭off --file-fsync-end=[on|off] 测试结束执行fsync()操作,默认开启on --file-fsync-mode=STRING 同步刷新方法,默认fsync {fsync, fdatasync} --file-merged-requests=N合并指定数量的IO请求,0代表不合并,默认0 --file-rw-ratio=N 读写比例,默认1.5/1

本文详细介绍了基于LuaJIT的多线程基准测试工具Sysbench的使用方法,包括CPU、内存、文件IO及OLTP数据库基准测试。文章提供了在CentOS上的安装步骤,并深入解析了OLTP测试的准备、执行及清理阶段的命令参数。
1116

被折叠的 条评论
为什么被折叠?



