用于检查磁盘 I/O 的系统活动报告器 (sar)
Sar(系统活动报告器)是另一个检查磁盘 I/O 的命令。
在开始使用 sar 之前,如果尚未启用,请使用 svcadm 启用 sar 服务:
# svcadm enable sar # svcs sar STATE STIME FMRI online 4:15:08 svc:/system/sar:default
要使用 sar 检查磁盘 I/O 统计信息,我们可以通过提供 2 秒和 10 次计数的间隔来运行它。
# sar -d 2 10 SunOS onitroad 5.11 11.1 i86pc 12/13/2013 10:11:46 device %busy avque r+w/s blks/s avwait avserv 10:11:48 ata1 0 0.0 0 0 0.0 0.0 iscsi0 0 0.0 0 0 0.0 0.0 mpt0 0 0.0 0 0 0.0 0.0 scsi_vhc 0 0.0 0 0 0.0 0.0 sd0 0 0.0 0 0 0.0 0.0 sd0,a 0 0.0 0 0 0.0 0.0 sd0,b 0 0.0 0 0 0.0 0.0 sd0,h 0 0.0 0 0 0.0 0.0 sd0,i 0 0.0 0 0 0.0 0.0 sd0,q 0 0.0 0 0 0.0 0.0 sd0,r 0 0.0 0 0 0.0 0.0
sar -d 命令报告的数据几乎与 iostat 报告的数据相同,除了每秒读取 + 写入 ( r+w/s ) 和没有。
每秒 (blks/s) 的块数(512 字节)。
其他重要的列参数是平均等待队列长度 (avque)、平均等待队列时间 (avwait)、平均服务时间 (avserv) 和 % busy (%busy)。
现在我们还可以使用 top 命令来获取 % I/O 等待时间。
默认情况下,Solaris 11 安装了顶级软件包。
对于solaris 10,我们必须安装第三方top 软件包。
# top last pid: 7448; load avg: 0.01, 0.13, 0.11; up 0+13:54:41 60 processes: 59 sleeping, 1 on cpu CPU states: 99.5% idle, 0.0% user, 0.5% kernel, 0.0% iowait, 0.0% swap Kernel: 187 ctxsw, 1 trap, 516 intr, 421 syscall, 1 flt Memory: 2048M phys mem, 205M free mem, 1024M total swap, 1024M free swap
检查磁盘故障
磁盘故障也可能是一个主要的,事实上是许多磁盘 I/O 瓶颈问题的唯一原因。
要检查磁盘故障:
# iostat -xne extended device statistics ---- errors -- r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b s/w h/w trn tot device 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 0 0 0 fd0 1.8 0.5 34.7 2.6 0.0 0.0 0.0 19.3 0 2 0 0 0 0 c1t0d0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 0 0 0 c0t0d0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 0 0 0 0 onitroad01:vold(pid555)
检查列 s/w(软错误)、h/w(硬错误)、trn(传输错误)和 tot(总错误)。
各种错误的含义是:
软错误:磁盘扇区CRC校验失败,需要重新读取
硬错误:CRC 校验重读多次失败
传输错误:I/O 总线报告的错误
总错误数:软错误 + 硬错误 + 传输错误
大量这些错误(尤其是越来越多的硬错误)可能表明磁盘已经发生故障或者即将发生故障。
另一个检查磁盘错误的命令是:
# iostat -E sd0 Soft Errors: 0 Hard Errors: 0 Transport Errors: 0 Vendor: VMware, Product: VMware Virtual S Revision: 1.0 Serial No: Size: 10.74GB [10737418240 bytes] Media Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0 Illegal Request: 9 Predictive Failure Analysis: 0 sd1 Soft Errors: 0 Hard Errors: 0 Transport Errors: 0 Vendor: VMware, Product: VMware Virtual S Revision: 1.0 Serial No: Size: 24.70GB [24696061952 bytes] Media Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0 Illegal Request: 6 Predictive Failure Analysis: 0
I/O 性能瓶颈可能是由于磁盘,甚至是 HBA 或者 HBA 驱动程序。
命令 iostat(输入输出统计)帮助我们开始分析磁盘 I/O 瓶颈问题。
标准的 iostat 输出如下所示:
# iostat -xn 1 5 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 293.1 0.0 37510.5 0.0 0.0 31.7 0.0 108.3 1 100 c0t0d0 294.0 0.0 37632.9 0.0 0.0 31.9 0.0 108.6 0 100 c0t0d0 293.0 0.0 37504.4 0.0 0.0 31.9 0.0 1032.0 0 100 c0t0d0 294.0 0.0 37631.3 0.0 0.0 31.8 0.0 108.1 1 100 c0t0d0 294.0 0.0 37628.1 0.0 0.0 31.9 0.0 108.6 1 100 c0t0d0
可以与 iostat 一起使用的各种选项是:
-x --> Extended disk statistics. This prints a line per device and provides the breakdown that includes r/s, w/s, kr/s, kw/s, wait, actv, svc_t, %w, and %b. -t --> Print terminal I/O statistics. -n --> Use logical disk names rather than instance names. -c --> Print the standard system time percentages: us, sy, wt, id. -z --> Don't print lines having all zeros.
iostat 输出中每列值的含义是:
r/s reads per second (r/s 每秒读取数) w/s writes per second (w/s 每秒写入) kr/s kilobytes read per second (kr/s 每秒读取的千字节数) kw/s kilobytes written per second (kw/s 每秒写入的千字节数) wait average number of transactions waiting for service (queue length) (wait 服务的平均事务数(队列长度)) actv average number of transactions actively being (actv 活跃的平均交易数) serviced (removed from the queue but not yet completed) ( 已服务(已从队列中移除但尚未完成)) svc_t average response time of transactions, in milliseconds (svc_t 事务的平均响应时间,单位毫秒) %w percent of time there are transactions waiting for service (queue non-empty) (%w 有事务等待服务的时间百分比(队列非空)) %b percent of time the disk is busy (transactions in progress) (%b 磁盘繁忙时间的百分比(正在进行的事务)) wsvc_t average service time in wait queue, in milliseconds (wsvc_t 等待队列中的平均服务时间,以毫秒为单位) asvc_t average service time of active transactions, in milliseconds (asvc_t 活动事务的平均服务时间,单位毫秒) wt the I/O wait time is no longer calculated as a percentage of CPU time, and this statistic will always return zero. ( I/O 等待时间不再计算为 CPU 时间的百分比, 并且此统计信息将始终返回0。)
iostat 输出中的第一行是自启动以来的摘要。
这一行将使我们大致了解服务器上的平均服务器 I/O。
这对于比较性能瓶颈时的服务器 I/O 性能非常有用。
现在,如果我们看到 asvc_t 列,我们会看到一个恒定的高值。
通常超过 30 到 40 ms 的值被认为是高的。
但是我们可以放心地忽略 asvc_t 列中 200 毫秒的峰值。
此处间隔为 1 秒,计数为 5.