使用Sysbench对Mysql进行基准测试
目录
安装
》检查是否已经安装
# sysbench --version // 已安装会显示对应的版本》下载
# wget https://github.com/akopytov/sysbench/archive/0.5.zip》解压
# unzip 0.5.zip -d /usr/local》切换目录
# cd /usr/local/usysbench-0》运行shell进行环境检查,缺什么就使用yum安装什么
# ./autogen.sh
解决缺少automake
# yum install -y automake
解决缺少libtoolize
# yum install -y libtool》配置
# ./configure --with-mysql-includes={mysql/include} --with-mysql-libs={mysql/lib}
变量{mysql/include}是mysql安装目录下的include文件路径
变量{mysql/lib}是mysql安装目录下的lib文件路径
例:./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib
【可选】如果找不到 include 跟 lib 文件路径,可以使用命令查看:
# mysql_config --include OR # mysql_config-64 --include //查看include文件路径
# mysql_config --libs OR # mysql_config-64 --libs // 查看lib文件路径【可选】还是找不到那就试试这个命令
# yum install -y mysql-devel》编译与安装
# make
# make install
语法
# sysbench [options]
常用参数说明
帮助命令:# sysbench --test={test} help
- --test=fileio | cpu | memory | oltp 用于指定所要执行的测试类型
fileio:文件系统I/O性能测试
cpu:CPU性能测试
memory:内存性能测试
oltp:测试要指定具体的lua脚本(0.5版本后不支持了改为lua脚本)
lua脚本位于 sysbench目录/sysbench/tests/db- --mysql-db 用于指定执行基准测试的数据库名(默认sbtest)
- --mysql-table-engine 用于指定所使用的存储引擎
- --oltp-tables-count 执行测试的表数量
- --oltp-table-size 指定每个表中的数据行数
- --num-threads 指定测试的并发线程数量
- --max-time 指定最大的测试时间
- --report-interval 指定间隔多长时间输出一次统计信息
- --mysql-user 执行测试的Mysql账户名
- --mysql-password Mysql账户密码
- prepare 用于准备测试数据
- run 用于实际进行测试
- cleanup 用于清理测试数据
测试案例
* 对CPU进行测试(只能单核测试)
# sysbench --test=cpu --cpu-max-prime=10000 run
* 对磁盘I/O进行测试(先生成测试文件)
# sysbench --test=fileio --file-total-size=2G prepare
# sysbench --test=fileio --num-threads=8 --init-rng=on --file-total-size=2G --file-test-mode=rndrw --report-interval=1 run
* 对数据库进行测试
》进入数据库建立一个测试用户
》先进入数据库建立一个测试数据库
》先生成测试数据
# sysbench --test=./oltp.lua --mysql-table-engine=innodb --oltp-table-size=10000 --oltp-tables-count=10 --mysql-db=sbtest --mysql-user=sbtest --mysql-password=123456 --mysql-socket=/var/lib/mysql/mysql.sock prepare》收集数据准备,可以使用脚本来收集Mysql的QPS与TPS
》测试
# sysbench --test=./oltp.lua --mysql-table-engine=innodb --oltp-table-size=10000 --oltp-tables-count=10 --mysql-db=sbtest --mysql-user=sbtest --mysql-password=123456 --mysql-socket=/var/lib/mysql/mysql.sock run》结果
》清除数据
# sysbench --test=./oltp.lua --mysql-table-engine=innodb --oltp-table-size=10000 --oltp-tables-count=10 --mysql-db=sbtest --mysql-user=sbtest --mysql-password=123456 --mysql-socket=/var/lib/mysql/mysql.sock cleanup