Home  >  Article  >  Operation and Maintenance  >  Understanding Linux CPU Load and CPU Usage

Understanding Linux CPU Load and CPU Usage

步履不停
步履不停Original
2019-07-02 16:16:153157browse

Understanding Linux CPU Load and CPU Usage

CPU load and CPU usage

Both of these can reflect the busyness of a machine to a certain extent.

The cpu usage reflects the current busyness of the CPU. The reason for high and low is that the process occupying the CPU processing time may be in the io waiting state but has not yet been released into wait.

The average load (load average) refers to the number of processes occupying CPU time and processes waiting for CPU time within a certain period of time. The processes waiting for CPU time here refer to processes waiting to be awakened, excluding those in the wait state. process.

It can be seen from the above analysis that a machine is likely to be in a situation of low CPU usage and high load. Therefore, the busyness of the machine should be combined with the two. From the actual usage, one of your own On a dual-core Zhiqiang 2.8GHZ, 2G memory machine, when the average load reaches about 50, the CPU usage is close to 100% (the application has a lot of IO operations). In this case, the application is quite smooth, and the actual access delay is not very high. Therefore, when the CPU is still idle, how to improve the IO response is the key to reducing the load. Many people think that the machine will be very busy when the load reaches dozens. I think that if the CPU usage is relatively low at this time, the high load may not This explains the problem very well. Once the processes processed by the CPU are processed, those waiting processes can also get responses immediately. In this case, the io reading and writing speed should be optimized. If the CPU usage is consistently above 90%, even if the average load is only in single digits (for example, a certain process has been computing), the machine is actually already busy~

In fact, in the previous article, there are It is written that the CPU usage is low and the load is high. Reason analysis: The CPU usage is low, but the load is very high. The high load may be an analogy of IO

CPU load

To determine whether the system load is too heavy, you must understand the true meaning of load average. Below, based on the article "Understanding Linux CPU Load", I try to explain this problem in the most popular language.
First, assume the simplest case, your computer has only one CPU, and all operations must be completed by this CPU.
So, we might as well imagine this CPU as a bridge. There is only one lane on the bridge, and all vehicles must pass through this lane. (Obviously, this bridge can only be used for one-way traffic.)
The system load is 0, which means there is not a single car on the bridge.

The system load is 0.5, which means there are cars on half of the bridge.

The system load is 1.0, which means that there are cars on all sections of the bridge, which means that the bridge is "full". However, it must be noted that the bridge was still open to traffic until this point.

The system load is 1.7, which means there are too many vehicles, the bridge is already occupied (100%), and the vehicles waiting to get on the bridge behind are 70% of the vehicles on the bridge. By analogy, a system load of 2.0 means that there are as many vehicles waiting to get on the bridge as there are vehicles on the bridge deck; a system load of 3.0 means that there are twice as many vehicles waiting to get on the bridge as there are vehicles on the bridge deck. In short, when the system load is greater than 1, the following vehicles must wait; the greater the system load, the longer they must wait to cross the bridge.

The system load of the CPU is basically equivalent to the above analogy. The traffic capacity of the bridge is the maximum workload of the CPU; the vehicles on the bridge are processes waiting for processing by the CPU.
If the CPU processes up to 100 processes per minute, then the system load 0.2 means that the CPU only processes 20 processes in this 1 minute; the system load 1.0 means that the CPU processes exactly 100 processes in this 1 minute; The system load is 1.7, which means that in addition to the 100 processes being processed by the CPU, there are 70 processes queued up waiting for the CPU to process.
In order for the computer to run smoothly, the system load should not exceed 1.0, so that no process needs to wait, and all processes can be processed at the first time. Obviously, 1.0 is a critical value. If it exceeds this value, the system is not in optimal condition and you need to intervene.

CPU load - multi-processor

Above, we assume that your computer only has 1 CPU. What will happen if your computer is equipped with 2 CPUs?
2 CPUs means that the computer's processing power has doubled, and the number of processes that can be processed simultaneously has also doubled.
Still using the bridge analogy, two CPUs mean that the bridge has two lanes, doubling the traffic capacity.

So, 2 CPUs indicate that the system load can reach 2.0, at which time each CPU reaches 100% workload. Broadly speaking, for a computer with n CPUs, the maximum acceptable system load is n.0.

CPU load - multi-core processor

Chip manufacturers often include multiple CPU cores inside a CPU, which is called a multi-core CPU.
In terms of system load, multi-core CPUs have similar effects to multi-CPUs. Therefore, when considering system load, you must consider how many CPUs this computer has and how many cores each CPU has. Then, divide the system load by the total number of cores. As long as the load on each core does not exceed 1.0, the computer is running normally.
How do you know how many CPU cores a computer has?
"cat /proc/cpuinfo" command can check CPU information. The "grep -c 'model name' /proc/cpuinfo" command directly returns the total number of cores of the CPU.

Rule of thumb for system load

Is 1.0 the ideal value for system load?
Not necessarily. System administrators often leave a little leeway. When this value reaches 0.7, attention should be paid. The rule of thumb is this:
When the system load is consistently greater than 0.7, you must start investigating where the problem lies and prevent the situation from getting worse.
When the system load continues to be greater than 1.0, you must find a solution to lower this value.
When the system load reaches 5.0, it means that your system has a serious problem, has not responded for a long time, or is close to crashing. You should not let the system reach this value.

For my machine, there are 24 cores. So, how much is the appropriate load?

[root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA]#grep 'model name' /proc/cpuinfo | wc -l24

The answer is:

[root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA]#echo "0.7*24" |bc16.8

##Best observation duration

The last question, "load average" returns a total of three average values--1-minute system load, 5-minute system load, and 15-minute system load--which value should be referenced?

If the system load in only 1 minute is greater than 1.0 and the other two time periods are less than 1.0, this indicates that it is only a temporary phenomenon and the problem is not serious.
If the average system load is greater than 1.0 within 15 minutes (after adjusting the number of CPU cores), it indicates that the problem persists and is not a temporary phenomenon. Therefore, you should mainly observe the "15-minute system load" as an indicator of normal computer operation.

For more Linux articles, please visit the

Linux Tutorial column to learn!

The above is the detailed content of Understanding Linux CPU Load and CPU Usage. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Common shell commandsNext article:Common shell commands