Load Average

  • Meaning:

    • Total number of processes that are being processed or waiting to be processed by the CPU during a period of time. The three numbers represent the statistics of 1, 5 and 15 minutes respectively.
  • What is load average

  • Correction: Load average (e.g. 0.01) is not 1% CPU usage. It’s the average number of runnable and uninterruptible processes on the system, or the average number of active processes, which has nothing to do with CPU usage.

  • Runnable: A process in the R state (Running or Runnable) can use the R state process seen in the ps command

  • Non-interruptible state: processes that are in kernel-state critical processes that are not interruptible, such as the most common one that is waiting for the I/O response from a hardware device, the D state seen in the ps command.

    • For example, if a process is writing data to disk, it cannot be interrupted until the disk replies. This is to ensure consistency between disk data and process data. Therefore, an uninterruptible state is actually a system protection mechanism for processes and hardware devices.

Ideally, the load average is equal to the number of cpus, just enough to maximize the machine’s performance without leaving some processes unexecuted.

Line by line analysis

The first line: top -20:41:08 up 18 days,  5:24.2 users,  load average: 0.04.0.03.0.05Top: indicates the current time. Up: indicates how long the machine has been running. Users: indicates how many current users1Minutes.5Minutes.15Minute loadCopy the code
The second line:Tasks: 216 total,   1 running, 215 sleeping,   0 stopped,   0Zombie Tasks: number of processes running: running processes Sleeping: hibernating processes stopped: stopped processes zombie: zombie processesCopy the code
Line 3: %Cpu(s):0.2 us,  0.1 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

us: Indicates the CPU usage of user processessy: Indicates the CPU usage of system processesni: The user process space changed the priorityid: Indicates the idle CPU usagewa: Percentage of CPU time spent waiting for input and outputhi: Hardware interrupt requestsi: Software interrupt requestst: steal time
Copy the code
  • Wa indicates disk I/O Wait, excluding network I/O Wait.

  • Wa means that I/O operations in DMA mode do not occupy CPU, so CPU I/O wait (WA in the figure above) is actually part of the CPU idle rate.

  • Note that a JAVA thread’s Runnable state corresponds to a thread’s operating system state, which can be Ready, Wait, or running

Lines 4 & 5 KiB Mem:65810456 total, 30324416 free,  9862224 used, 25623816 buff/cache
KiB Swap:  7999484 total,  7999484 free,        0 used. 54807988Avail Mem total: Total memory free: free memory Used: used buffer/cache: write cache/read cacheCopy the code
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND19868 root      20   0 19.733g 369980  15180 S   0.7  0.6 129:53.91 java                                                                                                                                                                     
19682 root      20   0 19.859g 5.766g  22252 S   0.3  9.2 139:42.81 java                                                                                                                                                                     
54625 100       20   0   50868  33512   4104 S   0.3  0.1   0:0468. fluentd                                                                               

PID: the process idUSER: Process ownerPR: Priority. A larger value indicates a higher priorityNI:nice value. A negative value indicates a high priority, and a positive value indicates a low priorityVIRT: Total virtual memory used by a processSWAP: The paged out size of virtual memory used by the processRES: The amount of physical memory used by a process that has not been swapped outSHR: Shared memory sizeSHR: Shared memory size S: process status. D is the uninterruptible state of sleep; R stands for run; S stands for sleep; T stands for trace/stop; Z stands for zombie process. %CPU: percentage of CPU usage since last update. %MEM: percentage of physical memory used by the process; TIME+: indicates the total CPU TIME used by a process, in units1/100Seconds;COMMAND: Command name/command lineCopy the code

Query the thread with the highest CPU

  • Query the toC-c process with the highest CPU usage
  • Find the thread with the highest internal CPU usage toC-hp
    • -p < process number > Specifies the process
    • -h Enables thread viewing
  • If it is a Java program, you need to turn it into a hexadecimal, and then through jStack stack query

reference

  • Juejin. Cn/post / 685669…
  • Juejin. Cn/post / 684490…