sysbench测试工具
一、安装
下载地址:https://github.com/akopytov/sysbench/archive/1.0.17.tar.gz
1、安装依赖,否则报错
yum -y install m4 autoconf automake libtool
2、安装sysbench
解决依赖库的问题:
cp /export/servers/mysql/lib/libmysqlclient.so.20.3.11 /usr/lib64/libmysqlclient.so.20
tar -zxvf sysbench-1.0.17.tar.gz
cd sysbench-1.0.17
./autogen.sh
./configure --prefix=/usr/local/sysbench -with-mysql-includes=/export/servers/mysql/include --with-mysql-libs=/export/servers/mysql/lib
make
make install
ln -s /usr/local/sysbench/bin/sysbench /usr/bin/sysbench
二、测试
1、准备数据(prepare)
sysbench /usr/local/sysbench/share/sysbench/tests/include/oltp_legacy/select.lua \
--oltp-tables-count=4 \
--oltp-table-size=1000000 \
--oltp-dist-type=special \
--oltp-dist-pct=1 \
--oltp-dist-res=95 \
--mysql-host=127.0.0.1 \
--mysql-port=3358 \
--mysql-user=root \
--mysql-password= \
--threads=16 \
--max-requests=0 \
--time=300 \
--report-interval=3 \
prepare
默认库名:sbtest(需要提前创建)
默认表名:sbtest1........(自动创建)
oltp-tables-count=4:表的个数
oltp-table-size=1000000:每个表的行数
oltp-dist-type=special:测试方式,结合oltp-dist-pct和oltp-dist-res
oltp-dist-pct=1:热点数据的比例,1即为1%
oltp-dist-res=95:热点数据的访问频率,95即为95%的占比
threads=16:线程并发数(老版本为num-threads)
max-requests=0:测试请求数,0代表无限大(因为该例子通过time控制)
time=300:测试时间:300s(老版本为max-time)
report-interval=3:每隔3s打印一次测试结果
prepare:创建测试表级准备测试数据
2、只读测试(是用select.lua脚本)
sysbench /usr/local/sysbench/share/sysbench/tests/include/oltp_legacy/select.lua \
--oltp-tables-count=4 \
--oltp-table-size=1000000 \
--oltp-dist-type=special \
--oltp-dist-pct=1 \
--oltp-dist-res=95 \
--mysql-host=127.0.0.1 \
--mysql-port=3358 \
--mysql-user=root \
--mysql-password= \
--threads=16 \
--max-requests=0 \
--time=300 \
--report-interval=3 \
run
测试结果如下,该测试重点关注qps:
[ 3s ] thds: 16 tps: 190138.27 qps: 190138.27 (r/w/o: 190138.27/0.00/0.00) lat (ms,95%): 0.11 err/s: 0.00 reconn/s: 0.00
[ 6s ] thds: 16 tps: 192742.96 qps: 192742.96 (r/w/o: 192742.96/0.00/0.00) lat (ms,95%): 0.10 err/s: 0.00 reconn/s: 0.00
[ 9s ] thds: 16 tps: 190613.93 qps: 190613.93 (r/w/o: 190613.93/0.00/0.00) lat (ms,95%): 0.11 err/s: 0.00 reconn/s: 0.00
3、OLTP的测试(使用oltp.lua脚本)
sysbench /usr/local/sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua \
--oltp-tables-count=4 \
--oltp-table-size=1000000 \
--oltp-dist-type=special \
--oltp-dist-pct=1 \
--oltp-dist-res=95 \
--mysql-host=127.0.0.1 \
--mysql-port=3358 \
--mysql-user=root \
--mysql-password= \
--threads=32 \
--max-requests=0 \
--time=300 \
--report-interval=3 \
run
测试结果如下,只有针对单业务测试时,tps大小才有比较的意义:
[ 3s ] thds: 32 tps: 943.86 qps: 19046.96 (r/w/o: 13353.52/3795.07/1898.37) lat (ms,95%): 97.55 err/s: 0.00 reconn/s: 0.00
[ 6s ] thds: 32 tps: 1047.67 qps: 20968.77 (r/w/o: 14669.07/4204.36/2095.34) lat (ms,95%): 92.42 err/s: 0.00 reconn/s: 0.00
[ 9s ] thds: 32 tps: 1035.99 qps: 20691.11 (r/w/o: 14490.51/4128.62/2071.98) lat (ms,95%): 90.78 err/s: 0.00 reconn/s: 0.00
4、清理数据
sysbench /usr/local/sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua \
--oltp-tables-count=4 \
--oltp-table-size=1000000 \
--oltp-dist-type=special \
--oltp-dist-pct=1 \
--oltp-dist-res=95 \
--mysql-host=127.0.0.1 \
--mysql-port=3358 \
--mysql-user=root \
--mysql-password= \
--threads=32 \
--max-requests=0 \
--time=300 \
--report-interval=3 \
cleanup
会将默认库下面的对应测试表执行drop table操作
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?