resources 理解 %IOWAIT (%WIO) LINUX系統的CPU使用率和LOAD Linux Performance Observability Tools How Linux CPU Usage Time and Percentage is calculated Linux進程狀態 ...
resources
- 理解 %IOWAIT (%WIO)
- LINUX系統的CPU使用率和LOAD
- Linux Performance Observability Tools
- How Linux CPU Usage Time and Percentage is calculated
- Linux進程狀態
man (on RHEL 7)
# man mpstat
%usr
Show the percentage of CPU utilization that occurred while executing at the user level (application).
%nice
Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.
%sys
Show the percentage of CPU utilization that occurred while executing at the system level (kernel).Note that this does not include time spent servicing hardware and software interrupts.
%iowait
Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%irq
Show the percentage of time spent by the CPU or CPUs to service hardware interrupts.
%soft
Show the percentage of time spent by the CPU or CPUs to service software interrupts.
%steal
Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.
%guest
Show the percentage of time spent by the CPU or CPUs to run a virtual processor.
%gnice
Show the percentage of time spent by the CPU or CPUs to run a niced guest.
%idle
Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
# man top
us, user : time running un-niced user processes
sy, system : time running kernel processes
ni, nice : time running niced user processes
id, idle : time spent in the kernel idle handler
wa, IO-wait : time waiting for I/O completion
hi : time spent servicing hardware interrupts
si : time spent servicing software interrupts
st : time stolen from this vm by the hypervisor
TIPS
- CPU Usage Time and Percentage
參考 mpstat 手冊,%usr + %nice + %sys + %iwoait + %irq + %soft + %steal + %guest + %gnice + %idle = 100% %steal一般是在虛擬機中才能看到數值,比如CPU overcommitment很嚴重的VPS,而%guest和%nice一般都很低,
所以也可以根據/proc/stat或者top可得,user + nice + system + idle + iowait + irq + softirq + steal = 100 To calculate Linux CPU usage time subtract the idle CPU time from the total CPU time as follows: Total CPU time since boot = user + nice + system + idle + iowait + irq + softirq + steal Total CPU Idle time since boot = idle + iowait Total CPU usage time since boot = (Total CPU time since boot) - (Total CPU Idle time since boot) Total CPU percentage = (Total CPU usage time since boot)/(Total CPU time since boot X 100)
- Linux進程狀態
運行狀態(TASK_RUNNING):
是運行態和就緒態的合併,表示進程正在運行或準備運行,Linux 中使用TASK_RUNNING 巨集表示此狀態
可中斷睡眠狀態(淺度睡眠)(TASK_INTERRUPTIBLE):
進程正在睡眠(被阻塞),等待資源到來是喚醒,也可以通過其他進程信號或時鐘中斷喚醒,進入運行隊列。Linux 使用TASK_INTERRUPTIBLE 巨集表示此狀態。
不可中斷睡眠狀態(深度睡眠狀態)(TASK_UNINTERRUPTIBLE):
其和淺度睡眠基本類似,但有一點就是不可被其他進程信號或時鐘中斷喚醒。Linux 使用TASK_UNINTERRUPTIBLE 巨集表示此狀態。
暫停狀態(TASK_STOPPED):
進程暫停執行接受某種處理。如正在接受調試的進程處於這種狀態,Linux 使用TASK_STOPPED 巨集表示此狀態。
僵死狀態(TASK_ZOMBIE):
進程已經結束但未釋放PCB,Linux 使用TASK_ZOMBIE 巨集表示此狀態
- %iowait 的正確認知
%iowait 表示在一個採樣周期內有百分之幾的時間屬於以下情況:CPU空閑、並且有仍未完成的I/O請求。
對 %iowait 常見的誤解有兩個:
一是誤以為 %iowait 表示CPU不能工作的時間,
二是誤以為 %iowait 表示I/O有瓶頸。
首先 %iowait 升高並不能證明等待I/O的進程數量增多了,也不能證明等待I/O的總時間增加了。
例如,在CPU繁忙期間發生的I/O,無論IO是多還是少,%iowait都不會變;當CPU繁忙程度下降時,有一部分IO落入CPU空閑時間段內,導致%iowait升高。
再比如,IO的併發度低,%iowait就高;IO的併發度高,%iowait可能就比較低。
可見%iowait是一個非常模糊的指標,如果看到 %iowait 升高,還需檢查I/O量有沒有明顯增加,avserv/avwait/avque等指標有沒有明顯增大,應用有沒有感覺變慢,如果都沒有,就沒什麼好擔心的。
- 查看CPU使用率,推薦如下Linux命令:
# top
# sar -u 1 5
# vmstat -n 1 5
# mpstat -P ALL 1 5
- 查看Load的值,推薦如下Linux命令:
# top
# uptime
# sar -q 1 5