标签搜索

目 录CONTENT

文章目录

如何压测MySQL

陈铭
2023-09-19 / 0 评论 / 0 点赞 / 130 阅读 / 722 字 / 正在检测是否收录...

安装命令

我创建了一个容器,安装命令来压测

docker run --rm -it centos:7 /bin/bash

# 进入容器后
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | bash
yum -y install sysbench

# 查看版本
sysbench --version

构造测试表和数据

sysbench --db-driver=mysql \
--time=10 \
--threads=10 \
--report-interval=1 \
--mysql-host=<ip> \
--mysql-port=<port> \
--mysql-user=<username> \
--mysql-password=<password> \
--mysql-db=cm_test \
--tables=10 \
--table_size=100000 \
oltp_read_write \
--db-ps-mode=disable \
prepare
参数 含义
–db-driver=mysql 这个很简单,就是说他基于mysql的驱动去连接mysql数据库,你要是oracle,或者sqlserver,那自然就是其他的数据库的驱动了
–time=10 这个就是说连续访问10秒
–threads=10 这个就是说用10个线程模拟并发访问
–report-interval=1 这个就是说每隔1秒输出一下压测情况
–mysql-host=<ip> 这是你要连接的sql服务连接
–db-driver=mysql 这个很简单,就是说他基于mysql的驱动去连接mysql数据库,你要是oracle,或者sqlserver,那自然就是其他的数据库的驱动了
–mysql-port=<port> 数据端口
–mysql-user=<username> 数据库用户名
–mysql-password=<password> 数据库密码
–mysql-db=cm_test 哪个数据库进行压测,需要手动创建库
–tables=10 压测数据库创建多少张表
–table_size=1000000 压测数据库每张表插入多少数据
oltp_read_write 执行oltp数据库的读写测试
–db-ps-mode=disable 禁止ps模式(不知道干嘛的)
prepare 参照这个命令的设置去构造出来我们需要的数据库里的数据,他会自动创建20个测试表,每个表里创建100万条测试数据

开始压测

从10个线程开始压,压10秒,同时读写操作

sysbench --db-driver=mysql \
--time=10 \
--threads=10 \
--report-interval=1 \
--mysql-host=<ip> \
--mysql-port=<port> \
--mysql-user=<username> \
--mysql-password=<password> \
--mysql-db=cm_test \
--tables=10 \
--table_size=100000 \
oltp_read_write \
--db-ps-mode=disable \
run

压测结果

image-1695029984830

[ 1s ] thds: 10 tps: 131.73 qps: 2668.44 (r/w/o: 1868.11/526.90/273.43) lat (ms,95%): 99.33 err/s: 0.00 reconn/s: 0.00
参数 含义
thds: 10 有10个线程在压测
tps: 131.73 每秒执行了131.73个事务
qps: 2668.44 每秒可以执行2668.44个请求
(r/w/o: 1868.11/526.90/273.43) 在每秒2668.44个请求中,有1868.11个请求是读请求,526.90个请求是写请求,273.43个请求是其他的请求,就是对QPS进行了拆解l
at (ms,95%): 99.33 err/s 95%的请求的延迟都在 99.33毫秒以下
0.00 reconn/s: 0.00 每秒有0个请求是失败的,发生了0次网络重连
0

评论区