sysbench–生产–01–mysql压测–压测的影响因素
1、公共信息
1.1、mysql环境
数据库机器 | 数据库架构 |
---|---|
16核64G | MGR架构,3台机器,单主 |
1.2、数据库配置临时修改
# 查看
show global variables like 'max_prepared_stmt_count';
show variables like '%max_connections%'
# 修改
set global max_connections=40960
set global max_prepared_stmt_count=1048576;
2、线程数对TPS和QPS的影响
2.1、目的
- 获取压测的最大线程数
- 将测试线程数定为1,2,4,8,16,32,64,128,256分别测试
2.2、准备压测数据
sysbench oltp_read_write --db-driver=mysql --time=60 --threads=10 --report-interval=3 --mysql-host=10.207.2.99 --mysql-port=3307 --mysql-user=root_admin --mysql-password=cqdbaa3W8GRg1Gdm --mysql-db=bpmapp --tables=10 --table_size=1000000 prepare
2.3、压测脚本
2.3.1、内容
vi /root/test/mysql_threads_test.sh
内容
#!/bin/bash
for i in {1,2,4,8,16,32,64,128,256}
do
sysbench oltp_read_write --db-driver=mysql --time=60 --threads=$i --report-interval=3 --mysql-host=10.207.2.99 --mysql-port=3307 --mysql-user=root_admin --mysql-password=cqdbaa3W8GRg1Gdm --mysql-db=bpmapp --tables=10 --table_size=1000000 run > mysql_threads_$i.log
done
2.3.2、授权和执行
cd /root/test/
# 授权
chmod +x mysql_threads_test.sh
# 后台执行
./mysql_threads_test.sh &
# 查看
ps -ef | grep oltp_read_write
2.4、结论
发现在64线程以后tps和qps达到上限水平,之后更高线程的测试结果浮动不大,但通过观察cpu占用情况,发现并没有满载,可能是达到磁盘IO上限。
3、长时间高负载数据库的稳定性
- 使用1的压测数据
- 线程数改为64
- 执行时间改为300秒
3.1、执行
sysbench oltp_read_write --db-driver=mysql --time=300 --threads=64 --report-interval=5 --mysql-host=10.207.2.99 --mysql-port=3307 --mysql-user=root_admin --mysql-password=cqdbaa3W8GRg1Gdm --mysql-db=bpmapp --tables=10 --table_size=1000000 run > mysql_time.log
3.2、结论
长时间高负载,数据库是稳定的
4、表大小对TPS和QPS的影响
4.1、目的
- 获取压测的最大表大小
- 将测试表大小从100W,到2000W进行测试。
4.2、脚本
4.2.1、内容
vi /root/test/table_size_test.sh
内容
#!/bin/bash
# 压测时间
time=600
# 压测线程
threadnum=64
# mysql host
host=10.207.0.111
# mysql port
port=3307
# mysql user
user=root
# mysql password
password=1234
#数据库名称
db_name=test
# savePath
savePath=/root/test/mysql_table_size
# model
model=oltp_read_write
# model
table_base=1000000
# table_num
table_num=10
# report-interval
report_interval=5
# 单个请求测试
function db_test(){
tableSize=$1
echo "------------------------"$tableSize"数据测试------------------------" > $savePath/$model"_"$tableSize.log
echo "time="$time >> $savePath/$model"_"$tableSize.log
echo "threadnum="$threadnum >> $savePath/$model"_"$tableSize.log
echo "host="$host >> $savePath/$model"_"$tableSize.log
echo "port="$port >> $savePath/$model"_"$tableSize.log
echo "user="$user >> $savePath/$model"_"$tableSize.log
echo "password="$password >> $savePath/$model"_"$tableSize.log
echo "model="$model >> $savePath/$model"_"$tableSize.log
echo "table_base="$table_base >> $savePath/$model"_"$tableSize.log
echo "table_num="$table_num >> $savePath/$model"_"$tableSize.log
echo "report_interval="$report_interval >> $savePath/$model"_"$tableSize.log
# 测试前要清除构建的测试数据
sysbench $model --db-driver=mysql --time=$time --threads=10 --report-interval=$report_interval --mysql-host=$host --mysql-port=$port --mysql-user=$user --mysql-password=$password --mysql-db=$db_name --tables=$table_num --table_size=$tableSize --db-ps-mode=disable cleanup >> $savePath/$model"_"$tableSize.log
# 准备数据
sysbench $model --db-driver=mysql --time=$time --threads=$threadnum --report-interval=$report_interval --mysql-host=$host --mysql-port=$port --mysql-user=$user --mysql-password=$password --mysql-db=$db_name --tables=$table_num --table_size=$tableSize --db-ps-mode=disable prepare >> $savePath/$model"_"$tableSize.log
# 综合读写测试
sysbench $model --db-driver=mysql --time=$time --threads=$threadnum --report-interval=$report_interval --mysql-host=$host --mysql-port=$port --mysql-user=$user --mysql-password=$password --mysql-db=$db_name --tables=$table_num --table_size=$tableSize --db-ps-mode=disable run >> $savePath/$model"_"$tableSize.log
# 测试完要清除构建的测试数据
sysbench $model --db-driver=mysql --time=$time --threads=10 --report-interval=$report_interval --mysql-host=$host --mysql-port=$port --mysql-user=$user --mysql-password=$password --mysql-db=$db_name --tables=$table_num --table_size=$tableSize --db-ps-mode=disable cleanup >> $savePath/$model"_"$tableSize.log
}
# for_begin 要传的参数
for_begin=$1
# for_end 要传的参数
for_end=$2
# 性能测试
function performance_test(){
# 测试
for ((i=$for_begin; i<=$for_end; i++));
do
tableSize=`expr $i \* $table_base`
db_test $tableSize
# 休息1分钟
sleep 1m
done
}
# 执行
performance_test
4.2.1、授权和执行
cd /root/test/
# 授权
chmod +x table_size_test.sh
# 后台执行
./table_size_test.sh 1 20 &
# 查看
ps -ef | grep oltp_read_write
4.3、结论
- 整体趋势是随表的增大而下降
- 在800W是最高性能
- 800到1100万之间性能下降的最严重