Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

PostgreSQL DBA (88)-Linux (CPU usage vs average load)

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

In fact, Linux has become the first choice of enterprise server OS, and there are not a few "installed capacity" of PostgreSQL on Linux. When optimizing and adjusting the performance of the database, we must also take into account the optimization and adjustment of Linux.

This section briefly introduces two confusing concepts in Linux performance monitoring: CPU usage and average load.

The most common performance monitor in daily use is top. Let's take a look at the output of top:

Top-14:20:02 up 2:19, 3 users, load average: 0.00,0.01, 0.07Tasks: 126 total, 1 running, 125 sleeping, 0 stopped, 0 zombie%Cpu (s): 0.2 us, 0.7 sy, 0.0 ni, 99.2 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 stKiB Mem: 3873760 total, 288164 free, 87888 used, 3497708 buff/cacheKiB Swap: 1048572 total, 970292 free 78280 used. 2952064 avail Mem PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND 1 root 20 0 193748 3452 2240 S 0.7 0.1 0 systemd 917 dbus 20 0 32780 1028 704 S 0.7 0.0 root 00.30 dbus-daemon 17 root rt 00 00 S 0.3 0.0 0:09.25 migration/2 559 root 20 00 00 S 0.3 0.0 0:17.53 kworker/2:2 912 root 20 0 24204 1020 864 S 0.3 0.0 0:00.36 systemd-logind 915 root 20 0 216908 476 440 S 0. 3 0.0 0:00.04 abrt-watch-log....

The first line of the output

Top-14:20:02 up 2:19, 3 users, load average: 0.00,0.01,0.07

Load average: 0.00,0.01,0.07 is the load average (average load) of the past 1 minute / 5 minutes / 15 minutes.

What does this average load mean? According to Brendan Gregg, the average load refers to the average number of processes in the runnable and uninterruptible state of the system, that is, the average number of active processes, which is not directly related to the use of CPU. Runnable state processes include processes that are using CPU or are waiting for CPU. Uninterruptible state refers to processes in kernel state uninterruptible critical processes, such as hardware device's I / O response, etc. The D state process viewed by top or ps command is such a state.

Line 3 of the output

% Cpu (s): 0.2 us, 0.7 sy, 0.0 ni, 99.2 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st

This is CPU utilization, where us is the percentage of user mode usage, sy is the percentage of system state, ni is the percentage of user state assigned by nice weighted processes, id is idle, wa is waiting to use CPU, hi is the percentage of hard interrupts, si is the percentage of soft interrupts, and st (steal) is the proportion of virtual machines used, which should add up to 100%.

In order to better understand the average load and CPU utilization, take a highway toll station as an analogy and assume that a highway toll station has eight toll gates.

1. If no car passes through, then the load of the toll station is 0

two。 If only 4 cars pay through at the same time, then the load is 4.

3. If there are eight cars at the same time, the load is 8.

4. If there are eight cars paying, and one car is waiting at each toll gate, the load is 16, and the toll station is actually overloaded.

5. If there are 8 cars paying, and there are 8 (n > 3) cars waiting at each toll gate, then the load will be Numb8. At this time, the toll station will be seriously overloaded and there will be serious congestion.

This is the average load, let's talk about CPU utilization.

1. If toll gates and car owners all use ETC to pay, then the utilization rate is very high.

two。 If some toll gates use manual toll collection, but support Wechat or Alipay, the car owner only needs to swipe his card and go, and the time to prepare to pay is not long, so the utilization rate is not low.

3. If some toll gates charge manually but can only be charged in cash, the proportion of useless work such as money / change is higher and the utilization rate becomes lower.

Through this analogy, we can see that there is no inevitable relationship between average load and utilization, high load does not necessarily have a high CPU utilization rate, and high CPU utilization rate does not necessarily lead to high load.

The following is the output of using top under pressure on PG using benchmarksql:

Top-14:51:33 up 2:50, 3 users, load average: 22.34,9.89, 3.81Tasks: 153 total, 7 running, 146sleeping, 0 stopped, 0 zombie%Cpu (s): 7.9 us, 5.2 sy, 0.0 ni, 23.3id, 47.6 wa, 0.0 hi, 16.0 si, 0.0 stKiB Mem: 3873760 total, 139744 free, 418508 used, 3315508 buff/cacheKiB Swap: 1048572 total, 969552 free 79020 used. 2620448 avail Mem... top-14:49:49 up 2:49, 3 users, load average: 14.47,4.19, 1.48Tasks: 153,151,151,0 stopped, 0 zombie%Cpu0: 20.2 us, 23.0 sy, 2620448 ni, 28.7 id, 19.9 wa, 0.0 hi, 8.2 si, 0.0 st%Cpu1: 13.5 us, 29.2 sy, 0.0 ni, 19.6 id, 28.5 wa 0.0 hi, 9.3 si, 0.0 st%Cpu2: 12.9 us, 19.3 sy, 0.0 ni, 16.4 id, 11.1 wa, 0.0 hi, 40.4 si, 0.0 st%Cpu3: 15.1 us, 25.8 sy, 0.0 ni, 19.7 id, 29.4 wa, 0.0 hi, 10.0 si, 0.0 stKiB Mem: 3873760 total, 133432 free, 435336 used 3304992 buff/cacheKiB Swap: 1048572 total, 970816 free, 77756 used. 2601620 avail Mem PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND 10337 benchma+ 20 4612656 222272 5376 S 42.7 5.7 0 benchma+ 40.99 java 10448 benchma+ 20 0789004 52556 20408 S 14.0 1.4 0 java 00.93 postgres 10356 benchma+ 20 0757376 179348 176640 D 9.7 4.6 0 v 04.15 postgres 10365 benchma+ 20 0 757384 194680 191904 D 9.3 5.0 0:05.12 postgres 10375 benchma+ 20 0 757452 183908 181172 D 9.3 4.7 0:04.51 postgres 10358 benchma+ 20 0 757340 190880 188144 D 8.7 4.90: 04.90 postgres 10357 benchma+ 20 0 757448 169860 167092 D 8.3 4.4 0:04.14 postgres 10352 benchma+ 20 0 757388 185012 182236 S 8.0 4.8 0:04.63 postgres 10354 benchma+ 20 0 757376 177416 174676 D 7.7 4.6 0:04.23 postgres 10367 benchma+ 20 0 757356 178524 175796 D 7.3 4.6 0:04.25 postgres...

It can be seen that the average load in nearly one minute has soared to 14.47, while the number of CPU logic cores is only 4, which has exceeded the system load.

The us part of the CPU utilization is only about 30%, and most of the CPU is on idle/wait.

references

Linux Load Averages: Solving the Mystery

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report