UNIX average load Average load calculation method

Source: Internet
Author: User

average load?表示系统在一段时间内的平均进程个数,也就是表示系统的繁忙程度。average load和CPU利用率不一样,更加能够表示系统的繁忙程度,下面将就系统的average load的计算和相关进行简单介绍。
View methods

Use the Uptime command under the Linux system, or view/proc/loadavg to see the system load average load. Using the Uptime command displays the average load of the system in the last 1 minutes, 5 minutes, and 10 minutes respectively.

[Email protected] ~]# uptime
19:32:09 up 5 days, 8:53, 5 users, load average:0.05, 0.04, 0.05
[Email protected] ~]# Cat/proc/loadavg
0.04 0.04 0.05) 1/394 23203

So what does the uptime command do to calculate how load average works?

Calculation method

For single-CPU and multi-CPU scenarios, the system's average load situation is slightly different. Single CPU is the simplest case, for example, in the past average one minute, the number of processes that determine the system is running or waiting state is the average load of the system, but under the Linux system slightly different, those in the IO wait state will be included in the calculation. This causes CPU utilization to be quite different from the average load, and when most processes are doing IO, even if the average load is large, there is no significant CPU utilization. In addition, some systems are very different for processes and threads, some for each thread, some for processes, and for Hyper-threading technology, which may be another way to handle it. The calculation of the average load for multiple CPUs is divided by the number of CPUs in the case of a single CPU.

File: kernel/timer.c:

UnsignedLongavenrun[3];StaticInlinevoidCalc_load (unsignedLongTicks) {unsignedLongActive_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);}}

function Sched.h in the kernel

/ * * These is the constant used to fake the fixed-point load-average * counting.  Some Notes: *-one bit fractions expand to $ bits by the Multiplies:this gives * a load-average precision of ten bits Integer + one bits fractional *-if you want to count load-averages more often, you need more * precision, or Roundin G'll get you.  With 2-second counting Freq, * The Exp_n values would is 1981, 2034 and 2043 if still using only * one bit fractions. */extern unsigned LongAvenrun[];/ * Load averages * /extern voidGet_avenrun (unsigned Long*loads,unsigned LongOffsetintSHIFT);#define FSHIFT/* NR of bits of precision * /#define FIXED_1 (1<<fshift)/* 1.0 as Fixed-point */#define LOAD_FREQ (5*hz+1)/* 5 sec intervals */#define EXP_1 1884/* 1/EXP (5sec/1min) as fixed-point */#define EXP_5 */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;extern unsigned LongTotal_forks;extern intNR_THREADS;DECLARE_PER_CPU (unsigned Long, process_counts);extern intNr_processes (void);extern unsigned LongNr_running (void);extern unsigned LongNr_uninterruptible (void);extern unsigned LongNr_iowait (void);extern unsigned LongNR_IOWAIT_CPU (intCPU);extern unsigned LongThis_cpu_load (void);
EWMA algorithm

Linux system uses this algorithm in many aspects, for example, in addition to the TC system CBQ algorithm, which is a statistical algorithm, please refer to Http://en.wikipedia.org/wiki/EWMA_chart and HTTP. En.wikipedia.org/wiki/moving_average

Reference documents

Http://man.he.net/man8/tc-cbq-details
Linux kernel code
Http://en.wikipedia.org/wiki/EWMA_chart
Http://en.wikipedia.org/wiki/Moving_average

UNIX average load Average load calculation method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.