sysbench是一个很不错的数据库性能测试工具。
官方站点:https://github.com/akopytov/sysbench/
rpm包下载:https://packagecloud.io/akopytov/sysbench/packages/el/7/sysbench-1.0.15-1.el7.CentOS.x86_64.rpm
源码包下载:https://github.com/akopytov/sysbench/archive/1.0.15.tar.gz
如果是编译安装,需要先安装好mysql的开发包(尽管编译错误时提示的是缺少Mysql库文件)。
yum -y install mysql-community-devel
tar xf 1.0.15.tar.gz
cd sysbench-1.0.15
./autogen.sh
./configure
make -j
make install
安装后,只有一个二进制文件sysbench,还提供了很多个lua脚本。
[root@s1 ~]# rpm -ql sysbench | grep 'bin\|lua'
/usr/bin/sysbench
/usr/share/sysbench/bulk_insert.lua
/usr/share/sysbench/oltp_common.lua
/usr/share/sysbench/oltp_delete.lua
/usr/share/sysbench/oltp_insert.lua
/usr/share/sysbench/oltp_point_select.lua
/usr/share/sysbench/oltp_read_only.lua
/usr/share/sysbench/oltp_read_write.lua
/usr/share/sysbench/oltp_update_index.lua
/usr/share/sysbench/oltp_update_non_index.lua
/usr/share/sysbench/oltp_write_only.lua
/usr/share/sysbench/select_random_points.lua
/usr/share/sysbench/select_random_ranges.lua
/usr/share/sysbench/tests/include/inspect.lua
/usr/share/sysbench/tests/include/oltp_legacy/bulk_insert.lua
/usr/share/sysbench/tests/include/oltp_legacy/common.lua
/usr/share/sysbench/tests/include/oltp_legacy/delete.lua
/usr/share/sysbench/tests/include/oltp_legacy/insert.lua
/usr/share/sysbench/tests/include/oltp_legacy/oltp.lua
/usr/share/sysbench/tests/include/oltp_legacy/oltp_simple.lua
/usr/share/sysbench/tests/include/oltp_legacy/parallel_prepare.lua
/usr/share/sysbench/tests/include/oltp_legacy/select.lua
/usr/share/sysbench/tests/include/oltp_legacy/select_random_points.lua
/usr/share/sysbench/tests/include/oltp_legacy/select_random_ranges.lua
/usr/share/sysbench/tests/include/oltp_legacy/update_index.lua
/usr/share/sysbench/tests/include/oltp_legacy/update_non_index.lua
本文介绍的是新版本sysbench oltp lua脚本的用法(/usr/share/sysbench/*.lua),所以不涉及传统的lua(tests/include/oltp_legacy/*.lua),如果想要了解这些传统Lua脚本的用法,网上随便找。
2.sysbench使用方法
以下列出了sysbench对测试mysql时常用的选项。
[root@xuexi ~]# sysbench --help
Usage:
sysbench [options]... [test_lua] [lua_options] [command]
Commands implemented by most tests: prepare run cleanup help
通用选项:以下中括号中的值表示默认值
--threads=N 指定线程数[1]
--events=N 限制最大请求数,0表示不限制[0]
--time=N 限制最长执行时间,0表示不限制[10]
--events和--time二者选一即可
--forced-shutdown=STRING 达到最长执行时间后还需等待多久关闭sysbench
off表示禁用该功能[off]
--thread-stack-size=SIZE 每个线程使用的栈空间大小[64K]
--rate=N 平均事务处理速率,0表示不限制[0]
--report-interval=N 每隔几秒报告一次结果,0表示禁用间隔报告[0]
--config-file=FILENAME 从文件中读取命令行选项
--tx-rate=N 已废弃,是--rate的别名[0]
--max-requests=N 已废弃,是--events的别名[0]
--max-time=N 已废弃,是--time的别名[0]
--num-threads=N 已废弃,是--threads的别名[1]
mysql相关选项:
--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-ignore-errors=[LIST,...] 要忽略的错误代码,值可为"all" [1213,1020,1205]