• sysbench--生产--01--mysql压测--压测的影响因素


    sysbench–生产–01–mysql压测–压测的影响因素


    1、公共信息

    1.1、mysql环境

    数据库机器数据库架构
    16核64GMGR架构,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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    2、线程数对TPS和QPS的影响

    2.1、目的

    1. 获取压测的最大线程数
    2. 将测试线程数定为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
    
    
    • 1
    • 2

    2.3、压测脚本

    2.3.1、内容

    vi /root/test/mysql_threads_test.sh
    
    • 1

    内容

    #!/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
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.3.2、授权和执行

    cd /root/test/
    # 授权
    chmod +x mysql_threads_test.sh
    
    # 后台执行
    ./mysql_threads_test.sh &
    
    # 查看
    ps -ef | grep oltp_read_write
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    2.4、结论

    在这里插入图片描述

    发现在64线程以后tps和qps达到上限水平,之后更高线程的测试结果浮动不大,但通过观察cpu占用情况,发现并没有满载,可能是达到磁盘IO上限。

    3、长时间高负载数据库的稳定性

    1. 使用1的压测数据
    2. 线程数改为64
    3. 执行时间改为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
    
    
    • 1
    • 2

    3.2、结论

    在这里插入图片描述

    在这里插入图片描述

    长时间高负载,数据库是稳定的

    4、表大小对TPS和QPS的影响

    4.1、目的

    1. 获取压测的最大表大小
    2. 将测试表大小从100W,到2000W进行测试。

    4.2、脚本

    4.2.1、内容

    vi /root/test/table_size_test.sh
    
    • 1

    内容

    #!/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
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90

    4.2.1、授权和执行

    cd /root/test/
    # 授权
    chmod +x table_size_test.sh
    
    # 后台执行
    ./table_size_test.sh 1 20  &
    
    # 查看
    ps -ef | grep oltp_read_write
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    4.3、结论

    在这里插入图片描述

    1. 整体趋势是随表的增大而下降
    2. 在800W是最高性能
    3. 800到1100万之间性能下降的最严重
  • 相关阅读:
    数据链路层概述
    人工智能在网络安全中的重要性
    flex 布局(弹性布局 / 弹性盒子)详细教程
    线性筛求欧拉函数前n个和
    案例丨如何提升可视化分析能力?听听这两家企业怎么说
    设计模式——迭代器模式
    5分钟构建电商API接口服务 | python小知识
    后端程序员生产力工具合集
    实验三.局域网的组建
    绘图和可视化(Python)
  • 原文地址:https://blog.csdn.net/zhou920786312/article/details/125420893