加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – %CPU列和顶部加载

发布时间:2020-12-14 01:03:57 所属栏目:Linux 来源:网络整理
导读:我的一个应用程序显示顶部的CPU%非常高,但负载非常低. myapp总是需要大约30%,显示在“top”命令的最顶层,但是负载总是像0.00,所以我很困惑load和%CPU列之间有什么区别? top - 14:09:54 up 62 days,2:52,1 user,load average: 0.00,0.00,0.00Tasks: 124 t
我的一个应用程序显示顶部的CPU%非常高,但负载非常低.
myapp总是需要大约30%,显示在“top”命令的最顶层,但是负载总是像0.00,所以我很困惑load和%CPU列之间有什么区别?

top - 14:09:54 up 62 days,2:52,1 user,load average: 0.00,0.00,0.00
Tasks: 124 total,1 running,123 sleeping,0 stopped,0 zombie
Cpu0  :  0.0%us,0.0%sy,0.0%ni,99.7%id,0.3%wa,0.0%hi,0.0%si,0.0%st
Cpu1  :  0.0%us,99.3%id,0.3%si,0.0%st
Mem:   2054824k total,1440364k used,614460k free,4644k buffers
Swap:  4194296k total,16604k used,4177692k free,610784k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                         
14774 root      20   0 1201m 9416 1856 S 28.3  0.5 376:13.50 myapp                                                                                        
14746 mysql     20   0 2012m 157m 3888 S  0.3  7.8   5:01.08 mysqld

谁能告诉我理解%CPU和负载之间的差异?

先感谢您!

解决方法

例如top中显示的%CPU是进气的,即当时正在使用的CPU,而正常运行时间显示的负载是平均值:

It conventionally appears in the form of three numbers which represent
the system load during the last one-,five-,and fifteen-minute
periods.

从Wikipedia.

随着时间的推移,这些应该会收敛,但是虽然%CPU是100%最大值,但是当有进程等待时,负载可以高于1.例如:

For example,one can interpret a load average of “1.73 0.50 7.98” on a
single-CPU system as:

during the last minute,the CPU was overloaded by 73% (1 CPU with 1.73 runnable processes,so that 0.73 processes had to wait for a turn)

during the last 5 minutes,the CPU was underloaded 50% (no processes had to wait for a turn)

during the last 15 minutes,the CPU was overloaded 698% (1 CPU with 7.98 runnable processes,so that 6.98 processes had to wait for a
turn)

更新:

我现在才注意到你的进程使用了??28%的CPU,而top报告说两个CPU的空闲率都是> 99%.我无法在我的Linux系统(Ubuntu 12.04,Intel i7-3770K quadcore HT)上重现这一点,请参阅下面的屏幕截图.

正常设置,无负载,显示所有核心的平均CPU使用率:

top - 18:10:04 up  7:50,2 users,0.05,0.15
Tasks: 157 total,156 sleeping,0 zombie
Cpu(s):  0.0%us,99.9%id,0.0%wa,0.0%st
Mem:  16528224k total,1124956k used,15403268k free,148772k buffers
Swap: 15624188k total,0k used,15624188k free,670460k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    7022 root      20   0     0    0    0 S    0  0.0   0:00.14 kworker/0:1        
    1 root      20   0  3640 2060 1324 S    0  0.0   0:01.23 init               
    2 root      20   0     0    0    0 S    0  0.0   0:00.00 kthreadd           
    3 root      20   0     0    0    0 S    0  0.0   0:00.14 ksoftirqd/0        
    6 root      RT   0     0    0    0 S    0  0.0   0:00.00 migration/0

在一个核心上满载(运行yes> / dev / null),显示所有核心的平均CPU使用率:

top - 18:11:58 up  7:52,load average: 0.11,0.07,2 running,155 sleeping,0 zombie
Cpu(s): 12.5%us,87.5%id,1124880k used,15403344k free,148824k buffers
Swap: 15624188k total,670472k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND           
 8254 tim       20   0  4188  280  228 R  100  0.0   0:04.88 yes                
    1 root      20   0  3640 2060 1324 S    0  0.0   0:01.23 init               
    2 root      20   0     0    0    0 S    0  0.0   0:00.00 kthreadd           
    3 root      20   0     0    0    0 S    0  0.0   0:00.15 ksoftirqd/0        
    6 root      RT   0     0    0    0 S    0  0.0   0:00.00 migration/0

与2)相同,但显示每核CPU使用率:

top - 18:13:47 up  7:54,load average: 0.86,0.36,0.24
Tasks: 157 total,100.0%id,0.0%st
Cpu2  :  0.3%us,0.0%st
Cpu3  :  0.0%us,0.0%st
Cpu4  :  0.0%us,0.0%st
Cpu5  :100.0%us,0.0%id,0.0%st
Cpu6  :  0.0%us,0.0%st
Cpu7  :  0.0%us,1124756k used,15403468k free,148840k buffers
Swap: 15624188k total,670472k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND           
 8254 tim       20   0  4188  280  228 R  100  0.0   1:53.98 yes                
    1 root      20   0  3640 2060 1324 S    0  0.0   0:01.23 init               
    2 root      20   0     0    0    0 S    0  0.0   0:00.00 kthreadd           
    3 root      20   0     0    0    0 S    0  0.0   0:00.15 ksoftirqd/0        
    6 root      RT   0     0    0    0 S    0  0.0   0:00.00 migration/0

N.B.:我确实注意到,第一个统计数据顶部显示没有显示是的100%cpu使用情况,类似于你所拥有的.也许那就是问题?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读