MySQL基准测试工具:sysbench 新手入门体验

sudo apt install -y automake

sudo apt install -y libtool

sudo apt install -y pkg-config

sudo apt install -y libmysqlclient-dev

4、cd cd sysbench-1.0.20/

5、./autogen.sh

6、./configure

7、sudo make -j

8、sudo make install

9、sysbench --version


sysbench语法


sysbench的基本语法如下:

sysbench [options]… [testname] [command]

command:sysbench要执行的命令,包括:

prepare:为测试提前准备数据

run:执行正式的测试

cleanup:在测试完成后对数据库进行清理


在新版本中,–test参数已经声明为废弃,可以不使用–test,而是直接指定脚本。

sysbench ./tests/include/oltp_legacy/oltp.lua

测试时使用的脚本为lua脚本,可以使用sysbench自带脚本,也可以自己开发。对于大多数应用,使用sysbench自带的脚本就足够了。


sysbench的options参数有很多,其中比较常用的包括:

MySQL连接信息参数

–mysql-host:MySQL服务器主机名,默认localhost;如果在本机上使用localhost报错,提示无法连接MySQL服务器,改成本机的IP地址应该就可以了。

–mysql-port:MySQL服务器端口,默认3306

–mysql-user:用户名

–mysql-password:密码

MySQL执行参数

–oltp-test-mode:执行模式,包括simple、nontrx和complex,默认是complex。simple模式下只测试简单的查询;nontrx不仅测试查询,还测试插入更新等,但是不使用事务;complex模式下测试最全面,会测试增删改查,而且会使用事务。可以根据自己的需要选择测试模式。

–oltp-tables-count:测试的表数量,根据实际情况选择

–oltp-table-size:测试的表的大小,根据实际情况选择

–threads:客户端的并发连接数

–time:测试执行的时间,单位是秒,该值不要太短,可以选择120

–report-interval:生成报告的时间间隔,单位是秒,如10


使用示例


准备数据:

sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 prepare

执行模式为complex,使用了10个表,每个表有10万条数据,客户端的并发线程数为10,执行时间为120秒,每10秒生成一次报告。

执行测试:

sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 run >> ./mysysbench.log

将测试结果导出到文件中,便于后续分析。

清理数据:

sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=100000 ./tests/include/oltp_legacy/oltp.lua cleanup

执行完测试后,清理数据,否则后面的测试会受到影响。


结果分析


参数信息部分:

sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:

Number of threads: 10

Report intermediate results every 10 second(s)

Initializing random number generator from current time

中间过程信息部分:

Initializing worker threads…

Threads started!

[ 10s ] thds: 10 tps: 477.40 qps: 9560.77 (r/w/o: 6694.08/1910.89/955.80) lat (ms,95%): 29.72 err/s: 0.00 reconn/s: 0.00

[ 20s ] thds: 10 tps: 451.43 qps: 9027.75 (r/w/o: 6319.48/1805.41/902.85) lat (ms,95%): 30.81 err/s: 0.00 reconn/s: 0.00

[ 30s ] thds: 10 tps: 424.02 qps: 8484.10 (r/w/o: 5938.15/1697.90/848.05) lat (ms,95%): 33.12 err/s: 0.00 reconn/s: 0.00

[ 40s ] thds: 10 tps: 410.76 qps: 8212.31 (r/w/o: 5749.55/1641.24/821.52) lat (ms,95%): 34.33 err/s: 0.00 reconn/s: 0.00

[ 50s ] thds: 10 tps: 394.41 qps: 7885.10 (r/w/o: 5519.27/1577.02/788.81) lat (ms,95%): 35.59 err/s: 0.00 reconn/s: 0.00

[ 60s ] thds: 10 tps: 395.00 qps: 7900.35 (r/w/o: 5530.06/1580.39/789.89) lat (ms,95%): 35.59 err/s: 0.00 reconn/s: 0.00

[ 70s ] thds: 10 tps: 387.90 qps: 7758.49 (r/w/o: 5431.66/1551.02/775.81) lat (ms,95%): 36.89 err/s: 0.00 reconn/s: 0.00

[ 80s ] thds: 10 tps: 386.48 qps: 7730.24 (r/w/o: 5410.45/1546.73/773.06) lat (ms,95%): 37.56 err/s: 0.00 reconn/s: 0.00

[ 90s ] thds: 10 tps: 396.70 qps: 7936.20 (r/w/o: 5556.07/1586.72/793.41) lat (ms,95%): 36.24 err/s: 0.00 reconn/s: 0.00

[ 100s ] thds: 10 tps: 400.21 qps: 8005.64 (r/w/o: 5604.10/1601.13/800.41) lat (ms,95%): 36.89 err/s: 0.00 reconn/s: 0.00

[ 110s ] thds: 10 tps: 398.60 qps: 7970.64 (r/w/o: 5579.33/1594.11/797.20) lat (ms,95%): 36.89 err/s: 0.00 reconn/s: 0.00

[ 120s ] thds: 10 tps: 393.49 qps: 7866.67 (r/w/o: 5506.31/1573.47/786.89) lat (ms,95%): 38.94 err/s: 0.00 reconn/s: 0.00

结果统计信息部分:

SQL statistics:

queries performed:

read: 688464

write: 196704

other: 98352

total: 983520

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值