【CPU篇】系統負載load average

一、什麼是系統負載

系統負載又叫平均負載(load average),man /proc/loadavg和man update都能看到系統負載的含義。

cat /proc/loadavg
0.18 0.26 0.25 2/251 20320

man /proc/loadavg

The first three fields in this file are load average figures giving the number of jobs in the run queue (state R) or waiting for disk I/O (state D) averaged over 1, 5, and 15 minutes. They are the same as the load average numbers given by uptime(1) and other programs. The fourth field consists of two numbers separated by a slash (/). The first of these is the number of currently runnable kernel scheduling entities (processes, threads). The value after the slash is the number of kernel scheduling entities that currently exist on the system. The fifth field is the PID of the process that was most recently created on the system.

man update

System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time.

 

二、基礎知識

  1. 指令:uptime、top、/proc/loadavg(平均負載即系統負載,能看到系統整體的情況,沒有隻能看進程負載的指令)
  2. load average:平均活躍進程數(R態+D態),衡量系統資源的爭用情況
  3. 症狀:如果load average比cpu核心數高出太多,那麼系統負載過高,說明活躍進程過多,是什麼導致活躍進程過多的?
    1. 活躍進程都在爭用CPU資源?大量R態進程在就緒隊列中,是什麼原因導致進程/線程過多,有可能代碼中有地方無節制的創建新的進程、線程;還有可能代碼中有地方死循環,導致系統的吞吐量下降,任務堆積
    2. 活躍進程都在爭用IO資源?大量D態進程在使用/等待IO,看是否合理,是否到該磁盤介質的性能瓶頸,ramdiksk優化,上緩存等優化等;是否是磁盤出問題,飄盤、掉盤、壞盤,文件系統的問題等
  4. 資料
    1. https://scoutapm.com/blog/understanding-load-averages
    2. https://linux.die.net/man/5/proc
    3. https://www.man7.org/linux/man-pages/man1/uptime.1.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章