iostat
2014-03-14 09:48:25 阿炯

iostat是一个用于收集显示系统存储设备输入和输出状态统计的简单工具,系Sysstat工具包中的重要一员。该工具常常用来追踪存储设备的性能问题,其中存储设备包括设备、本地磁盘,以及诸如使用NFS等的远端磁盘,可用来对Linux硬盘IO性能进行了解。Linux内核在2.4及之前的版本为iostat的数据主要来源对应的文件是/proc/partitions,而Linux 2.6内核对应的文件是/proc/diskstats或/sys/block/[块设备名]/stat。

语法:
iostat [选择参数] [时间] [次数]
iostat [ -c | -d ] [ -k ] [ -t ] [ -V ] [ -x [ device ] ] [ interval [ count ] ]

参数说明:
-C 显示CPU使用情况
-d 显示磁盘使用情况
-k 以 KB(kilobytes) 为单位显示
-m 以 M 为单位显示
-N 显示磁盘阵列(LVM) 信息
-n 显示NFS 使用情况
-p[磁盘] 显示磁盘和分区的情况
-t 显示终端和CPU的信息
-x 显示详细信息
-V 显示版本信息
-v 表示打印出版本信息和用法
-x device指定要统计的设备名称,默认为所有的设备
interval指每次统计间隔的时间
count指按照这个时间间隔统计的次数

注:默认单位为 Blk (块)

iostat (input/output statistics) is a computer system monitor tool used to collect and show operating system storage input and output statistics. It is often used to identify performance issues with storage devices, including local disks, or remote disks accessed over network file systems such as NFS. It can also be used to provide information about terminal (TTY) input and output.

1) Get report and statistic
To run it, just use the command in your console. Here's a sample.

# iostat
Linux 3.10.0-518.el7.x86_64 (freeoa-01)     05/22/2017     _x86_64   (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.69    0.00    0.19    0.02    0.04   99.08

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               1.00         3.40        14.08    1552428    6423128

The first section contains CPU report

%user : percentage of CPU utilization that occurred while executing at the user (application) level
%nice : percentage of CPU utilization that occurred while executing at the user level with nice priority
%system : percentage of CPU utilization that occurred while executing at the system (kernel) level
%iowait : percentage of the time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request
%steal : percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor
%idle : percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request

The second section contains device utilization report

Device : device/partition name as listed in /dev directory
tps : number of transfers per second that were issued to the device. Higher tps means the processor is busier
Blk_read/s : show the amount of data read from the device expressed in a number of blocks (kilobytes, megabytes) per second
Blk_wrtn/s : amount of data written to the device expressed in a number of blocks (kilobytes, megabytes) per second
Blk_read : show the total number of blocks read
Blk_wrtn : show the total number of blocks written

iostat uses the files below to create reports.

/proc/stat contains system statistics.
/proc/uptime contains system uptime.
/proc/diskstats contains disks statistics.
/sys contains statistics for block devices.
/proc/self/mountstats contains statistics for network filesystems.
/dev/disk contains persistent device names.


2) Show more details statistics information
Iostat command gives I/O devices report utilization. It is possible to extend the statistic result for a diagnose in depth with -x option

# iostat -x
Linux 3.10.0-518.el7.x86_64 (freeoa-01)     05/23/2017     _x86_64_    (1 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.69    0.00    0.19    0.02    0.04   99.06

Device: rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
vda     0.01     1.10    0.16    0.84     3.37    14.04    34.88     0.00    2.35    1.41    2.53   0.40   0.04

avg-cpu: it is the cpu block information
Devide: it is device block information. To be sure you are on the good device
%util: how much time did the storage device have outstanding work (was busy).
svctm: indicate how fast does your I/O subsystem respond requests overall when busy. Actually, less you load your system, higher svctm is.
await: indicates how fast do requests go through. It is just an average.
avgqu-sz: how many requests are there in a request queue. Low = either your system is not loaded, or has serialized I/O and cannot utilize underlying storage properly. High = your software stack is scalable enough to load properly underlying I/O.
avgrq-sz: Just an average request size. can indicate what kind of workload happens.
wsec/s & rsec/s: Sectors read and written per second. Divide by 2048, and you’ll get megabytes per second.
r/s & w/s: Read and write requests per second. These numbers are the ones that are the I/O capacity figures, though of course, depending on how much pressure underlying I/O subsystem gets (queue size!), they can vary.
rrqm/s & wrqm/s: How many requests were merged by block layer.

3) Show only the cpu statistic
It is possible to show statistic information and report of our cpu with -c option


4) Display only the device report
It is possible to only show the status of the device utilization with -d option. It will list information for each connected device

5) Show extended I/O statistic for device only
We can display extended statistic on one side and from the other side we can display extended statistics. It means that we can display extended statistics only for devices with -xd option

6) Capture the statistics in kilobytes or megabytes
By default, iostat measure the I/O system with bytes unit. To make it easier to read, we can convert iostat to show us reports in kilobytes or megabytes unit.

Use -k parameter to create reports with kilobytes unit, and -m parameter to create reports with megabytes unit.

7) Display cpu and device statistics with delay
Same with vmstat, as a statistic tool the best way to use it is with delay parameter. With delay, we can see what’s the trend. Here are some samples to run iostat with delay.

Run iostat with kilobytes unit, 2 seconds interval with 3 times reports
# iostat -k 2 3

Show CPU only report with 2 seconds interval and 2 times reports
# iostat -c 2 2

Show sda6 and sda7 device only report with 2 seconds interval and 2 times reports
# iostat -d sda7 sda6 2 2

8) Display persistent device name statistics
It is possible to print the report by device name. Instead of the standard /dev/sda name, it will print the persistent device name with -j parameter and adding ID keyword ( specify the type of the persistent name).

# iostat -j ID mmcbkl0 sda6 -x -m 2 2

9) Display statistics for block devices
It is possible to directly show information for each block device automatically. No need to indicate each device name. It will display statistics for block devices and all their partitions that are used by the system. If a device name is entered on the command line, then statistics for it and all its partitions are displayed. Just use -p option

-j { ID | LABEL | PATH | UUID | ... } [ device [...] | ALL ]
Display persistent device names. Options ID, LABEL, etc. specify the type of the persistent name. These options are not limited, only prerequisite is that directory with required persistent names is present in /dev/disk. Optionally, multiple devices can be specified in the chosen persistent name type. Because persistent device names are usually long, option

# iostat -p sdf 1 2

10) Display lvm2 statistic information
It is possible to view LVM statistic with -N option. The command displays the registered device mapper names for any device mapper devices.

You can tell iostat to omit output for any devices for which there was no activity during the sample period with -z option.(可以通过-z选项告诉iostat忽略任何在采样期间没有活动的设备将信息输出到终端。)

One of the advantages of this tool is you can run them without root privilege.

10) 磁盘监控时常见的指标

IOPS 每秒IO数对磁盘来说,一次磁盘的连续读或写称为一次磁盘 IO,当传输小块不连续数据时,该指标有重要参考意义。

Throughput 吞吐量
硬盘传输数据流的速度,单位一般为 MB/s,在传输大块不连续数据的数据,该指标有重要参考作用。

IO平均大小
实际上就是吞吐量除以 IOPS,用于判断磁盘使用模式,一般大于 32K 为顺序读取为主,否则随机读取为主。

Utilization 磁盘活动时间百分比
磁盘处于活动状态 (数据传输、寻道等) 的时间百分比,也即磁盘利用率,一般该值越高对应的磁盘资源争用越高。

Service Time 服务时间
磁盘读写操作执行的时间,对于机械磁盘包括了寻道、旋转、数据传输等,与磁盘性能相关性较高,另外,也受 CPU、内存影响。

Queue Length 等待队列长度
待处理的 IO 请求的数目,注意,如果该磁盘为磁盘阵列虚拟的逻辑驱动器,需要除以实际磁盘数,以获取单盘的 IO 队列。

Wait Time 等待时间
在队列中排队的时间。


1. 基本使用
iostat -d -k 1 10
参数 -d 表示,显示设备(磁盘)使用状态;-k某些使用block为单位的列强制使用Kilobytes为单位;1 10表示,数据显示每隔1秒刷新一次,共显示10次。

iostat -d -k 1 10
 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
 sda 39.29 21.14 1.44 441339807 29990031
 sda1 0.00 0.00 0.00 1623 523
 sda2 1.32 1.43 4.54 29834273 94827104
 sda3 6.30 0.85 24.95 17816289 520725244
 sda5 0.85 0.46 3.40 9543503 70970116
 sda6 0.00 0.00 0.00 550 236
 sda7 0.00 0.00 0.00 406 0
 sda8 0.00 0.00 0.00 406 0
 sda9 0.00 0.00 0.00 406 0
 sda10 60.68 18.35 71.43 383002263 1490928140

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
 sda 327.55 5159.18 102.04 5056 100
 sda1 0.00 0.00 0.00 0 0

tps:该设备每秒的传输次数(Indicate the number of transfers per second that were issued to the device.)。“一次传输”意思是“一次I/O请求”。多个逻辑请求可能会被合并为“一次I/O请求”。“一次传输”请求的大小是未知的。

kB_read/s:每秒从设备(drive expressed)读取的数据量;kB_wrtn/s:每秒向设备(drive expressed)写入的数据量;kB_read:读取的总数据量;kB_wrtn:写入的总数量数据量;这些单位都为Kilobytes。

上面的例子中,我们可以看到磁盘sda以及它的各个分区的统计数据,当时统计的磁盘总TPS是39.29,下面是各个分区的TPS(因为是瞬间值,所以总TPS并不严格等于各个分区TPS的总和)。

2. -x 参数

使用-x参数我们可以获得更多统计信息。

iostat -d -x -k 1 10
 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util
 sda 1.56 28.31 7.80 31.49 42.51 2.92 21.26 1.46 1.16 0.03 0.79 2.62 10.28
 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util
 sda 2.00 20.00 381.00 7.00 12320.00 216.00 6160.00 108.00 32.31 1.75 4.50 2.17 84.20

rrqm/s:每秒这个设备相关的读取请求有多少被Merge了(当系统调用需要读取数据的时候,VFS将请求发到各个FS,如果FS发现不同的读取请求读取的是相同Block的数据,FS会将这个请求合并Merge);wrqm/s:每秒这个设备相关的写入请求有多少被Merge了。

rsec/s:每秒读取的扇区数;wsec/:每秒写入的扇区数。r/s:The number of read requests that were issued to the device per second;w/s:The number of write requests that were issued to the device per second;

await:每一个IO请求的处理的平均时间(单位是微秒毫秒)。这里可以理解为IO的响应时间,一般地系统IO响应时间应该低于5ms,如果大于10ms就比较大了。

%util:在统计时间内所有处理IO时间,除以总共统计时间。例如,如果统计间隔1秒,该设备有0.8秒在处理IO,而0.2秒闲置,那么该设备的%util = 0.8/1 = 80%,所以该参数暗示了设备的繁忙程度。一般地,如果该参数是100%表示设备已经接近满负荷运行了(当然如果是多磁盘,即使%util是100%,因为磁盘的并发能力,所以磁盘的使用未必就到了瓶颈)。

3. -c 参数

iostat还可以用来获取cpu部分状态值:

iostat -c 1 10
 avg-cpu: %user %nice %sys %iowait %idle
 1.98 0.00 0.35 11.45 86.22
 avg-cpu: %user %nice %sys %iowait %idle
 1.62 0.00 0.25 34.46 63.67

4. 常见用法

iostat -d -k 1 10 #查看TPS和吞吐量信息
iostat -d -x -k 1 10 #查看设备使用率(%util)、响应时间(await)
iostat -c 1 10 #查看cpu状态
iostat 5 2 //每隔5秒刷新显示,且显示2次
iostat -d sda//显示 sda磁盘信息
iostat -t //显示tty和Cpu信息
iostat -m //以M为单位显示所有信息
iostat -n //显示NFS负载情况

5. 实例分析

iostat -d -k 1 |grep sda10
 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
 sda10 60.72 18.95 71.53 395637647 1493241908
 sda10 299.02 4266.67 129.41 4352 132
 sda10 483.84 4589.90 4117.17 4544 4076
 sda10 218.00 3360.00 100.00 3360 100
 sda10 546.00 8784.00 124.00 8784 124
 sda10 827.00 13232.00 136.00 13232 136

上面看到,磁盘每秒传输次数平均约400;每秒磁盘读取约5MB,写入约1MB。

iostat -d -x -k 1
 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util
 sda 1.56 28.31 7.84 31.50 43.65 3.16 21.82 1.58 1.19 0.03 0.80 2.61 10.29
 sda 1.98 24.75 419.80 6.93 13465.35 253.47 6732.67 126.73 32.15 2.00 4.70 2.00 85.25
 sda 3.06 41.84 444.90 54.08 14204.08 2048.98 7102.04 1024.49 32.57 2.10 4.21 1.85 92.24

可以看到磁盘的平均响应时间<5ms,磁盘使用率>80。磁盘响应正常,但是已经很繁忙了。

仅展现CPU的统计
iostat with -c arguments displays only CPU statistics as shown below.

仅展现硬盘I/O的统计
iostat with -d arguments displays only disks I/O statistics of all partitions as shown.
iostat -d

展现指定硬盘的I/O统计,默认为所有硬盘。
iostat -p sda

展现LVM的相关统计
With -N (Uppercase) parameter displays only LVM statistics as shown.


延伸:

# grep sda /proc/diskstats
   8       0 sda 328128 1172916 68134925 6826452 1998304 950394 118088772 72081542 0 17781655 78904079

第1列 : 磁盘主设备号(major)
第2列 : 磁盘次设备号(minor)
第3列 : 磁盘的设备名(name)
第4列 : 读请求总数(rio);成功完成读的总次数:rd_ios
第5列 : 合并的读请求总数(rmerge);合并写完成次数,通过合并提高效率,例如两次4K合并为8K后就只有一次IO操作;合并操作是由IO Scheduler(也叫 Elevator)负责:rd_merges
第6列 : 读扇区总数(rsect);成功读过的扇区总次数:rd_sectors
第7列 : 读数据花费的时间,单位是ms.(从__make_request到end_that_request_last)(ruse);所有读操作所花费的毫秒数,每个读从__make_request()开始计时,到end_that_request_last()为止,包括了在队列中等待的时间:rd_ticks
第8列 : 写请求总数(wio);成功完成写的总次数:wr_ios
第9列 : 合并的写请求总数(wmerge);合并写的次数:wr_merges
第10列 : 写扇区总数(wsect);成功写过的扇区总次数:wr_sectors
第11列 : 写数据花费的时间,单位是ms. (从__make_request到 end_that_request_last)(wuse);所有写操作所花费的毫秒数:wr_ticks
第12列 : 现在正在进行的I/O数(running),等于I/O队列中请求数;现在正在进行的IO数目,在IO请求进入队列时该值加1,在IO结束时该值减1,注意是在进出队列时,而非交给磁盘时:in_flight
第13列 : 系统真正花费在I/O上的时间,除去重复等待时间(aveq);输入/输出操作花费的毫秒数:io_ticks
第14列 : 系统在I/O上花费的时间(use);是一个权重值,当有上面的IO操作时,此值就增加:time_in_queue。

除'正在处理的输入/输出请求数(I/O队列中请求数)'这项是非累积值外,其它统计都是累积值。/proc/diskstats文件比/sys/class/block/sda/stat文件多3个域,从左至右分别对应主设备号,次设备号和设备名称。后续的11个域在这两个文件里是相同的;(/sys/class/block/sda/stat)除了第9个域,所有的域都是从启动时的累积值。

需要注意 io_ticks 与 rd/wr_ticks 的区别,后者是把每一个 IO 所消耗的时间累加在一起,因为硬盘设备通常可以并行处理多个 IO,所以统计值往往会偏大;而前者表示该设备有 IO 请求在处理的时间,也就是非空闲,不考虑 IO 有多少,只考虑现在有没有 IO 操作。在实际计算时,会在字段 in_flight 不为零的时候 io_ticks 保持计时,为 0 时停止计时。另外,io_ticks 在统计时不考虑当前有几个 IO,而 time_in_queue 是用当前的 IO 数量 (in_flight) 乘以时间,统计时间包括了在队列中的时间以及磁盘处理 IO 的时间。

注意:这是在3.10内核(CentOS7)看到的情况,在4.x的内核版本中,/proc/diskstats与/sys/class/block/DNP/stat中的字段多了一些(Debian10(4.19)中这个文件有15列,甚至包括iostat指令的输出也有增加),具体要参考对应的文档;不过多出来的都是加在后续的列,理论上不会对前面的列产生影响。


# iostat -x 1
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
          30.72    0.00    5.00    5.72    0.00   58.56
Device:   rrqm/s   wrqm/s    r/s    w/s     rsec/s   wsec/s   avgrq-sz avgqu-sz   await    svctm    %util
sda         0.79       21.81     9.15   8.08   237.99   239.29    27.69       1.32         76.31    4.07      7.02

rrqm/s:每秒进行 merge 的读操作数目。即 delta(rmerge)/s
wrqm/s:每秒进行 merge 的写操作数目。即 delta(wmerge)/s
r/s:每秒完成的读 I/O 设备次数。即 delta(rio)/s
w/s:每秒完成的写 I/O 设备次数。即 delta(wio)/s
rsec/s:每秒读扇区数。即 delta(rsect)/s
wsec/s:每秒写扇区数。即 delta(wsect)/s
rkB/s:每秒读K字节数。是 rsect/s 的一半,因为每扇区大小为512字节(需要计算)
wkB/s:每秒写K字节数。是 wsect/s 的一半(需要计算)
avgrq-sz:平均每次设备I/O操作的数据大小(扇区)。delta(rsect+wsect)/delta(rio+wio)
avgqu-sz:平均I/O队列长度。即 delta(aveq)/s/1000 (因为aveq的单位为毫秒)
await:平均每次设备I/O操作的等待时间(毫秒)。即 delta(ruse+wuse)/delta(rio+wio)
svctm:平均每次设备I/O操作的服务时间(毫秒)。即 delta(use)/delta(rio+wio)
%util:一秒中有百分之多少的时间用于 I/O 操作,或者说一秒中有多少时间 I/O 队列是非空的。即 delta(use)/s/1000 (因为use的单位为毫秒)

如果 %util 接近100%,说明接收的I/O请求太多,I/O系统已经是满负荷,该硬盘可能存在瓶颈;idle小于70%即表示IO压力就较大了,一般读取速度有较多的wait。

svctm 一般要小于 await (因为同时等待的请求的等待时间被重复计算了),其大小一般和磁盘性能有关,CPU/内存的负荷也会对其有影响,请求过多也会间接导致 svctm 的增加。

await 的大小一般取决于服务时间(svctm)以及 I/O 队列的长度和 I/O 请求的发出模式。如果 svctm 比较接近 await,说明 I/O 几乎没有等待时间;如果 await 远大于 svctm,说明 I/O 队列太长,应用得到的响应时间变慢,如果响应时间超过了用户可以容许的范围,这时可以考虑更换更快的磁盘,调整内核文件系统对IO的调度算法(elevator),优化应用,或者升级 CPU。

队列长度 (avgqu-sz) 也可作为衡量系统 I/O 负荷的指标,但由于 avgqu-sz 是按照单位时间的平均值,因此其不能反映瞬间的 I/O 洪泛。

io/s = r/s + w/s
await = (ruse+wuse)/io (每个请求的等待时间)
await*io/s = 每秒内的I/O请求总共需要等待的ms
avgqu-sz = await*(r/s+w/s)/1000 (队列长度)

同时可以结合 vmstat 查看查看b参数(等待资源的进程数)和wa参数(IO等待所占用的CPU时间的百分比,高过30%时IO压力高);另外 await 的参数也要多和 svctm 来参考,差的过多就一定有 IO 方面的问题。

avgqu-sz 也是个做 IO 调优时需要注意的地方,这个就是直接每次操作的数据的大小,如果次数多,但数据拿的小的话,其实 IO 也会很小。如果数据块拿的大,IO 的数据才会高,也可以通过 avgqu-sz×(r/s or w/s) = rsec/s or wsec/s,也就是说读的速度是这个来决定的。

I/O 系统也和超市排队有很多类似之处:
r/s+w/s:类似于交款人的总数
平均队列长度(avgqu-sz):类似于单位时间里平均排队人的个数
平均服务时间(svctm):类似于收银员的收款速度
平均等待时间(await):类似于平均每人的等待时间
平均I/O数据(avgrq-sz):类似于平均每人所买的东西多少
I/O 操作率(%util):类似于收款台前有人排队的时间比例

设备IO操作:总IO(io)/s = r/s(读) +w/s(写) = 1.46 + 25.28=26.74
平均每次设备I/O操作只需要0.36毫秒完成,现在却需要10.57毫秒完成,因为发出的请求太多(每秒26.74个),假如请求时同时发出的,可以这样计算平均等待时间:
平均等待时间=单个I/O服务器时间*(1+2+...+请求总数-1)/请求总数
每秒发出的I/O请求很多,但是平均队列就4,表示这些请求比较均匀,大部分处理还是比较及时。

从/sys/class/block/DISK/stat中读取的数据其实与/proc/diskstats中除设备号与设备名外的其它数据是一一对应关系,只是统计的方法略有差别而已。
# more /sys/class/block/sda/stat
 328128  1172916 68134925  6826452  1998454   950406 118091292 72085003        0 17782791 78907540


iostat命令除了可以通过该命令查看磁盘信息之外,还可以用来查看 CPU 信息,分别通过 -d 和 -c 参数控制;可直接通过 iostat -xdm 1 命令显示磁盘队列的长度等信息。其中参数如下:

rrqm/s,wrqm/s:读写请求每秒合并后发送给磁盘的请求。

r/s,w/s:应用发送给系统的请求数目。

avgrq-sz:提交给驱动层IO请求的平均大小(sectors),一般不小于4K,不大于max(readahead_kb, max_sectors_kb);可用于判断当前的 IO 模式,越大代表顺序,越小代表随机;计算公式如下:avgrq-sz = (rsec + wsec)/(r + w)

avgqu-sz:Average Queue Size
在驱动层的队列排队的平均长度。

await:Average Wait
平均的等待时间,包括了在队列中的等待时间,以及磁盘的处理时间。

svctm(ms):Service Time
请求发送给IO设备后的响应时间,也就是一次磁盘IO请求的服务时间,不过该指标官网说不准确,可能要取消。对于单块标准SATA盘在完全随机读时,基本在7ms左右,即寻道+旋转延迟时间。

%util:一秒内IO操作所占的比例,计算公式是(r/s+w/s)*(svctm/1000),例如采集时间为 1s 其中有 0.7s 在处理 IO 请求,那么 util 为 70%;对于一块磁盘,如果没有并发IO的概念,那么这个公式是正确的,但是对于RAID磁盘组或者SSD来说,这个计算公式就有问题了,就算这个值超过100%,也不代表存储有瓶颈,易产生误导。

iostat 统计的是通用块层经过合并 (rrqm/s, wrqm/s) 后,直接向设备提交的 IO 数据,可以反映系统整体的 IO 状况,但是距离应用层比较远,由于系统预读、Page Cache、IO调度算法等因素,很难跟代码中的 write()、read() 对应。该命令会读取 /proc/diskstats 文件,各个指标详细的含义可以参考内核文档 iostats.txt,其中各个段的含义如上。

重要指标

简单介绍下常见的指标,包括经常误解的指标。

重点说一下 iostat 中 util 的含义,该参数可以理解为磁盘在处理 IO 请求的总时间,如果是 100% 则表明磁盘一直在处理 IO 请求,这也就意味着 IO 在满负载运行。对于一块磁盘,如果没有并发 IO 的概念,所以这个公式是正确的,但是现在的磁盘或者对于RAID磁盘组以及SSD来说,这个计算公式就有问题了,就算这个值超过100%,也不代表存储有瓶颈,容易产生误导。

await

在 Linux 中,每个 IO 的平均耗时用 await 表示,包括了磁盘处理时间以及队列排队时间,所以该指标不能完全表示设备的性能,包括 IO 调度器等,都会影响该参数值。一般来说,内核中的队列时间几乎可以忽略不计,而 SSD 不同产品从 0.01ms 到 1.00 ms 不等,对于机械磁盘可以参考 io 。

svctm

这个指标在 iostat 以及 sar 上都有注释:Warning! Do not trust this field any more. This field will be removed in a future sysstat version.
该指标包括了队列中排队时间以及磁盘处理时间。

实际上,在 UNIX 中通常通过 avserv 表示硬盘设备的性能,它是指 IO 请求从 SCSI 层发出到 IO 完成之后返回 SCSI 层所消耗的时间,不包括在 SCSI 队列中的等待时间,所以该指标体现了硬盘设备处理 IO 的速度,又被称为 disk service time,如果 avserv 很大,那么肯定是硬件出问题了。

iowait

从 top 中的解释来说,就是 CPU 在 time waiting for I/O completion 中消耗的时间,而实际上,如果需要等待 IO 完成,实际 CPU 不会一直等待该进程,而是切换到另外的进程继续执行。

所以在 Server Fault 中将该指标定义为如下的含义:iowait is time that the processor/processors are waiting (i.e. is in an idle state and does nothing), during which there in fact was outstanding disk I/O requests.

那么对于多核,iowait 是只在一个 CPU 上,还是会消耗在所有 CPU,如果有 4 个 CPUs,那么最大是 20% 还是 100% ?

可以通过 dd if=/dev/sda of=/dev/null bs=1MB 命令简单测试下,一般来说,为了提高 cache 的命中率,会一直使用同一个 CPU ,不过部分系统会将其均分到不同的 CPU 上做均衡。另外也可以通过 taskset 1 dd if=/dev/sda of=/dev/null bs=1MB 命令将其绑定到单个 CPU 上。

按照二进制形式,从最低位到最高位代表物理 CPU 的 #0、#1、#2、…、#n 号核,例如:0x01 代表 CPU 的 0 号核,0x05 代表 CPU 的 0 号和 2 号核。

例如将 1865 绑定到 #0、#1 上面,命令为 taskset -p 0x03 1865;

将进程 9034 绑定到 #1、#2、#5~#11 号核上面,从 1 开始计数,命令为 taskset -cp 1,2,5-11 9034 。

可以看出,如果是 top <1> 显示各个 CPU 的指标,则是 100% 计算,而总的统计值则按照 25% 统计。



参考文档
iostat cmd

iostats.txt
该文章最后由 阿炯 于 2022-11-08 21:10:49 更新,目前是第 2 版。