Loadaverage is displayed when we use the top command to view system resource usage, as shown in. It indicates the average workload of the system in 1, 5, 15 minutes. So what is the load? What is the relationship between it and cpu utilization?
When we use the top command to view the system resource usage, we will see the load average, as shown in. It indicates the average workload of the system in 1, 5, 15 minutes. So what is the load? What is the relationship between it and cpu utilization?
Load average: the average system Load is the CPU load. The information contained in the system is not the CPU usage, the sum of the number of processes that the CPU is processing and waiting for the CPU to process within a period of time, that is, the length of the CPU queue. The smaller the number, the better.
Differences between Cpu load and cpu utilization
CPU usage: displays the percentage of CPU occupied by the program during running.
CPU load: displays the average number of tasks in use and waiting for CPU usage for a period of time. High CPU utilization does not mean that the load is huge. For example, if I have a program that needs to always use the cpu computing function, the cpu usage may reach 100% at this time, but the cpu workload is close to "1 ", because the cpu is only responsible for one job! What if two such programs are executed at the same time? The cpu usage is still 100%, but the workload is changed to 2. That is to say, when the cpu workload increases, it means that the cpu must switch between different jobs frequently.
L example
There is an article on the Internet that provides an interesting analogy. I will explain the difference between the two by making a phone call.
In a public phone booth, one person is making a call, and four people are waiting. each person is limited to one minute. if someone does not finish the call within one minute, they can only wait for the next round. The number of calls here is equivalent to the CPU, and the number of people waiting for a call is equivalent to the number of tasks.
During the use of phone booths, some people may leave after phone calls. some people choose to re-queue after phone calls are not completed, and some new people will queue up here, this change is equivalent to an increase or decrease in the number of tasks. To measure the average load, we count the number of people every 5 minutes and take the average value for the statistics at 1st, 5, and 15 minutes, thus, the average load is 1st, 5, and 15 minutes.
Some people pick up the phone and call it for one minute. some people may be looking for a phone number thirty seconds ago, or are hesitant to call the phone number. they will only be making a call thirty seconds later. If we regard the phone number as a CPU and the number of people as a task, we can say that the CPU usage of the previous person (task) is high, and the CPU usage of the next person (task) is low.
Of course, the CPU will not work in the first thirty seconds, but will rest in the next thirty seconds. it just means that some programs involve a lot of computing, so the CPU utilization is high, some programs involve a small amount of computing, and the CPU utilization is naturally low. However, no matter whether the CPU utilization is high or low, it is not necessarily related to the number of tasks in the queue.
What is the load?
This controversy has its own arguments. I personally agree that a CPU load smaller than or equal to 0.5 is an ideal situation.
No matter how good the performance of a CPU is and how many tasks can be processed in one second, we can think that it is irrelevant, although this is not the case. When evaluating the CPU load, the length of the task queue is measured in 5 minutes. If the task queue length is 1 every five minutes, the CPU load is 1. If we only have one single-core CPU and the load is always 1, it means that no tasks are waiting in the queue, which is not bad.
However, my server is dual-core and CPU, so there are four kernels. if the load of each kernel is 1, the total load is 4. That is to say, if the CPU load on my server remains around 4 for a long time, it is acceptable.
But the load on each kernel is 1, which is not an ideal state! This means that our CPU has been very busy and should not be idle. On the Internet, it is said that the ideal state is that the load of each kernel is about 0.7. I agree that the ideal CPU load of the server is obtained by multiplying 0.7 by the number of kernels, such as my server, the load is less than 3.0.
How can I reduce the server's CPU load?
The simplest way is to replace a server with better performance. don't just think about improving the CPU performance. it's useless. to make the best performance out of the CPU, you also need the cooperation of other hardware and software.
When other aspects of the server are properly configured, the number of CPUs and the number of CPU cores (that is, the number of cores) will affect the CPU load, because the task is finally allocated to the CPU core for processing. Two CPUs are better than one CPU, and two-core CPUs are better than single-core CPUs.
Therefore, we need to remember that, apart from the differences in CPU performance, the CPU load is calculated based on the number of cores! There is a saying: "How many kernels are there? how much load is there ".
What is the ideal CPU usage?
In the past, CPU utilization was often determined by our layers to determine whether the machine has reached a full-load standard. I saw a long period of CPU usage of 60-80% and thought that the machine had a bottleneck.