When we use the top command to see the system's resource usage, we see load average, as shown in. It represents the average workload of the system at 1, 5, and 15 minutes. So what is load? How does it relate to CPU utilization?
Load average: The system average load is the load of the CPU, which contains information that is not CPU usage, but rather statistics on the sum of the number of processes that the CPU is processing and waiting for the CPU to process over time, that is, the length of the CPU usage queue. The smaller the number, the better.
1. Differences in CPU load and CPU utilization
CPU Utilization : Shows the percentage of CPU that the program consumes in real time during runtime
CPU Load : Displays the average number of tasks that are being used and waiting for the CPU over time. High CPU utilization does not mean that the load is necessarily large. For example: If I have a program that needs to use the CPU's computing function all the time, then CPU usage may reach 100%, but the CPU workload is approaching "1" because the CPU is only responsible for one job! What if two of these programs are executed at the same time? The CPU usage is still 100%, but the workload becomes 2. So that is to say, when the CPU workload is larger, the CPU must be switching between different jobs frequently.
Examples Show
There is an interesting analogy on the internet, and call to explain the difference between the two, I explained in my own understanding.
A public telephone kiosk, there is a person on the phone, four people waiting, each limit the use of the phone for one minute, if someone does not finish the phone within a minute, can only hang up the phone line, waiting for the next round. The phone is the equivalent of the CPU, and the person who is or is waiting for the call is the equivalent of the task.
In the use of telephone booths, it is certain that someone will be out of the phone, some people do not call and choose to re-queue, there will be new people in the line here, the number of changes is equivalent to the number of tasks increase or decrease. To count the average load, we counted the number of people in 5 minutes and averaged the statistics at 1th, 5, and 15 minutes, resulting in an average load of 1th, 5 and 15 minutes.
Some people pick up the phone to play, has been playing 1 minutes, and some people may be in the first 30 seconds to find the phone number, or hesitate to play, after 30 seconds is really on the phone. If you think of the phone as a CPU, the number of people as a task, we say the previous person (Task) CPU utilization is high, the latter one (Task) CPU utilization is low.
Of course, the CPU does not work in the first 30 seconds, after 30 seconds to rest, just said, some programs involve a lot of computation, so CPU utilization is high, and some programs involved in the calculation of the few, CPU utilization is naturally low. However, regardless of the CPU utilization is high is low, with the number of tasks behind the queue does not necessarily have a relationship.
2. What is the ideal load?
This controversial, each has its own argument, the individual is more agree that the CPU load is less than or equal to 0.5 is an ideal state.
No matter how good the performance of a particular CPU is, how many tasks can be handled in 1 seconds, we can think of it as irrelevant, although that is not the case. When we evaluate the CPU load, we only count the task queue length in 5 minutes. If the task queue length is 1 when counted every 5 minutes, then the CPU load is 1. If we only have a single-core CPU, the load is always 1, which means that no task is queued and not bad.
But my server, which is a dual-core CPU, equals 4 cores, with a load of 1 per core, and a total load of 4. This means that if my server's CPU load remains around 4 for a long time, it can be accepted.
But a load of 1 per core is not an ideal state! This means that our CPU is always busy and not idle. The network has said that the ideal state is about 0.7 of the load per core, I agree, 0.7 times the number of cores, the server ideal CPU load, such as I this server, load under 3.0 can be.
3. How can I reduce the CPU load on my server?
The simplest way is to replace the better performance of the server, do not want to just improve the performance of the CPU, it is not used, the CPU to play its best performance also requires the coordination of other hardware and software.
In other aspects of the server configuration, the number of CPUs and CPU cores (that is, the number of cores) will affect the CPU load, because the task is ultimately allocated to the CPU core to be processed. Two CPUs are better than one CPU, and dual cores are better than single cores.
Therefore, we need to keep in mind that the CPU load is calculated based on the number of cores, except for the difference in CPU performance! There is a saying, "How many cores, that is, how much load".
4. How much CPU usage is ideal?
CPU utilization In the past is often used by our layman to determine whether the machine has reached the full load of a standard, I see a long time CPU utilization 60-80% that the machine has a bottleneck.
Reproduced from: http://blog.csdn.net/andylauren/article/details/52561851
Physical number of CPUs, number of cores, number of threads
To view the number of physical CPUs
grep ' physical id '/proc/cpuinfo | Sort-u
- 2
View number of cores
grep ' core ID '/proc/cpuinfo | Sort-u | Wc-l
- 3
To view the number of threads
grep ' Processor '/proc/cpuinfo | Sort-u | Wc
In general, the number of CPUs we said above should refer to the thread count (remember, not all CPUs are dual-threaded)
CPU usage and load, physical CPU count, number of cores, number of threads