12
09
Mysql系列-压测工具使用
2020 19:32:10
by
chenjuntao
|
0 评论
一、sysbench简介
sysbench工具可以自动在数据库里构造出大量的数据,然后工具可以模拟几千个线程并发访问数据库,模拟使用各种各样的sql语句访问数据库,包括模拟出来各种事务提交到数据库,甚至可以模拟出几十万的TPS去压测数据库。
二、linux上安装sysbench工具
基于yum安装sysbench
[root@localhost etc]# curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
[root@localhost etc]# sudo yum -y install sysbench
[root@localhost etc]# sysbench --version
sysbench 1.0.20
三、数据库压测的测试用例
创建测试库:test_db, 基于sysbench构建20个测试表,每个表100万条数据,使用10个并发线程去对数据库发起访问,连续访问5分钟,也就是300秒,对其进行压力测试
四、基于sysbench构建测试表和测试数据
[root@localhost etc]# sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=localhost --mysql-port=3306 --mysql-user=taotao --mysql-password=taotao --mysql-db=
test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable prepare
- --db-driver=mysql : 基于mysql的驱动去连接mysql数据库
- --time=300 : 连续访问300秒
- --threads=10: 10个线程模拟并发访问
- --report-interval=1 : 每隔1秒输出压测情况
- --mysql-host=localhost --mysql-port=3306 --mysql-user=taotao --mysql-password=taotao : 连接mysql数据库
- --mysql-db=test_db --tables=20 --table_size=1000000:在test_db库,构造20个测试表,每个测试表里构造10万条测试数据
- oltp_read_write:执行oltp数据库的读写测试
- --db-ps-mode=disable:禁止ps模式
- prepare : 构造数据库里的数据
五、对数据库进行全面压测
测试数据库的综合读写TPS,使用oltp_read_write模式,注命令最后使用run运行压测;
[root@localhost etc]# sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=localhost --mysql-port=3306 --mysql-user=taotao --mysql-password=taotao --mysql-db=
test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable run
测试数据库的只读性能,使用oltp_read_only模式;
[root@localhost etc]# sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=localhost --mysql-port=3306 --mysql-user=taotao --mysql-password=taotao --mysql-db=
test_db --tables=20 --table_size=1000000 oltp_read_only --db-ps-mode=disable run
测试数据库的删除性能,使用oltp_delete模式;
测试数据库的更新索引字段的性能,使用oltp_update_index模式;
测试数据库的更新非索引字段的性能,使用oltp_update_non_index模式;
测试数据库的插入性能,使用oltp_insert模式;
测试数据库的写入性能,使用oltp_write_only模式;
压测完之后,可以执行cleanup命令,清理数据
[root@localhost etc]# sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=localhost --mysql-port=3306 --mysql-user=taotao --mysql-password=taotao --mysql-db=
test_db --tables=20 --table_size=1000000 oltp_read_only --db-ps-mode=disable cleanup
六、压测试结果分析
[ 300s ] thds: 10 tps: 137.04 qps: 2758.80 (r/w/o: 1927.56/557.16/274.08) lat (ms,95%): 125.52 err/s: 0.00 reconn/s: 0.00
第300s输出的压测统计报告
- thds: 10 :10个线程在压测
- tps: 137.04 :每秒执行137.04个事务
- qps: 2758.80 : 每秒执行2758.80个请求
- (r/w/o: 1927.56/557.16/274.08):在每秒2758.8个请求中, 1927.56个请求是读请求,557.16个请求是写请求,274.08个请求是其他请求,对qps进行拆解
- lat (ms,95%): 125.52:95%的请求延迟都在125.52毫秒以下
- err/s: 0.00 reconn/s: 0.00 :每秒0个请求失败,0个网络重连
压测总报告:
SQL statistics:
queries performed:
read: 664608 #300s的压测执行60万多次读请求
write: 189888 #300s的压测执行18万多次写请求
other: 94944 #300s的压测执行9万多次其他请求
total: 949440 #一共执行90万多次请求
transactions: 47472 (158.23 per sec.) #一共执行4万多个事务,每秒执行158.23个事务
queries: 949440 (3164.57 per sec.) # 一共执行90万多次请求,每秒执行3164+请求
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 300.0204s
total number of events: 47472
Latency (ms):
min: 4.68 #请求中延迟最小的是4.68
avg: 63.20 #所有请求平均延时
max: 682.75 #延时最大的请求
95th percentile: 121.08 #95%的请求延时
sum: 3000003.82
Threads fairness:
events (avg/stddev): 4747.2000/17.11
execution time (avg/stddev): 300.0004/0.00