展开 磁盘性能指标 指标1: IOPS=r/s+w/s,即每秒读写次数; 指标2: 吞吐量=rkB/s+wkB/s,即每秒读写数据量; 指标3: 使用率,是指磁盘忙处理 I/O 请求的百分比。过高的使用率(比如超过 80%)通常意味着磁盘 I/O 存在性能瓶颈; 指标4: 响应时间,是指从发出 I/O 请求到收到响应的间隔时间; IO问题排查思路 首先,查看系统IO情况,确认IO异常指标;(top/iostat) 其次,查看各进程IO使用情况,确认导致指标异常的进程;(iotop/pidstat) 最后,分析进程的IO行为(文件、磁盘读写),确认问题根源;(strace + ioprofile/lsof)

Step1: 查看系统IO情况   说明:iostat和top命令中的iowait并不能等于IO负载情况,只是反映了CPU等待IO时间占用CPU总时间的百分比;使用iostat命令查看系统IO情况,如下:

[root@master ~]# iostat -xdm 1 Linux 3.10.0-514.16.1.el7.x86_64 (master) 05/05/2019 x86_64 (48 CPU)

Device: rrqm/s wrqm/s r/s w/s rMB/s wMB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda 4.28 3.81 1.93 3.75 0.03 0.04 26.21 0.06 10.25 26.09 2.08 0.45 0.25 sdb 5.70 9.00 13.21 139.56 0.38 1.87 30.23 0.07 0.43 2.80 0.20 0.09 1.41 dm-0 0.00 0.00 0.59 3.02 0.00 0.01 8.00 0.00 0.85 4.06 0.22 0.55 0.20 dm-1 0.00 0.00 12.11 138.73 0.35 1.64 27.02 0.10 0.64 3.96 0.35 0.09 1.32 dm-2 0.00 0.00 12.11 138.73 0.35 1.64 27.02 0.10 0.64 3.96 0.35 0.09 1.34 dm-3 0.00 0.00 6.16 5.20 0.03 0.21 42.40 0.01 0.57 0.51 0.65 0.20 0.22

iostat 选项

-x Display extended statistics.
This option works with post 2.5 kernels since it needs /proc/diskstats file or a mounted sysfs to get the statistics. This option may also work with older kernels (e.g. 2.4) only if extended statistics are available in /proc/partitions (the kernel needs to be patched for that).

-d Display the device utilization report. -m Display statistics in megabytes per second instead of blocks or kilobytes per second.
Data displayed are valid only with kernels 2.4 and later. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 await:IO请求平均响应时间(队列排队时间+IO处理时间),一般系统 I/O 响应时间应该低于 5ms,如果大于 10ms 就比较大了; svctm:IO请求平均处理时间,不包含等待时间; %util:磁盘繁忙程度。 例如,如果统计间隔 1 秒,该设备有 0.8 秒在处理 I/O,而 0.2 秒闲置,那么该设备的 %util = 0.8/1 = 80%; avgqu-sz:IO请求的平均队列长度; r/s + w/s 即为IOPS; r MB/s + w MB/s 即为吞吐量; r_await/w_await:读/写请求处理完成时间,等待时间+处理时间; Step2: 查看进程IO统计   iotop/pidstat命令可以查看系统中每个进程IO使用情况,利用这个信息可以找出占用IO最多的进程;

[root@master ~]# pidstat -d 1 Linux 3.10.0-514.16.1.el7.x86_64 (master) 05/05/2019 x86_64 (48 CPU)

07:21:45 PM UID PID kB_rd/s kB_wr/s kB_ccwr/s Command 07:21:46 PM 0 34197 0.00 4.00 4.00 gunicorn: 07:21:48 PM 0 465 0.00 16.00 16.00 mongod 07:21:51 PM 0 14989 0.00 8.00 0.00 java 1 2 3 4 5 6 7 Step3: 分析进程IO行为  ioprofile可以统计出某个进程对每个文件的读写情况,本质上是 lsof + strace。对于Java应用,还可以使用jstack等命令工具查看线程行为;

#lsof:查看文件打开情况 查看某个进程打开的所有文件: lsof -p <pid> 查看打开某个某个文件的所有进程: lsof <file> 1 2 3 #strace:跟踪系统调用 #timeout:限制命令执行时间 timeout 5 strace -f -F -o <outputfile> -p <pid> 1 2 3 工具介绍及安装 指标 → 工具

工具 → 指标

pidstat   pidstat 是一个常用的进程性能分析工具,用来实时查看进程的 CPU、内存、I/O 以及上下文切换等性能指标;   pidstat命令属于sysstat包,安装命令如下:

//Ubuntu apt install sysstat //CentOs yum install sysstat 1 2 3 4 参考:

https://blueswind8306.iteye.com/blog/2032980 iotop和pidstat使用:http://blog.itpub.net/21980353/viewspace-2113906/ lsof使用:https://www.cnblogs.com/peida/archive/2013/02/26/2932972.html Linux下的IO监控与分析:http://www.cnblogs.com/quixotic/p/3258730.html strace:https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/strace.html ————————————————