数据准备
sysbench /usr/local/share/sysbench/oltp_common.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=Zc1063420481 --tables=10 --table_size=20000000 --threads=100 --max-requests=0 prepare
oltp测试
sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=Zc1063420481 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=200000 --threads=10 --time=120 --report-interval=10 run >> /home/test/mysysbench.log
纯读模式
sysbench ./tests/include/oltp_legacy/select.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=Zc1063420481 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=200000 --threads=10 --time=120 --report-interval=10 run >> /home/test/mysysbench.log
sysbenh测试工具命令,根据测试需要调整参数sysbench [options]… [testname] [command]
sysbench --help 查看命令的基本参数
表5-1
选项[options] | 备注 |
---|---|
–test | 脚本路径 oltp.lua |
–mysql-db | 测试库名称 |
–mysql-host | 数据库IP地址 |
–mysql-port | 端口号 默认3306 |
–mysql-user | 数据库用户名,一般是root |
–mysql-password | 数据库密码 |
在老版本的sysbench中,可以通过–test参数指定测试的脚本;
而在新版本中,–test参数已经声明为废弃,可以不使用–test,而是直接指定脚本。如下两种结果相同
测试项[testname] | 备注 |
---|---|
–oltp-tables-count | 建表数量 |
–oltp-table-size | 每张表的数据量,默认[10000] |
–time=N | 限制的总执行时间,默认为10s |
–threads=N | 需要使用的线程数,默认为1 |
–report-interval=N | 指定间隔(秒)报告统计信息,默认为0,禁用 |
–oltp-test-mode=complex | 测试模式,默认complex |
–oltp-test-mode 运行模式包括:
simple 模式下只测试简单的查询;
nontrx 不仅测试查询,还测试插入更新等,但是不使用事务;
complex 模式下测试最全面,会测试增删改查,而且会使用事务。
备注:如果需要特别测试服务器只读性能,或不使用事务时的性能,可以
选择simple模式或nontrx模式。
命令[command] | 备注 |
---|---|
prepare | 准备测试数据 |
run | 执行测试 |
cleanup | 清理数据 |