温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

通过IOStat命令监控IO性能

发布时间:2020-06-01 15:05:14 来源:网络 阅读:384 作者:sky-鹏 栏目:移动开发

小技巧:你知道iostat是从哪里得到IO相关信息的吗?使用strace命令能跟踪到答案:

shell> strace -eopen iostat
open("/proc/diskstats", O_RDONLY)

注:Strace教程:5 simple ways to troubleshoot using Strace

注:关于diskstats的说明,参见官方文档(主要是其中的field1 ~ field11部分)。

如果你的操作系统里没有iostat命令的话,除了从源代码安装,还可以使用下面方式:

  • Centos/Fedora的安装方式是:yum install sysstat
  • Debian/Ubuntu的安装方式是:aptitude install sysstat

我最常用的iostat命令格式是:『iostat -dx 1』,意思是每隔一秒显示一次IO扩展信息。

shell> iostat -dx 1
Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s
sda               0.18    37.71  0.65  2.63    50.18   322.08
                avgrq-sz avgqu-sz   await  svctm  %util
                  113.46     0.35  107.49   1.67   0.55

Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s
sda               0.00  4208.00  0.00 165.00     0.00 163872.00
                avgrq-sz avgqu-sz   await  svctm  %util
                  993.16   119.54 1144.36   6.07 100.10

注:开头显示的是自系统启动开始的平均值,后面显示的是每段时间间隔里的平均值。

介绍一下相关参数的含义:

  • rrqm/s:队列中每秒钟合并的读请求数量
  • wrqm/s:队列中每秒钟合并的写请求数量
  • r/s:每秒钟完成的读请求数量
  • w/s:每秒钟完成的写请求数量
  • rsec/s:每秒钟读取的扇区数量
  • wsec/s:每秒钟写入的扇区数量
  • avgrq-sz:平均请求扇区的大小
  • avgqu-sz:平均请求队列的长度
  • await:平均每次请求的等待时间
  • svctm:平均每次请求的服务时间
  • util:设备的利用率

注:建议对照源代码来记忆这些参数都是如何计算出来的。

关于这些参数,相对重要的是后面几个,具体来说是:util,svctm,await,avgqu-sz:

util是设备的利用率。如果它接近100%,通常说明设备能力趋于饱和(并不绝对)。有时候会出现大于100%的情况,这是因为读取数据的时候是非原子操作。

svctm是平均每次请求的服务时间。从源代码里可以看出:(r/s+w/s)*(svctm/1000)=util。举例子:如果util达到 100%,那么此时svctm=1000/(r/s+w/s),假设IOPS是1000,那么svctm大概在1毫秒左右,如果长时间大于这个数值,说明 系统出了问题。

await是平均每次请求的等待时间。这个时间包括了队列时间和服务时间,也就是说,一般情况下,await大于svctm,它们的差值越小,则说明队列时间越短,反之差值越大,队列时间越长,说明系统出了问题。

avgqu-sz是平均请求队列的长度。毫无疑问,队列长度越短越好。

说明:svctm参数在未来某个版本的iostat会被删除,官方文档是这样描述原因的:

The average service time (svctm field) value is meaningless, as I/O statistics are calculated at block level, and we don’t know when the disk driver starts to process a request. For this reason, this field will be removed in a future sysstat version.

另外,有时候iostat会显示一些很离谱的结果,官方FAQ给出了如下的解释:

Because of a Linux kernel bug, iostat -x may display huge I/O response times (svctm) and a bandwidth utilization (%util) of 100% for some devices. Indeed these devices have a value for the field #9 (beginning after the device name) in /proc/{partitions,diskstats} which is always different from 0, and even negative sometimes. Yet this field should go to zero, since it gives the number of I/Os currently in progress (it is incremented as requests are submitted, and decremented as they finish). To (temporarily) solve the problem, you should reboot your system to reset the counters in /proc/{partitions,diskstats}.

如果大家想要更系统的了解关于IO的相关知识,可以参考如下资料:

  • Getting the hang of IOPS
  • Basic I/O Monitoring on Linux
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI