One, what is the system average load (load average)?
In the Linux system, uptime, W, top and other commands will have the average load average output of the system, then what is the average system load?
The average system load is defined as the average number of processes running in a queue during a specific time interval。 If a process meets the following criteria, it will be in the run queue:
-It is not in the result of waiting for I/O operation
-It does not actively enter the waiting state (that is, "Wait" is not called)
-Not stopped (for example: waiting to be terminated)
For example:
[Email protected] root]# uptime
7:51pm up 2 days, 5:43, 2 users, load average:8.13, 5.90, 4.94
The final content of the command output represents the average number of processes running in the queue in the past 1, 5, 15 minutes.
In general, as long as the current number of active processes per CPU is not greater than 3 then the performance of the system is good, if the number of tasks per CPU is greater than 5, then the performance of this machine is a serious problem. For the above example, assuming that the system has two CPUs, the current number of tasks per CPU is: 8.13/2=4.065. This indicates that the performance of the system is acceptable.
Second, the Load average algorithm
The above output data is the number of active processes checked every 5 seconds, and then calculated based on this value. If this number is divided by the number of CPUs, the result above 5 indicates that the system is overloaded. The algorithm (extracted from the kernel Code of Linux 2.4) is as follows:
File: include/linux/sched.h:
#define FSHIFT/* NR of bits of precision */
#define FIXED_1 (1< #define LOAD_FREQ (5*hz)/* 5 sec Intervals */
#define EXP_1 1884/* 1/EXP (5sec/1min) as fixed-point, 2048/pow (EXP (1), 5.0/60) */
#define EXP_5 */1/exp (5sec/5min), 2048/pow (EXP (1), 5.0/300) */
#define EXP_15 2037/* 1/EXP (5sec/15min), 2048/pow (EXP (1), 5.0/900) */
#define CALC_LOAD (load,exp,n) \
Load *= exp; \
Load = n (fixed_1-exp); \
Load >>= fshift;
/**********************************************************/
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);
}
}
/**********************************************************/
File: fs/proc/proc_misc.c:
#define LOAD_INT (x) ((x) >> fshift)
#define LOAD_FRAC (x) Load_int (((x) & (Fixed_1-1)) * 100)
static int Loadavg_read_proc (char *page, Char **start, off_t off,
int count, int *eof, void *data)
{
int A, b, C;
int Len;
A = Avenrun[0] (fixed_1/200);
b = avenrun[1] (fixed_1/200);
c = avenrun[2] (fixed_1/200);
len = sprintf (page, "%d.d%d.d%d.d%ld/%d%d",
Load_int (a), Load_frac (a),
Load_int (b), Load_frac (b),
Load_int (c), Load_frac (c),
Nr_running (), nr_threads, last_pid);
return Proc_calc_metrics (page, start, off, Count, EOF, Len);
}
Iii./proc/loadavg The meaning of the data
/proc file system is a virtual file system, does not occupy disk space, it reflects the current operating system in memory operation, view/proc files can be sent to the system running status. View the average system load using the "CAT/PROC/LOADAVG" command, the output is as follows:
0.27 0.36 0.37) 4/83 4828/
The first three numbers are known to be the average number of processes in 1, 5, 15 minutes (some think it is a percentage of the system load, but in fact, you can see 200 or more in some cases). The next two, one molecule is the number of processes running, the denominator is the total number of processes, and the other is the most recently run process ID number.
Iv. common commands for viewing the average system load
1, Cat/proc/loadavg
2, uptime
Name: Uptime
Usage rights: All users
How to use: uptime [-v]
Description: Uptime provides users with the following information, no additional parameters are required:
The current time system is running to the current elapsed time of the number of users of the last minute, five minutes and 15 minutes of system load
Parameter:-V displays version information.
Example: Uptime
The result is:
10:41am up 5 days, ten min, 1 users, Load average:0.00, 0.00, 1.99
3, W
Feature Description: Displays the user information currently logged into the system.
Syntax: w [-fhlsuv][user name]
Additional note: The implementation of this directive will be known to users who are currently logged into the system, as well as the programs they are executing. Execute W separately
The command displays all users, and you can specify the user name to display only information about a user.
Parameters
-F turn on or off to show where users are logged into the system.
-H does not display the header information column for each field.
-L uses a detailed format list, which is a preset value.
-S uses a concise format list, which does not show the CPU time consumed by user login times, terminal stage jobs, and programs.
-U ignores the name of the executing program and the information that the program consumes CPU time.
-V Displays version information.
4. Top
Function Description: Display, manage the program in execution.
Syntax: Top [Bciqss][d < interval seconds >][n < number of executions;]
Additional note: The Execute top command displays the program currently being executed in the system and is managed with a hotkey through the interactive interface it provides.
Parameters
b use Batch mode.
c When listing a program, displays the complete instructions for each program, including information about the instruction name, path, and parameters.
d< interval seconds > set the time interval for top monitor execution, in seconds.
I ignore unused or zombie programs when I execute the top command.
n< Execution Count > set the number of updates to monitor information.
Q Continuously monitors the status of program execution.
s use privacy mode to eliminate potential crises in interactive mode.
S uses the cumulative mode, which works like the "-S" parameter of the PS instruction.
5, Tload
Function Description: Displays the system load status.
Syntax: tload [-v][-d < interval seconds >][-s < scale size >][terminal number]
Supplemental Note: The tload instruction uses ASCII characters to simply display the system load status in text mode. Assuming the terminal number is not given, the load situation is displayed at the terminal where the tload instruction is executed.
Parameters
-d< interval seconds > set the interval between tload to detect the system load, measured in seconds.
-s< scale size > Set the vertical scale size of the chart, measured in columns.
-V Displays version information.
The above knowledge hopes to be able to gain to you.
Linux/proc/loadavg (average load)