sysbench并不是一个压力测试工具,是一个基准测试工具。linux自带的版本比较低,我们需要自己安装sysbench。
sysbench支持以下几种测试模式:
1、CPU运算性能
2、磁盘IO性能
3、调度程序性能
4、内存分配及传输速度
5、POSIX线程性能
6、数据库性能(OLTP基准测试)
一、安装Sysbench
1、检查linux是否安装
[root@home-server-60 mysqlTest]# sysbench --version
sysbench 1.0.17
2、如果没有安装,则要手动安装
下载地址:https://github.com/akopytov/sysbench
二、基准测试OLTP
sysbench 有自带的测试脚本,包含:insert.lua、oltp.lua、parallel_prepare.lua、select_random_points.lua、update_index.lua、delete.lua oltp_simple.lua、select.lua、select_random_ranges.lua、update_non_index.lua。
1、mysql准备
-- 创建数据库
CREATE DATABASE sbtest;
-- 创建用户
create user 'sbtest'@'%' identified by 'sbtest';
GRANT ALL PRIVILEGES ON *.* TO sbtest@'%' IDENTIFIED BY 'sbtest' WITH GRANT OPTION;
FLUSH PRIVILEGES ;
-- 删除测试数据库
drop database sbtest;
2、sysbench 准备
执行模式为complex,使用了10个表,每个表有10万条数据,客户端的并发线程数为10,执行时间为120秒,每10秒生成一次报告。
sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=root --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 prepare
3、sysbench 运行
//将测试结果导出到文件中,便于后续分析
sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=root --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 run >> sysbench.log
4、sysbench清理
//执行完测试后,清理数据,否则后面的测试会受到影响
sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=root cleanup
5、测试结果
多表测试请看这篇:
https://blog.csdn.net/luoqinglong850102/article/details/104341695