Chinaunix首页 | 论坛 | 博客
  • 博客访问: 471210
  • 博文数量: 135
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 1441
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-05 20:39
文章分类
文章存档

2012年(2)

2011年(130)

2009年(2)

2008年(1)

我的朋友

分类:

2011-08-23 11:36:24

 

通过『iostat -dx 1』命令监控IO性能

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

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

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

注: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会显示一些很离谱的结果,给出了如下的解释:

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

阅读(2055) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~