Man 上的解释:

load average

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.

单从这点上可以看出有些资料说load average可以理解为cpu运行队列中的进程数或者解释为CPU的工作负载量是不靠谱的,只有在早期Unix上定义仅处于Running状态的平均进程数代表load average,这样的话才算是队列中的包含正在被服务和等待被服务的进程数总和(排队论)

我们还是通过下面两点深入和准确的了解下什么是load average

1.为什么只统计进程状态是Running和Uninterruptible 

传统的OS进程有三种状态:Running、ready和block,而在Linux中把进程状态进行了细分扩展,ps man 上描述了如下状态及标记:

D    uninterruptible sleep (usually IO)

R    running or runnable (on run queue)

S    interruptible sleep (waiting for an event to complete)

T    stopped, either by a job control signal or because it is being traced.

W    paging (not valid since the 2.6.xx kernel)

X    dead (should never be seen)

Z    defunct ("zombie") process, terminated but not reaped by its parent.

R状态包括了传统划分的runnig跟ready两种状态,R状态的进程消耗CPU时间片,所以该状态的进程自然是系统的一种负载,那么D状态的Uninterruptible为什么也会被统计进来?

首先到底什么是interruptible和Uninterruptible进程,stackoverflow上有这样的解释:

  • TASK_INTERRUPTIBLE, the interruptible sleep. If a task is marked with this flag, it is sleeping, but can be woken by signals. This means the code which marked the task as sleeping is expecting a possible signal, and after it wakes up will check for it and return from the system call. After the signal is handled, the system call can potentially be automatically restarted (and I won't go into details on how that works).

  • TASK_UNINTERRUPTIBLE, the uninterruptible sleep. If a task is marked with this flag, it is not expecting to be woken up by anything other than whatever it is waiting for, either because it cannot easily be restarted, or because programs are expecting the system call to be atomic. This can also be used for sleeps known to be very short.

这两种状态的进程都是sleep状态的,区别在于可中断也就是S态的进程可以被其他系统信号中断唤醒,而不可中断D状态的进程不能被其他的任何信号中断唤醒除非等到它需要的资源被释放,或者说进程进行了一种被系统认为类似于原子操作的行为。

原子操作不可分割,所以进程处于D状态时不能被其他信号中断。例如进程在申请内存页,或者等待磁盘返回都是属于不可中断的状态。

也就是说D状态的进程通常都是申请使用系统中除CPU以外的资源,所以把D状态算进系统的load中也算是相当的合乎情理。所以说load average是针对CPU的负载情况体现是不正确,它代表的是系统中主要资源的整体负载情况。

2.load average的计算 

怎么来的?

$ cat /proc/loadavg 

0.14 0.05 0.06 1/122 13870

前面三个分别指的1/5/15分钟的load average,第四列数表示总共有多少线程以及当前运行着的线程数,最后一个是在该命令运行时最近或最后的线程ID

那么loadavg里面的数据又是怎么计算出来的呢?

wiki上说不同的系统load average计算有所不同,其中Linux上是这样计算的:

unsigned long avenrun[3]; 
 
static inline void calc_load(unsigned long ticks) 

   unsigned long active_tasks; /* fixed-point */ 
   static int count = LOAD_FREQ; 
 
   count -= ticks; 
   if (count < 0) { 
      count += LOAD_FREQ; 
      active_tasks = count_active_tasks(); 
      CALC_LOAD(avenrun[0], EXP_1, active_tasks); 
      CALC_LOAD(avenrun[1], EXP_5, active_tasks); 
      CALC_LOAD(avenrun[2], EXP_15, active_tasks); 
   } 
}

#define FSHIFT   11 /* nr of bits of precision */ 
#define FIXED_1  (1<<FSHIFT) /* 1.0 as fixed-point */ 
#define LOAD_FREQ (5*HZ) /* 5 sec intervals */ 
#define EXP_1  1884 /* 1/exp(5sec/1min) as fixed-point */ 
#define EXP_5  2014 /* 1/exp(5sec/5min) */ 
#define EXP_15 2037 /* 1/exp(5sec/15min) */ 
 
#define CALC_LOAD(load,exp,n) \ 
   load *= exp; \ 
   load += n*(FIXED_1-exp); \ 
   load >>= FSHIFT;

这一系列的计算代表着在前n分钟处于Running和Uninterruptible进程总数的指数移动平均数。

好像有点难理解,其实主要目的就是解决数值大幅抖动造成的平均数计算误差,得到一个更平滑的接近最多真实情况的平均数值。

我们可以从业务角度这样理解:

For example, one can interpret a load average of "1.73 0.60 7.98" on a single-CPU system as:

  • during the last minute, the system was overloaded by 73% on average (1.73 runnable processes, so that 0.73 processes had to wait for a turn for a single CPU system on average).

  • during the last 5 minutes, the CPU was idling 40% of the time on average.

  • during the last 15 minutes, the system was overloaded 698% on average (7.98 runnable processes, so that 6.98 processes had to wait for a turn for a single CPU system on average).

This means that this system (CPU, disk, memory, etc.) could have handled all of the work scheduled for the last minute if it were 1.73 times as fast.

In a system with four CPUs, a load average of 3.73 would indicate that there were, on average, 3.73 processes ready to run, and each one could be scheduled into a CPU

下面使用高速公路收费排队的模型更能形象的解释load average的数值:

= load of 1.00

  = load of 0.50

 = load of 1.70

Reference :

http://en.wikipedia.org/wiki/Load_(computing)

http://en.wikipedia.org/wiki/Exponential_smoothing

转载于:https://www.cnblogs.com/hundredsofyears/p/3593915.html

Load average in Linux的精确含义相关推荐

  1. linux load average,理解Linux中的Load Average

    在Linux系统中,使用下面的命令: top w uptime (以上三个命令各有区别,top是以固定间隔显示进程的资源占用排名,w显示who and what they are doing,upti ...

  2. 理解Linux系统中的load average(图文版)转载

    理解Linux系统中的load average(图文版) 博客分类: Linux linux load nagios  一.什么是load average? linux系统中的Load对当前CPU工作 ...

  3. 理解Linux系统中的load average

    一.什么是load average? linux系统中的Load对当前CPU工作量的度量 (WikiPedia: the system load is a measure of the amount ...

  4. linux cpu load 值,理解Linux系统中的load average(图文版)转

    一.什么是load average? linux系统中的Load对当前CPU工作量的度量 (WikiPedia: the system load is a measure of the amount ...

  5. Linux系统中的load average

    1. load average 定义 linux系统中的Load对当前CPU工作量的度量.简单的说是进程队列的长度. Load Average 就是一段时间 (1 分钟.5分钟.15分钟) 内平均 L ...

  6. 理解Linux系统中的load average(图文版)

    一.什么是load average? linux系统中的Load对当前CPU工作量的度量 (WikiPedia: the system load is a measure of the amount ...

  7. linux中负载值为多少正常_Linux load average负载量分析与解决思路

    一.load average top命令中load average显示的是最近1分钟.5分钟和15分钟的系统平均负载.系统平均负载表示 系统平均负载被定义为在特定时间间隔内运行队列中(在CPU上运行或 ...

  8. linux主机load average的概念计算过程注意事项

    最近开发的一个模块需要根据机房各节点的负载情况(如网卡IO.load average等指标)做任务调度,刚开始对Linux机器load average这项指标不是很清楚,经过调研,终于搞清楚了其计算方 ...

  9. linux load average,Linux 平均负载 Load Average 详解

    一.什么是Load Average? 系统负载(System Load)是系统CPU繁忙程度的度量,即有多少进程在等待被CPU调度(进程等待队列的长度). 平均负载(Load Average)是一段时 ...

最新文章

  1. 使用接口改变已经装箱的值类型的字段
  2. 『SHELL』--SHELL脚本执行方式(转)
  3. Linux下oracle数据库spfile参数配置文件丢失问题解决,“ORA-32001: write to SPFILE requested but no SPFILE is in use“问题处理
  4. Spring事务传递性探讨
  5. SpringBoot整合mybatis进行快速开发
  6. 工作总结6:token问题
  7. linq查询不包含某个值的记录_MySQL行(记录)的详细操作
  8. 基于SSM实现酒店入住预定管理系统
  9. web漏洞扫描器-appscan
  10. php千月影视,千月影视双端源码完美运营新手搭建教程
  11. Unity设置相机正交相机和透视相机的动态切换
  12. 现代软件工程 第一章 【概论】练习与讨论 王旭阳(2,3,4)
  13. linux新建数字名字用户,linux 用户、用户组不能是全数字
  14. HM中CU,TU的划分
  15. ClusterProfiler在线基因集富集分析,支持自定义基因集、任意物种
  16. 108K加湿器开发方案 单片机 NY8A051F 单片机开发设计开发
  17. R语言数据可视化——图形色彩设计(调色盘)
  18. 计算机绘图二维三维实用教程,计算机绘图二维三维实用教程教学课件作者王建勇第二章.ppt...
  19. 查看硬盘缓存linux,Linux如何查看硬盘型号和缓存
  20. android词典论文,基于Android的电子词典软件的设计与实现(毕业论文doc)资料.doc...

热门文章

  1. 建立一个Web项目及一些错误解决办法
  2. php代码审计之MetInfo5.3盲注
  3. SourceTree 3.0.17如何跳过注册进行安装? — git图形化工具(一)
  4. Swift_类型选择
  5. KindEditor ASP.NET 上传/浏览服务器 附源码
  6. 一起来开发Android的天气软件(三)——使用Volley实现网络通信
  7. Reconstruct binary tree
  8. 算法----- 下一个更大元素 I
  9. Andrid 图片被挤压
  10. android圆角ImageView的几种实现方式