通过IOStat命令监控IO性能

http://huoding.com/2011/07/13/91

网站的很多性能问题最终都会归结到IO头上,所以说理解iostat命令是非常有必要的。

小技巧:你知道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的相关知识,可以参考如下资料:

This entry was posted in Technical and tagged , by 老王. Bookmark the permalink.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值