首页  

linux load 简介     所属分类 linux 浏览量 790
CPU 维护一个运行队列 
调度器 让队列中的进程运行  
load 代表 运行队列长度
cpu资源不够 ,譬如大量的空循环 ,cpu占用很高
进程在等待其他资源如磁盘io、网络io等 ,cpu利用率很低

查看load 的命令
w uptime top
/proc/loadavg 
 
进程状态
D  不中断休眠
R  正在运行
S  休眠
T  被跟踪或被停止
Z  僵死

运行队列长度  处于  D 和 R状态的进程/线程 数

D状态线程 等待资源调度,如磁盘io、网络io或其它资源

D  disksleep


ps -eL -o pid,state,cmd
T      Select all processes associated with this terminal.
r      Restrict the selection to only running processes.
-L     Show threads, possibly with LWP and NLWP columns.
h      隐藏标题信息

ps -r

pid,state,cmd,ucmd
ucmd 线程名
cmd  完整线程名


总线程数
ps -eLf|wc -l
297


sar -q 2  
09时20分04秒   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15   blocked
09时20分06秒         1       295      0.08      0.23      0.14         0
09时20分08秒         1       296      0.08      0.23      0.14         0
09时20分10秒         1       296      0.07      0.22      0.14         0
09时20分12秒         0       296      0.07      0.22      0.14         0

runq-sz    R状态线程数  nr_running
plist-sz   总线程数

R状态 才耗 CPU 
其他状态(包括D状态)并不耗CPU 


快速统计运行队列长度 

vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 5  0      0  65716 120812 883188    0    0    58    52    1    0  1  1 98  1  0
 0  0      0  65220 120812 883204    0    0    16     0  242  531  1  1 98  0  0
 0  0      0  66508 120812 883220    0    0    20     0  277  584  2  0 97  1  0
 
Procs
r: The number of runnable processes (running or waiting for run time).
b: The number of processes in uninterruptible sleep.
       

ps -e -L h o state,ucmd  | awk '{if($1=="R"){print $0}}' | wc -l
ps -e -L h o state,ucmd  | awk '{if($1=="D"){print $0}}' | wc -l
ps -e -L h o state,ucmd  | awk '{if($1=="R"||$1=="D"){print $0}}' | wc -l

ps 可 找出 R 或 D 状态的进程或线程

各种状态统计
ps -e -L h o state |sort |uniq -c
      6 R
    292 S
ps -e  h o state |sort |uniq -c
      4 R
    101 S
    
    

https://github.com/os-health/load2process

https://github.com/os-health/load2process/blob/master/load2process

https://github.com/os-health/load2process/blob/master/load2pid

       

Linux Load 查看及计算

上一篇     下一篇
Linux资源监控命令

Linux查找磁盘IO读写很高的进程

linux pidstat 命令

linux watch 命令

linux sar 使用简介

Linux系统监控工具大全