怎么做赌钱网站,建站系统源码,网站建设目标 优帮云,如何做网站微信支付一、背景
工作中我们经常遇到CPU 负载高#xff0c;CPU负载高意味着什么#xff1f; CPU的负载是怎么计算的#xff1f; top指令中的各个指标代表什么含义#xff1f; 二、CPU 负载计算方法
在系统出现负载问题#xff0c;通常会使用uptime和top确认负载#xff0c;这两…一、背景
工作中我们经常遇到CPU 负载高CPU负载高意味着什么 CPU的负载是怎么计算的 top指令中的各个指标代表什么含义 二、CPU 负载计算方法
在系统出现负载问题通常会使用uptime和top确认负载这两个命令代表的含义是什么
1、首先看uptime
geekCNSZX-4N7FGK3:~$ uptime
22:13:59, up 2 min, 0 users, load average: 0.52, 0.58, 0.59
当前时间, 系统启动的总时间, 当前user数, load average 后的三个数分别是 1分钟5分钟15 分钟的平均负载
man uptime System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time.关于平均负载的解释注意如上面的是进程处于runnable和uninterruptable状态的平均数
当这个值为1时如果我们的系统有4个CPU那么表示系统大概有75%的时间处于空闲idle状态
如果我们只有2个CPU 表示 系统有50%时间处于空闲。
这三个值的差异反应了当前系统的负载变化情况
如果 1 分钟、5 分钟、15 分钟的三个值相差不大说明系统负载很稳定。
如果 1 分钟的值远小于 15 分钟的值就说明系统最近 1 分钟的负载在减少而过去 15 分钟内却有很大的负载。如果 1 分钟的值远大于 15 分钟的值就说明最近 1 分钟的负载在增加若 1 分钟的平均负载超过了 CPU 的个数意味着系统遇到过载的问题需要进行分析优化了。
通常负载数 CPU数70%~80%认为异常
2、top指令 默认每3秒刷新一次 按1 可以显示每个CPU上的详细信息 us, user : normal 进程nice值 0的cpu占用量 sy, system : process 内核态执行时间 ni, nice : normal进程 nice值 0的cpu占用量 id, idle : idle占比CPU空闲时间 wa, IO-wait : 等待I/O的时间 hi : 硬件中断的CPU占用时间 si : 软件中断的CPU占用时间 st : 当系统运行在虚拟机时被其他虚拟机占用的时间 三、查看CPU负载高的原因
1、vmstat 工具 Procs
r: running/runable 的process数量 .
b: blocked process数量uninterrupt状态)
Memory
swpd: swap 内存使用量同/proc/meminfo
free: 可用的free mem 同/proc/meminfo
buff: buff 内存使用数量
cache: cache 内存使用量
Swap
si: swap 从disk换入 单位/s
so: swap从内存换出 单位 /s
IO
bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).
System
in: interrupt 数量单位/s
cs: context switches /s
CPU
us: userspace执行消耗时间占比user time 包括 nice time
sy: 内核执行消耗时间占比
id: idle time 这里计算会包括iowait的时间
wa: iowait time
st: 通过虚拟化运行其他操作系统的时间被其他虚拟机占用的CPU时间
2、pidstat pidstat按进程分布相比前面的vmstat和top还多了一个guest 参数%guest代表运行虚拟机的CPU占用率
pidstat -w 查看context switch的数量context switch就是进程上下文切换 cswch/s每秒自愿上下文切换的次数voluntary context switch
nvcswch/s: 每秒非自愿上下文切换的次数non voluntary context switch
cswch 当进程出发IO读写malloc/mmap触发缺页异常sleep等自愿上下文切换
nvcswch 通常是由于时间片运行完被系统强制调度切换当有大量CPU消耗性进程抢占CPU时这个指标值就会很大 四、总结
CPU占用的指标大概有这些通常我们用top,vmstat,pidstat来确认初步原因