Linux 부하 평균 이해 및 Linux 성능 모니터링


이 기사에서는 중요한 Linux 시스템 관리 작업 중 하나 인 시스템/CPU로드 및로드 평균과 관련된 성능 모니터링에 대해 설명합니다.

더 나아 가기 전에 모든 유닉스 계열 시스템에서 다음 두 가지 중요한 문구를 이해합시다.

  • System load/CPU Load – is a measurement of CPU over or under-utilization in a Linux system; the number of processes which are being executed by the CPU or in waiting state.
  • Load average – is the average system load calculated over a given period of time of 1, 5 and 15 minutes.

Linux에서로드 평균은 기술적으로 실행 중 또는 중단 불가능으로 태그가 지정된 커널 (커널) 실행 대기열에있는 프로세스의 실행 평균으로 간주됩니다.

참고 :

  • All if not most systems powered by Linux or other Unix-like systems will possibly show the load average values somewhere for a user.
  • A downright idle Linux system may have a load average of zero, excluding the idle process.
  • Nearly all Unix-like systems count only processes in the running or waiting states. But this is not the case with Linux, it includes processes in uninterruptible sleep states; those waiting for other system resources like disk I/O etc.

Linux 시스템로드 평균을 모니터링하는 방법

시스템이 실행 된 시간, 사용자 수와 부하 평균을 보여주는 가동 시간을 포함하여 시스템 부하 평균을 모니터링하는 다양한 방법이 있습니다.

$ uptime

07:13:53 up 8 days, 19 min,  1 user,  load average: 1.98, 2.15, 2.21

숫자는 왼쪽에서 오른쪽으로 읽 히며 위의 출력은 다음을 의미합니다.

  • load average over the last 1 minute is 1.98
  • load average over the last 5 minutes is 2.15
  • load average over the last 15 minutes is 2.21

평균 부하가 높으면 시스템이 과부하 상태임을 의미합니다. 많은 프로세스가 CPU 시간을 기다리고 있습니다.

CPU 코어 수와 관련하여 다음 섹션에서 이에 대해 설명합니다. 또한 실행중인 Linux 시스템의 실시간 상태를 표시하는 top 및 glances와 같은 다른 잘 알려진 도구와 기타 여러 도구를 사용할 수도 있습니다.

$ top
top - 12:51:42 up  2:11,  1 user,  load average: 1.22, 1.12, 1.26
Tasks: 243 total,   1 running, 242 sleeping,   0 stopped,   0 zombie
%Cpu(s): 17.4 us,  2.9 sy,  0.3 ni, 74.8 id,  4.6 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  8069036 total,   388060 free,  4381184 used,  3299792 buff/cache
KiB Swap:  3906556 total,  3901876 free,     4680 used.  2807464 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                        
 6265 tecmint   20   0 1244348 170680  83616 S  13.3  2.1   6:47.72 Headset                                                                                                                                        
 2301 tecmint    9 -11  640332  13344   9932 S   6.7  0.2   2:18.96 pulseaudio                                                                                                                                     
 2459 tecmint   20   0 1707692 315628  62992 S   6.7  3.9   6:55.45 cinnamon                                                                                                                                       
 2957 tecmint   20   0 2644644 1.035g 137968 S   6.7 13.5  50:11.13 firefox                                                                                                                                        
 3208 tecmint   20   0  507060  52136  33152 S   6.7  0.6   0:04.34 gnome-terminal-                                                                                                                                
 3272 tecmint   20   0 1521380 391324 178348 S   6.7  4.8   6:21.01 chrome                                                                                                                                         
 6220 tecmint   20   0 1595392 106964  76836 S   6.7  1.3   3:31.94 Headset                                                                                                                                        
    1 root      20   0  120056   6204   3964 S   0.0  0.1   0:01.83 systemd                                                                                                                                        
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd                                                                                                                                       
    3 root      20   0       0      0      0 S   0.0  0.0   0:00.10 ksoftirqd/0                                                                                                                                    
    5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H   
....
$ glances
TecMint (LinuxMint 18 64bit / Linux 4.4.0-21-generic)                                                                                                                                               Uptime: 2:16:06

CPU      16.4%  nice:     0.1%                                        LOAD    4-core                                        MEM     60.5%  active:    4.90G                                        SWAP      0.1%
user:    10.2%  irq:      0.0%                                        1 min:    1.20                                        total:  7.70G  inactive:  2.07G                                        total:   3.73G
system:   3.4%  iowait:   2.7%                                        5 min:    1.16                                        used:   4.66G  buffers:    242M                                        used:    4.57M
idle:    83.6%  steal:    0.0%                                        15 min:   1.24                                        free:   3.04G  cached:    2.58G                                        free:    3.72G

NETWORK     Rx/s   Tx/s   TASKS 253 (883 thr), 1 run, 252 slp, 0 oth sorted automatically by cpu_percent, flat view
enp1s0     525Kb   31Kb
lo           2Kb    2Kb     CPU%  MEM%  VIRT   RES   PID USER        NI S    TIME+ IOR/s IOW/s Command 
wlp2s0        0b     0b     14.6  13.3 2.53G 1.03G  2957 tecmint      0 S 51:49.10     0   40K /usr/lib/firefox/firefox 
                             7.4   2.2 1.16G  176M  6265 tecmint      0 S  7:08.18     0     0 /usr/lib/Headset/Headset --type=renderer --no-sandbox --primordial-pipe-token=879B36514C6BEDB183D3E4142774D1DF --lan
DISK I/O     R/s    W/s      4.9   3.9 1.63G  310M  2459 tecmint      0 R  7:12.18     0     0 cinnamon --replace
ram0           0      0      4.2   0.2  625M 13.0M  2301 tecmint    -11 S  2:29.72     0     0 /usr/bin/pulseaudio --start --log-target=syslog
ram1           0      0      4.2   1.3 1.52G  105M  6220 tecmint      0 S  3:42.64     0     0 /usr/lib/Headset/Headset 
ram10          0      0      2.9   0.8  409M 66.7M  6240 tecmint      0 S  2:40.44     0     0 /usr/lib/Headset/Headset --type=gpu-process --no-sandbox --supports-dual-gpus=false --gpu-driver-bug-workarounds=7,2
ram11          0      0      2.9   1.8  531M  142M  1690 root         0 S  6:03.79     0     0 /usr/lib/xorg/Xorg :0 -audit 0 -auth /var/lib/mdm/:0.Xauth -nolisten tcp vt8
ram12          0      0      2.6   0.3 79.3M 23.8M  9651 tecmint      0 R  0:00.71     0     0 /usr/bin/python3 /usr/bin/glances
ram13          0      0      1.6   4.8 1.45G  382M  3272 tecmint      0 S  6:25.30     0    4K /opt/google/chrome/chrome 
...

이러한 도구에서 표시되는로드 평균은/proc/loadavg 파일로 읽혀지며, 아래의 cat 명령을 사용하여 볼 수 있습니다.

$ cat /proc/loadavg

2.48 1.69 1.42 5/889 10570

그래프 형식으로로드 평균을 모니터링하려면 다음을 확인하십시오. ttyload – 터미널에서 Linux로드 평균의 색상 코드 그래프를 표시합니다.

데스크톱 컴퓨터에는 시스템 부하 평균을 보는 데 사용할 수있는 그래픽 사용자 인터페이스 도구가 있습니다.

CPU 수와 관련된 시스템 평균로드 이해

CPU 코어 수가 성능에 미치는 영향에 대한 설명 없이는 시스템 부 하나 시스템 성능을 설명 할 수 없습니다.

  • Multi-processor – is where two or more physical CPU’s are integrated into a single computer system.
  • Multi-core processor – is a single physical CPU which has at least two or more separate cores (or what we can also refer to as processing units) that work in parallel. Meaning a dual-core has 2 two processing units, a quad-core has 4 processing units and so on.

또한 하이퍼 스레딩이라고하는 병렬 컴퓨팅을 개선하기 위해 인텔에서 처음 도입 한 프로세서 기술도 있습니다.

하이퍼 스레딩에서 단일 물리적 CPU 코어는 운영 체제에 대해 두 개의 논리적 CPU 코어로 나타납니다 (그러나 실제로는 하나의 물리적 하드웨어 구성 요소가 있음).

단일 CPU 코어는 한 번에 하나의 작업 만 수행 할 수 있으므로 다중 CPU/프로세서, 다중 코어 CPU 및 하이퍼 스레딩과 같은 기술이 실현되었습니다.

하나 이상의 CPU로 여러 프로그램을 동시에 실행할 수 있습니다. 현재의 Intel CPU는 다중 코어와 하이퍼 스레딩 기술을 모두 사용합니다.

시스템에서 사용 가능한 처리 장치의 수를 찾으려면 다음과 같이 nproc 또는 lscpu 명령을 사용할 수 있습니다.

$ nproc
4

OR
lscpu

표시된대로 grep 명령을 사용하여 처리 장치 수를 찾는 또 다른 방법입니다.

$ grep 'model name' /proc/cpuinfo | wc -l

4

이제 시스템 부하를 더 이해하기 위해 몇 가지 가정을하겠습니다. 다음과 같은 부하 평균이 있다고 가정 해 보겠습니다.

23:16:49 up  10:49,  5 user,  load average: 1.00, 0.40, 3.35
  • The CPU was fully (100%) utilized on average; 1 processes was running on the CPU (1.00) over the last 1 minute.
  • The CPU was idle by 60% on average; no processes were waiting for CPU time (0.40) over the last 5 minutes.
  • The CPU was overloaded by 235% on average; 2.35 processes were waiting for CPU time (3.35) over the last 15 minutes.
  • The one CPU was 100% idle on average, one CPU was being used; no processes were waiting for CPU time(1.00) over the last 1 minute.
  • The CPUs were idle by 160% on average; no processes were waiting for CPU time. (0.40) over the last 5 minutes.
  • The CPUs were overloaded by 135% on average; 1.35 processes were waiting for CPU time. (3.35) over the last 15 minutes.

또한 다음을 좋아할 수 있습니다.

  1. 20 Command Line Tools to Monitor Linux Performance – Part 1
  2. 13 Linux Performance Monitoring Tools – Part 2
  3. Perf- A Performance Monitoring and Analysis Tool for Linux
  4. Nmon: Analyze and Monitor Linux System Performance

결론적으로, 시스템 관리자라면 높은로드 평균이 실제로 걱정할 필요가 있습니다. CPU 코어 수보다 높으면 CPU에 대한 수요가 높음을 의미하고 CPU 코어 수 미만의 평균 부하가 낮 으면 CPU 사용률이 낮음을 나타냅니다.