教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 教学研究 >

Linux性能监控、调优(CPU篇)(2)

来源:网络收集 时间:2026-04-28
导读: Field Description r The amount of threads in the run queue. These are threads that are runnable, but the CPU is not available to execute them. 当前运行队列中线程的数目.代表线程处于可运行状态,但CPU 还

Field Description

r The amount of threads in the run queue. These are threads that are runnable, but the CPU is not available to execute them.

当前运行队列中线程的数目.代表线程处于可运行状态,但CPU 还未能执行.

b This is the number of processes blocked and waiting on IO requests to finish.

当前进程阻塞并等待IO 请求完成的数目

in This is the number of interrupts being processed.

当前中断被处理的数目

cs This is the number of context switches currently happening on the system.

当前kernel system中,发生上下文切换的数目

us This is the percentage of user CPU utilization.

CPU 利用率的百分比

sys This is the percentage of kernel and interrupts utilization.

内核和中断利用率的百分比

wa This is the percentage of idle processor time due to the fact that ALL runnable threads are blocked waiting on IO.

所有可运行状态线程被阻塞在等待IO 请求的百分比

id This is the percentage of time that the CPU is completely idle.

CPU 空闲时间的百分比

4.2 案例学习:持续的CPU 利用率

在这个例子中,这个系统被充分利用

# vmstat 1

procs memory swap io system cpu

r b swpd free buff cache si so bi bo in cs us sy wa id

3 0 206564 15092 80336 176080 0 0 0 0 718 26 81 19 0 0

2 0 206564 14772 80336 176120 0 0 0 0 758 23 96 4 0 0

1 0 206564 14208 80336 176136 0 0 0 0 820 20 96 4 0 0

1 0 206956 13884 79180 175964 0 412 0 2680 1008 80 93 7 0 0

2 0 207348 14448 78800 175576 0 412 0 412 763 70 84 16 0 0

2 0 207348 15756 78800 175424 0 0 0 0 874 25 89 11 0 0

1 0 207348 16368 78800 175596 0 0 0 0 940 24 86 14 0 0

1 0 207348 16600 78800 175604 0 0 0 0 929 27 95 3 0 2

3 0 207348 16976 78548 175876 0 0 0 2508 969 35 93 7 0 0

4 0 207348 16216 78548 175704 0 0 0 0 874 36 93 6 0 1

4 0 207348 16424 78548 175776 0 0 0 0 850 26 77 23 0 0

2 0 207348 17496 78556 175840 0 0 0 0 736 23 83 17 0 0

0 0 207348 17680 78556 175868 0 0 0 0 861 21 91 8 0 1

根据观察值,我们可以得到以下结论:

1,有大量的中断(in) 和较少的上下文切换(cs).这意味着一个单一的进程在产生对硬件设备的请求. 2,进一步显示某单个应用,user time(us) 经常在85%或者更多.考虑到较少的上下文切换,这个应用应该还在处理器中被处理.

3,运行队列还在可接受的性能范围内,其中有2个地方,是超出了允许限制.

4.3 案例学习:超负荷调度

在这个例子中,内核调度中的上下文切换处于饱和

# vmstat 1

procs memory swap io system cpu

r b swpd free buff cache si so bi bo in cs us sy wa id

2 1 207740 98476 81344 180972 0 0 2496 0 900 2883 4 12 57 27

0 1 207740 96448 83304 180984 0 0 1968 328 810 2559 8 9 83 0

0 1 207740 94404 85348 180984 0 0 2044 0 829 2879 9 6 78 7

0 1 207740 92576 87176 180984 0 0 1828 0 689 2088 3 9 78 10

2 0 207740 91300 88452 180984 0 0 1276 0 565 2182 7 6 83 4

3 1 207740 90124 89628 180984 0 0 1176 0 551 2219 2 7 91 0

4 2 207740 89240 90512 180984 0 0 880 520 443 907 22 10 67 0

5 3 207740 88056 91680 180984 0 0 1168 0 628 1248 12 11 77 0

4 2 207740 86852 92880 180984 0 0 1200 0 654 1505 6 7 87 0

6 1 207740 85736 93996 180984 0 0 1116 0 526 1512 5 10 85 0

0 1 207740 84844 94888 180984 0 0 892 0 438 1556 6 4 90 0

根据观察值,我们可以得到以下结论:

1,上下文切换数目高于中断数目,说明kernel中相当数量的时间都开销在上下文切换线程.

2,大量的上下文切换将导致CPU 利用率分类不均衡.很明显实际上等待io 请求的百分比(wa)非常高,以及user time百分比非常低(us).

3,因为CPU 都阻塞在IO请求上,所以运行队列里也有相当数目的可运行状态线程在等待执行.

4.4 mpstat 工具的使用

如果你的系统运行在多处理器芯片上,你可以使用 mpstat 命令来监控每个独立的芯片.Linux 内核视双核处理器为2 CPU's,因此一个双核处理器的双内核就报告有4 CPU's 可用.

mpstat 命令给出的CPU 利用率统计值大致和 vmstat 一致,但是 mpstat 可以给出基于单个处理器的统计值.

# mpstat –P ALL 1

Linux 2.4.21-20.ELsmp (localhost.localdomain) 05/23/2006

05:17:31 PM CPU %user %nice %system %idle intr/s

05:17:32 PM all 0.00 0.00 3.19 96.53 13.27

05:17:32 PM 0 0.00 0.00 0.00 100.00 0.00

05:17:32 PM 1 1.12 0.00 12.73 86.15 13.27

05:17:32 PM 2 0.00 0.00 0.00 100.00 0.00

05:17:32 PM 3 0.00 0.00 0.00 100.00 0.00

4.5 案例学习: 未充分使用的处理量

在这个例子中,为4 CPU核心可用.其中2个CPU 主要处理进程运行(CPU 0 和1).第3个核心处理所有内核和其他系统功能(CPU 3).第4个核心处于idle(CPU 2).

使用 top 命令可以看到有3个进程差不多完全占用了整个CPU 核心.

# top -d 1

top - 23:08:53 up 8:34, 3 users, load average: 0.91, 0.37, 0.13

Tasks: 190 total, 4 running, 186 sleeping, 0 stopped, 0 zombie

Cpu(s): 75.2% us, 0.2% sy, 0.0% ni, 24.5% id, 0.0% wa, 0.0% hi, 0.0%

si

Mem: 2074736k total, 448684k used, 1626052k free, 73756k buffers

Swap: 4192956k total, 0k used, 4192956k free, 259044k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

15957 nobody 25 0 2776 280 224 R 100 20.5 0:25.48 php

15959 mysql 25 0 2256 280 224 R 100 38.2 0:17.78 mysqld

15960 apache 25 0 2416 280 224 R 100 15.7 0:11.20 httpd

15901 root 16 0 2780 1092 800 R 1 0.1 0:01.59 top

1 root 16 0 1780 660 572 S 0 0.0 0:00.64 init

# mpstat –P ALL 1

Linux 2.4.21-20.ELsmp (localhost.localdomain) 05/23/2006

05:17:31 PM CPU %user %nice %system %idle intr/s

05:17:32 PM all 81.52 0.00 18.48 21.17 130.58

05:17:32 PM 0 83.67 0.00 17.35 0.00 115.31

05:17:32 PM 1 80.61 0.00 19.39 0.00 13.27

05:17:32 PM 2 0.00 0.00 16.33 84.66 2.01

05:17:32 PM 3 79.59 0.00 21.43 0.00 0.00

05:17:32 PM CPU %user %nice %system %idle intr/s

05:17:33 PM all 85.86 0.00 14.14 25.00 116.49

05:17:33 PM 0 88.66 0.00 12.37 0.00 116.49

05:17:33 PM 1 80.41 0.00 19.59 0.00 0.00

05:17:33 PM 2 0.00 0.00 0.00 100.00 0.00

05:17:33 PM 3 83.51 0.00 16.49 0.00 0.00

05:17:33 PM CPU %user %nice %system %idle intr/s

05:17:34 PM a …… 此处隐藏:4135字,全部文档内容请下载后查看。喜欢就下载吧 ……

Linux性能监控、调优(CPU篇)(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/49825.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)