[MySQL]-压力测试之性能监测指标
森格 | 2022年12月
本文主要是介绍在数据库的压测过程中,要时刻的一些指标,尤其是当数据库的性能达到瓶颈时,要注意哪个指标已经打满。
一、前文回顾
在前面量两篇文章中,分别介绍了两款压测数据库的工具,Sysbench 与 TPCC-MySQL,大家可以点击链接回顾一下(大概需要10分钟)。在压力测试中,我们不断增加并发数去获取当前数据库配置下的最大性能(QPS、TPS、TPMC等)。
今天呢,我们来注意下在这过程中,是哪些方面的原因导致了性能达到了瓶颈。
二、机器配置
对于压力测试前,我们需要对我们的机器大概的配置有一个了解,在这里个人写了个shell脚本供大家做参考:
#!/bin/sh
#Date:2022年10月21日
#author:liangsen
#
echo -e "\033[41;30;30mI will show computer Infomation there\033[0m"
echo ""
echo -e "\033[44;30;30m====================CPU========================\033[0m"
grep "model name" /proc/cpuinfo
echo ""
echo -e "\033[44;30;30m================Memory Size====================\033[0m"
grep MemTotal /proc/meminfo
echo ""
echo -e "\033[44;30;30m=================32/64Bit=======================\033[0m"
getconf LONG_BIT
echo ""
echo -e "\033[44;30;30m===============Linux version====================\033[0m"
cat /etc/redhat-release
echo ""
echo -e "\033[44;30;30m=================Linux Core=====================\033[0m"
uname -r
echo ""
echo -e "\033[44;30;30m============HardDisk And Partition==============\033[0m"
df -h
echo ""
echo -e "\033[44;30;30m=====================IP==========================\033[0m"
ifconfig
echo "gateWay"
cat /etc/sysconfig/network
echo "DNS"
cat /etc/resolv.conf
echo ""
echo -e "\033[44;30;30m=====================HostName==========================\033[0m"
hostname
echo ""
该脚本分别展示了机器的CPU、内存、位数、Linux版本、Linux内核版本、磁盘和分区情况、IP地址以及主机名称。
 
 
三、性能监测
对于测试的性能,我们可以从几个方面来观察,分别是 CPU、磁盘、内存、网络。
注:在压力测试过程,如果想要测试到最佳的性能,最好压测机和被压测机分开来。
工具
这里使用dstat来对几个指标进行监测。dstat结合了vmstat,iostat,ifstat,netstat以及更多的信息, 实时显示统计情况,输出报告, 在分析和排障时可以通过启用监控项并排序, 模块化设计,使用python编写的,方便扩展现有的工作任务。
安装:
# 使用 yum 安装
hostname>yum install dstat
# 检测是否安装成功
hostname>dstat
查看dstat参数:
Usage: dstat [-afv] [options..] [delay [count]]
Versatile tool for generating system resource statistics
Dstat options:
  -c, --cpu              enable cpu stats
     -C 0,3,total           include cpu0, cpu3 and total
  -d, --disk             enable disk stats
     -D total,hda           include hda and total
  -g, --page             enable page stats
  -i, --int              enable interrupt stats
     -I 5,eth2              include int5 and interrupt used by eth2
  -l, --load             enable load stats
  -m, --mem              enable memory stats
  -n, --net              enable network stats
     -N eth1,total          include eth1 and total
  -p, --proc             enable process stats
  -r, --io               enable io stats (I/O requests completed)
  -s, --swap             enable swap stats
     -S swap1,total         include swap1 and total
  -t, --time             enable time/date output
  -T, --epoch            enable time counter (seconds since epoch)
  -y, --sys              enable system stats
  --aio                  enable aio stats
  --fs, --filesystem     enable fs stats
  --ipc                  enable ipc stats
  --lock                 enable lock stats
  --raw                  enable raw stats
  --socket               enable socket stats
  --tcp                  enable tcp stats
  --udp                  enable udp stats
  --unix                 enable unix stats
  --vm                   enable vm stats
  --plugin-name          enable plugins by plugin name (see manual)
  --list                 list all available plugins
  -a, --all              equals -cdngy (default)
  -f, --full             automatically expand -C, -D, -I, -N and -S lists
  -v, --vmstat           equals -pmgdsc -D total
  --bits                 force bits for values expressed in bytes
  --float                force float values on screen
  --integer              force integer values on screen
  --bw, --blackonwhite   change colors for white background terminal
  --nocolor              disable colors (implies --noupdate)
  --noheaders            disable repetitive headers
  --noupdate             disable intermediate updates
  --output file          write CSV output to file
  --profile              show profiling statistics when exiting dstat
对我们来说,用到 -cdrmngy就足以:
hostname>dstat -cdrmngy

total-cpu-usage:
| usr | sys | idl | wai | hiq | siq | 
|---|---|---|---|---|---|
| 用户时间占比 | 系统时间占比 | 空闲时间占比 | 等待时间占比 | 硬中断 | 软中断 | 
dsk/total:
| read | writ | 
|---|---|
| 磁盘的读总数(KB或者MB) | 磁盘的写总数(KB或者MB) | 
net/total:
| recv | send | 
|---|---|
| 网络设备接收的数据总数(KB或者MB) | 网络设备发送的数据总数(KB或者MB) | 
paging(系统的分页活动):
| in | out | 
|---|---|
| 换入次数 | 换出次数 | 
system(系统统计):
| int | csw | 
|---|---|
| 终端次数 | 上下文切换次数 | 
四、总结
在压测过程中,需要我们时刻监测这些性能指标,并去分析哪个指标是是性能达到瓶颈的关键因素,从而可以更好地去进行性能优化。以上仅为个人总结,如有不对之处欢迎大佬们指导。



















