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 average in Linux的精确含义的更多相关文章

  1. Linux系统中的load average

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

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

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

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

    本文转自:http://heipark.iteye.com/blog/1340384 一.什么是load average? linux系统中的Load对当前CPU工作量的度量 (WikiPedia: ...

  4. 理解Linux系统中的load average

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

  5. load average 定义(网易面试)

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

  6. linux 平均负载 load average 的含义

      load average 的含义 平均负载(load average)是指系统的运行队列的平均利用率,也可以认为是可运行进程的平均数. 以路况为例, 单核CPU.单车道 情况如下: 0.00-1. ...

  7. linux 平均负载 load average 的含义【转】

    文章来源: linux 平均负载 load average 的含义 load average 的含义 平均负载(load average)是指系统的运行队列的平均利用率,也可以认为是可运行进程的平均数 ...

  8. [转]理解Linux系统中的load average

    转自:http://heipark.iteye.com/blog/1340384 谢谢,写的非常好的文章. 一.什么是load average linux系统中的Load对当前CPU工作量的度量 (W ...

  9. linux load average

    性能分析_linux服务器CPU_Load Average 理解Linux系统中的load average(图文版) 理解Load Average做好压力测试 top命令的Load average 含 ...

随机推荐

  1. Lesson one of python

    Test1:Use the powershell to output the contents print "Hello World!" print "Hello Aga ...

  2. 关闭ext4文件系统的日志功能

    最近在帮一个研究生弄一个虚拟化环境下的基于Innodb的日志文件的读写优化的实验,实验的具体详细内容就不说了,其中有一个步骤需要将MySQL的日志文件放置在一块单独的硬盘里面,这块硬盘要么是ext2, ...

  3. Myeclipse----Hibernate环境搭建

    使用myEclipse来生成hibernate 持久化类和映射文件 总体步骤:创建数据库----创建web工程----创建数据视图中的数据库-----导入hibernate框架需要的capabilit ...

  4. http基础知识摘录

    HTTP是一个基于请求/响应模式的,无状态的协议 (只有客户端发送请求服务器才会响应,否则服务器不会主动发送信息的,无状态指客户端发过来一个请求服务端给你发回一个响应,接着你再去发送一个请求,服务器根 ...

  5. 杂项-公司:Aspose

    ylbtech-杂项-公司:Aspose Aspose 于2002年3月在澳大利亚悉尼创建,旗下产品覆盖文档.图表.PDF.条码.OCR.CAD.HTML.电子邮件等各个文档管理领域,为全球.NET ...

  6. Windows远程服务器不能复制粘贴

    操作步骤: 在服务器上打开任务管理器,查看进程,有 rdpclip.exe 进程,关闭此进程: 然后 开始->运行->rdpclip.exe 重新运行此程序,恢复正常.

  7. vim的visual可视模式(转载)

    转自:http://www.cnblogs.com/chenyadong/archive/2011/08/30/2159809.html 为了便于选取文本,VIM 引入了可视(Visual)模式.要选 ...

  8. YCOJ黑熊过河

    Description 有一只黑熊想过河,但河很宽,黑熊不会游泳,只能借助河面上的石墩跳过去,他可以一次跳一墩,也可以一次跳两墩,但是每起跳一次都会耗费一定的能量,黑熊最终可能因能量不够而掉入水中,所 ...

  9. 多线程 线程间通信 wait,notify

    1. 方法wait锁释放,notify()锁不释放

  10. Flexbox布局的基本概念

    flex container(flex容器 或 弹性容器) flex容器是flex元素的的父元素. 通过设置display 属性的值为flex 或 inline-flex定义. 注旧版本的属性值: b ...