使用sysbench进行oltp测试之前,首先要确定sysbench的版本,Ubuntu中默认的apt-get版本为0.4.12,在执行数据准备时,参数不同会出错!
ubuntu版本: 18.6
sysbench版本
在oltp测试中,基本分为三个阶段:
1、初始化数据
需要在数据库中提前创建好sbtest数据库,若不创建,也可使用参数指定对应的数据库,进行数据插入准备
根据自己电脑的实际情况拼写参数,如,mysql-user和mysql-password分别对应的是数据库的登录名和密码,mysql-socket需要指定mysql.sock文件的位置【查看my.cnf配置文件】
sysbench --test=oltp.lua --mysql-table-engine=innodb --oltp-tables-count=3 --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 --mysql-socket=/var/lib/mysql/mysql.sock prepare
参数:
–mysql-db=test //测试数据库
–mysql-user=root //用户名
–myssql-password=123456 //密码
–oltp-tables-count=8 //表的数量
–oltp-table-size=100000 //每张表记录为10万
–mysql-sock=/var/lib/mysql/mysql.sock //mysql.sock路径,本地连接时可指定host ip连接,也可直接使用Mysql.sock连接
执行完建表语句后,生成一下数据
执行结果:在使用root账户登录数据库,在sbtest数据库中插入三张表,每张表1000000条数据
2、执行测试
sysbench --test=oltp.lua --mysql-table-engine=innodb --oltp-tables-count=3 --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 --mysql-socket=/var/lib/mysql/mysql.sock --max-time=60 --max-requests=0 --num-threads=8 --report-interval=10 run
新增的几个参数选项:
–num-threads=8 //线程数为8
–max-time=60 //测试时间为60s
–report-interval=10 //报告打印周期为10s,每10s打印一次
–oltp-read-only=off //非只读操作测试
最重要的参数指标:
总的事务数,每秒事务数,时间统计信息(最大、最小、平均、95%以上语句响应时间)
3、清理数据
sysbench --test=oltp.lua --mysql-table-engine=innodb --oltp-tables-count=3 --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 --mysql-socket=/var/lib/mysql/mysql.sock cleanup
测试过程中的问题:
1、oltp的位置指定,报错找不到对应的oltp.lua文件
注:此处需要指定oltp.lua脚本位置,sysbench5默认已经指定,如果按照网上或者树上的语句,提示如下报错,找不到对应的文件,发现自己写的路径前又追加了sysbench自带的路径,直接指定到了sysbench子文件夹。
需要改变路径,直接指定oltp.lua即可
sysbench --test=oltp.lua --mysql-table-engine=innodb --oltp-tables-count=3 --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 --mysql-socket=/var/lib/mysql/mysql.sock prepare