blog icon indicating copy to clipboard operation
blog copied to clipboard

Linux 下的 iostat 与 %iowait、%steal、IOPS

Open penglongli opened this issue 7 years ago • 0 comments
trafficstars

主要介绍下 iostat 的使用,以及其中一个参数 %steal。关于 %steal 的问题,与 top 的 id、wa 参数也有一定联系,下文会指出。

相关工具:sar、vmstat

iostat

iostat 我们通常用来看各物理设备的 I/O 情况,其实还可以查看 CPU、NFS 检查。其中 NFS 检查(-n 参数)不清楚是否已经被废弃,目前已经没有了 -n 参数

参考文档:https://linux.die.net/man/1/iostat

下文直接用具体的实例来演示:

示例 1

命令:iostat -k -x -N 1

参数:

  • -k 以 kilobytes 为单位显示(也可以使用 -m 以 megabytes 为单位显示)
  • -x 显示扩展信息
  • -N 显示 LVM 设备映射的设备信息
  • 1 每隔 1 秒刷新一次

图片

介绍下上图中一些参数的信息:

avg-cpu:

  • %user 显示用户级别执行 iostat 命令时,CPU 利用率百分比
  • %nice 此参数与 nice 优先级命令有关系,笔者不清楚
  • %system 系统级别(kernel)CPU 使用率占比
  • %iowait 此参数通常与 top 的 %wa 参数对应。关于此参数下文会讲解
  • %idle CPU 空闲时间,参数值越小代表目前 CPU 越繁忙

Device:

  • rrqm/s 每秒被合并的读 I/O 请求。当 I/O 操作发生在相邻数据块时,它们可以被合并成一个,以提高效率。

  • wrqm/s 每秒被合并的写 I/O 请求。 与上边的 rrqm/s , 参见:http://linuxperf.com/?p=156

  • %util 表示设备有 I/O 请求(即非空闲)的时间比。此参数并不能作为衡量设备饱和程度指标,只能衡量设备的繁忙程度

    **为什么?**现代的硬盘具有并行处理多个 I/O 请求的能力,如某硬盘处理单个 I/O 需要 0.1s,如果并行处理 10 个 I/O 请求的话,则 0.1s 可以完成,即在过去 1s 时间内的 %util = 10%;如果 10 个 I/O 请求顺序提交,则 %util = 100%。但是设备并没有饱和。可参见上文链接

示例二

命令:iostat 1

root@host-1:~# iostat 1
Linux 4.4.0-91-generic (host-1) 	01/24/2018 	_x86_64_	(2 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.15    0.00    0.04    0.06    0.00   99.75

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               0.26         0.98         3.80     537233    2090884
vdb               0.00         0.01         0.00       3152          0
vdc               0.00         0.00         0.00        340          0

参数:

  • tps(Transactions Per Second) 每秒钟处理的事务数量

%iowait

参考文章:

  • http://linuxperf.com/?p=33
  • https://support.hpe.com/hpsc/doc/public/display?docId=emr_na-c02783994

此项参数并不能作为衡量设备性能的指标

  • 定义:

    Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
    

    此项参数说明,在过去的时间段内(如示例 1,为 1s),有多少时间出现了:CPU(s) 空闲,并且仍然有未完成的 I/O 请求

  • 能说明什么?

    答:说明虽然有未完成的 I/O 请求,但是 CPU 是空闲的仍然可以做更多工作。

%steal

参考文章:

  • https://major.io/2008/11/04/what-is-steal-time-in-my-sysstat-output/
  • http://blog.scoutapp.com/articles/2013/07/25/understanding-cpu-steal-time-when-should-you-be-worried
  • http://blog.csdn.net/jessysong/article/details/73571878

此项参数与虚拟机的性能息息相关,如果数值高则机器的状态非常糟糕

  • 定义:

    Steal time is the percentage of time a virtual CPU waits for a real CPU while the hypervisor is servicing another virtual processor.
    

    %steal 参数表示,宿主机 CPU 目前在服务于其它虚拟机,当前虚拟机等待宿主机 CPU 服务的时间占比。如果数值偏大则表示等待时间越长

  • 原因:一般出现此种情况,表明宿主机的负载过高(此种情况往往见于云服务商的超卖)

  • 解决:

    • 为虚拟机换一台宿主机,或者迁移数据到另一台宿主机下的虚拟机
    • 增加 CPU 的资源配额(Foolish 的做法)
    • 换一家服务商

    第一种解决办法较为明智

IOPS(IO Operations Per Second)

参考文章:

  • http://www.thattommyhall.com/2011/02/18/iops-linux-iostat/

概念

过去 1s 时间的 I/O 操作的数量(读 + 写)

如何计算

https://unix.stackexchange.com/questions/225095/how-to-get-total-read-and-total-write-iops-in-linux

penglongli avatar Jan 10 '18 14:01 penglongli