Linux performance optimization practice - load average

Load Average

When we enter uptimethe command,
insert image description here
there are several parameters here, explained as follows

  • 0:54:current time;
  • up 50 mins: system running time;
  • 2 users: the number of users who are logging in;
  • load averages: 2.12 1.85 1.81: average load;

What does load average mean here? The average load refers to the average number of processes that the system is in a runnable and uninterruptible
state per unit time , that is, the average number of active processes .

Enter the command ps aux, you can see the process PID, CPU usage, and process status and other information,
insert image description here

  • Runnable process: refers to the process that is using the CPU or waiting for the CPU, that is, the process whose STAT is R (Running/Runnable) above;
  • Uninterruptible process: a process that is in a key process in the kernel state, and these processes are uninterruptible. For example, the most common is to wait for the I/O response of the hardware device, that is, the STAT is D (Uninterruptible Sleep, also known as A process in Disk Sleep state;

How reasonable is the average load

Ideally, the average load is equal to the number of CPUs.
First check how many CPUs the system has. The Linux system can obtain the number of CPUs through the top command or the file /proc/cpuinfo.
Enter the following command on this machine to view the basic information:

  • sysctl hw.physicalcpu: View the number of physical CPUs;
  • sysctl hw.logicalcpu: View the number of logical CPUs;
  • system_profiler SPHardwareDataType: View the overview of hardware information;
    insert image description here
    it can be seen that the average load is close to ideal, and the three values ​​are the average values ​​of three different time intervals (1 minute total, 5 minutes, 15 minutes). From the numerical point of view, the system load is relatively stable.

You can also use topthe command to view the value of the average load, as follows,
insert image description here
when the average load is higher than 70% of the number of CPUs, you need to troubleshoot the problem of high load. Once the load is too high, it may cause the process response to slow down, thereby affecting the normal function of the service.

Average load and CPU usage

It includes not only the processes that are using the CPU, but also the processes waiting for the CPU and waiting for I/O.
CPU usage is the statistics of CPU busyness per unit time, which may not exactly correspond to the average load.

  • CPU-intensive processes: using a lot of CPU will lead to an increase in the average load, the two are consistent;
  • I/O-intensive processes: waiting for I/O will also increase the average load, but the CPU usage is not necessarily high;

Guess you like

Origin blog.csdn.net/zkkzpp258/article/details/131606740