Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the average load of Linux system

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to understand the average load of the Linux system". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand the average load of the Linux system".

What is the average system load (Load average)?

In Linux systems, uptime, w, top, and other commands all have the output of the system average load load average, so what is the system average load?

The average system load is defined as the average process tree in the running queue during a specific time interval. A process is in the run queue if it meets the following conditions:

-it is not waiting for the result of the Ithumb O operation

-it did not actively enter the waiting state (that is, it did not call 'wait')

-not stopped (for example, waiting for termination)

For example:

The code is as follows:

[root@opendigest root] # uptime

7:51pm up 2 days, 5:43, 2 users, load average: 8.13, 5.90, 4.94

The last content of the command output represents the average number of processes in the run queue in the past 1, 5, and 15 minutes.

Generally speaking, as long as the number of currently active processes per CPU is not more than 3, then the performance of the system is good. If the number of tasks per CPU is greater than 5, it means that there is a serious problem with the performance of this machine. For the above example, assuming that the system has two CPU, the current number of tasks per CPU is: 8.13 prime 2 to 4.065. This means that the performance of the system is acceptable.

2. Algorithm of Load average

The above output data checks the number of active processes every 5 seconds, and then calculates based on this value. If this number is divided by the number of CPU, a result higher than 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:

The code is as follows:

# define FSHIFT 11 / * nr of bits of precision * /

# define FIXED_1 (1 > = FSHIFT

File: kernel/timer.c:

The code is as follows:

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); } } 文件: 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% ld/%d% d\ n"

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 each item of data

/ proc file system is a virtual file system, does not take up disk space, it reflects the current operating system running in memory, view / proc files can be sent to the running status of the system. To view the average system load, use the "cat / proc/loadavg" command, and the output is as follows:

0.27 0.36 0.37 4/83 4828/

As we all know, the first three figures are the average number of processes in 1, 5, and 15 minutes (some people think it is the percentage of system load, but it is not, sometimes you can see 200 or more). For the last two, one numerator is the number of running processes, and the denominator is the total number of processes; the other is the ID number of the recently running process.

Common commands to view the average load of the system

1 、

The code is as follows:

Cat / proc/loadavg

2 、 uptime

Name: uptime

Permissions: all users

Usage: uptime [- V]

Description: uptime provides users with the following information, no other parameters are required:

The number of users connected to the last minute, five minutes and fifteen minutes of system load since the current time system is up and running.

Parameter:-V displays version information.

Example: uptime

The result is:

The code is as follows:

10:41am up 5 days, 10 min, 1 users, load average: 0.00, 0.00, 1.99

3 、 w

Function description: displays the user information currently logged in to the system.

Grammar: W [- fhlsuV] [user name]

Add: by executing this instruction, you can know who are currently logged in to the system and the programs they are executing. Execute w separately

The directive displays all users, or you can specify a user name to display only information about a user.

Parameters:

-f turns on or off showing where the user logs in to the system.

-h does not display the title information column of each field.

-l uses a detailed format list, which is the default value.

-s uses a concise format list and does not show the login time of the user, the CPU time spent by the terminal phase jobs and programs.

-u ignores the name of the executing program and the information that the program takes CPU time.

-V displays version information.

4 、 top

Function description: display and manage the programs in execution.

Grammar: top [bciqsS] [d] [n]

Additional note: the execution of the top instruction displays the programs currently being executed in the system and is managed by hotkeys through the interactive interface it provides.

Parameters:

B uses batch mode.

C when listing programs, display the complete instructions of each program, including instruction name, path and parameters and other related information.

D sets the interval between the execution of the top monitor program, in seconds.

I ignore programs that are idle or have become Zombie when executing the top instruction.

N sets the number of updates to the monitoring information.

Q continuously monitor the execution of the program.

S uses the secret mode to eliminate the potential crisis in the interactive mode.

S uses cumulative mode, which is similar to the "- S" parameter of the ps instruction.

5 、 tload

Function description: displays the system load status.

Syntax: tload [- V] [- d] [- s] [terminal number]

Note: the tload instruction uses ASCII characters to simply display the system load status in text mode. Assuming that the terminal number is not given, the load situation is displayed on the terminal that executes the tload instruction.

Parameters:

-d sets the interval time, in seconds, for tload to detect system load.

-s sets the vertical scale size of the chart, calculated in columns.

-V displays version information.

IV. System average load-Advanced explanation

In order to better understand the system load, we use traffic flow as an analogy.

1. Single-core CPU-single lane-the number is normal between 0.00 and 1.00

The road manager will tell the driver that if the front is congested, the driver will have to wait, and if the road ahead is smooth, then the driver can drive directly past.

Specifically:

The number between 0.00 and 1.00 indicates that the road is in very good condition at this time, there is no congestion, and vehicles can pass through without hindrance.

1.00 indicates that the road is normal, but it is likely to worsen and cause congestion. At this time, the system has no extra resources, and the administrator needs to optimize it.

1.00 shows that the road is not very good. If it reaches 2.00, it means that twice the number of vehicles on the bridge is waiting. You have to check this situation.

2. Multicore CPU-Multi-lane-Digital / CPU cores are normal between 0.00 and 1.00.

In the case of multi-core CPU, the number of full-load state is "1.00 * CPU core", that is, the dual-core CPU is 2.00 and the quad-core CPU is 4.00.

3. Secure average system load

The author believes that a single core load below 0.7 is safe, and if it exceeds 0.7, it needs to be optimized.

Which number should I look at, 1 minute, 5 minutes or 15 minutes?

The author thinks that it is better to look at 5 minutes and 15 minutes, that is, the last two numbers.

5. How do I know how many cores my CPU is?

The number of CPU cores can be obtained directly using the following command

The code is as follows:

Grep 'model name' / proc/cpuinfo | wc-l

Thank you for your reading, the above is the content of "how to understand the average load of Linux system". After the study of this article, I believe you have a deeper understanding of how to understand the average load of Linux system. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report