Average unix load average load calculation method, averageload

Source: Internet
Author: User

Average unix load average load calculation method, averageload

Average load? Indicates the average number of processes in a period of time, that is, the system is busy. The average load and CPU usage are different, which can indicate the system's busy schedule. The calculation and related aspects of the system's average load will be briefly introduced below.
View Method

Use the uptime command in linux, or view/proc/loadavg to view the system load average load. The uptime command displays the average load of the system in the past 1 minute, 5 minutes, and 10 minutes.

[Root @ localhost ~] # Uptime
19:32:09 up 5 days, 5 users, load average: 0.05, 0.04, 0.05
[Root @ localhost ~] # Cat/proc/loadavg
0.04 0.04 0.05 1/394 23203

So what is the working principle of the uptime command to calculate the load average?

Calculation Method

For single cpu and multi-cpu scenarios, the average load of the system is slightly different. A single cpu is the simplest case. For example, in the past average minute, the number of processes that determine the system is running or waiting indicates the average load of the system, but it is slightly different in linux, those processes in the io wait state will also be included for computing. In this way, the CPU utilization may be very different from the average load. When most processes perform IO, even if the average load is large, there will be no high CPU utilization. In addition, some systems process processes and threads differently, some compute for each thread, and some focus only on processes. For threads with hyper-Threading Technology, it may be another way of processing. The average load of multiple CPUs is calculated by dividing the number of CPUs by one CPU.

File: kernel/timer. c:

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);}}

Sched. h In the kernel

/* * These are the constant used to fake the fixed-point load-average * counting. Some notes: *  - 11 bit fractions expand to 22 bits by the multiplies: this gives *    a load-average precision of 10 bits integer + 11 bits fractional *  - if you want to count load-averages more often, you need more *    precision, or rounding will get you. With 2-second counting freq, *    the EXP_n values would be 1981, 2034 and 2043 if still using only *    11 bit fractions. */extern unsigned long avenrun[];         /* Load averages */extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);#define FSHIFT          11              /* 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           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;extern unsigned long total_forks;extern int nr_threads;DECLARE_PER_CPU(unsigned long, process_counts);extern int nr_processes(void);extern unsigned long nr_running(void);extern unsigned long nr_uninterruptible(void);extern unsigned long nr_iowait(void);extern unsigned long nr_iowait_cpu(int cpu);extern unsigned long this_cpu_load(void);
Ewma Algorithm

In linux, this algorithm is used in many aspects. For example, in addition to the CBQ algorithm of the TC system, this algorithm is a statistical algorithm. For details, refer to the algorithm

References

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

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.