总结
豆包 AI 助手文章总结
首页 > 系统教程 > LINUX > 正文

如何寻找IO杀手进程

聖光之護
发布: 2024-12-08 19:24:35
转载
387人浏览过

linux下可以通过iostat查看目前主机总的io使用情况,不过当通过top等命令查看时,发现cpu wait占多过多,想定位具体是哪些程序占用了io,本篇就通过一些常用的手段进行汇总下。

一、top下的wait状状

wa = I/O waiting ,wa指的是CPU等待磁盘写入完成的时间,就是说前提是要进行IO操作,在进行IO操作的时候,CPU等待时间。如一个程序执行的最后,从系统空间到dst硬盘空间的时候,如果程序是阻塞的,那么这个时候cpu就要等待数据写入磁盘才能完成写操作了。所以这个时候cpu等待的时间就是wa。

所以wa状态占比越高,证明IO越繁忙。

我们可以通过以下指令查看当前io的总终态:

[root@361way ~]# sar -u 2 5
Linux 2.6.32-431.29.2.el6.x86_64 (361way) 01/25/2015 _x86_64_ (1 CPU)
06:59:58 PM CPU %user %nice %system %iowait %steal %idle
07:00:00 PM all 1.00 0.00 0.50 0.00 0.00 98.50
07:00:02 PM all 5.05 0.00 1.52 1.01 0.00 92.42
07:00:04 PM all 0.50 0.00 0.50 0.00 0.00 98.99
07:00:06 PM all 0.00 0.00 0.00 0.00 0.00 100.00
07:00:08 PM all 0.50 0.00 0.00 0.50 0.00 98.99
Average: all 1.41 0.00 0.50 0.30 0.00 97.79
[root@361way ~]# vmstat 2 5
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 98488 209916 218256 0 0 8 28 11 10 5 0 95 0 0
0 0 0 98480 209916 218256 0 0 0 0 155 198 0 0 100 0 0
0 0 0 98496 209916 218256 0 0 0 0 141 191 1 0 99 0 0
0 0 0 98496 209916 218256 0 0 0 0 142 189 0 1 99 0 0
0 0 0 98512 209916 218256 0 0 0 0 152 189 0 0 100 0 0
[root@361way ~]# iostat -x 1 2
Linux 2.6.32-431.29.2.el6.x86_64 (361way) 01/25/2015 _x86_64_ (1 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
4.71 0.00 0.42 0.24 0.00 94.63
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvda 0.00 0.13 0.31 0.91 14.08 8.30 18.39 0.01 11.84 1.38 0.17
xvdb 0.00 2.12 0.05 3.90 1.52 48.10 12.57 0.05 11.84 0.57 0.22
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.00 0.00 100.00
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
登录后复制
二、找出IO繁忙的进程

可以通过linux下最常用的两个命令top、ps找出目前正在占用IO的进程。在进行下一步之前我了解一下D状态,ps命令中查看的状态有D、R、S、Z、T ,D状态指不可中断睡眠 (通常是在IO操作) 收到信号不唤醒和不可运行, 进程必须等待直到有中断发生。

找出当前进程为D的状态:

while true; do date; ps auxf | awk '{if($8=="D") print $0;}'; sleep 1; don
登录后复制

上面的这个操作有一个缺点,就是一旦匹配到一个进程为D的,就开始重新执行下一个循环。而想查看所有当于D状态的进程,可以将其改为如下:

watch -d -n 1 "(ps aux | awk '\$8 ~ /D/ { print \$0 }')"

如下,是我在执行一个大文件的cp时,通过上面的指令查看到的结果:

如何寻找IO杀手进程

除此之外,还可以通过专用工具去查看,如iotop或latencytop。这里以iotop为例,执行后会显示当前的读写速度及每个进程占用的速度。执行后可以按o仅显示占用IO的进程:

[root@361way ~]# iotop --help
Usage: /usr/sbin/iotop [OPTIONS]
DISK READ and DISK WRITE are the block I/O bandwidth used during the sampling
period. SWAPIN and IO are the percentages of time the thread spent respectively
while swapping in and waiting on I/O more generally. PRIO is the I/O priority at
which the thread is running (set using the ionice command).
Controls: left and right arrows to change the sorting column, r to invert the
sorting order, o to toggle the --only option, p to toggle the --processes
option, a to toggle the --accumulated option, q to quit, any other key to force
a refresh.
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-o, --only only show processes or threads actually doing I/O
-b, --batch non-interactive mode
-n NUM, --iter=NUM number of iterations before ending [infinite]
-d SEC, --delay=SEC delay between iterations [1 second]
-p PID, --pid=PID processes/threads to monitor [all]
-u USER, --user=USER users to monitor [all]
-P, --processes only show processes, not all threads
-a, --accumulated show accumulated I/O instead of bandwidth
-k, --kilobytes use kilobytes instead of a human friendly unit
-t, --time add a timestamp on each line (implies --batch)
-q, --quiet suppress some lines of header (implies --batch)
登录后复制

以上就是如何寻找IO杀手进程的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:Linux就该这么学网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
豆包 AI 助手文章总结
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号