%iowait和CPU使用率的正確認知,%iowaitcpu認知

來源:互聯網
上載者:User

%iowait和CPU使用率的正確認知,%iowaitcpu認知
 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 topus, user : time running un-niced user processessy, system : time running kernel processesni, nice : time running niced user processesid, idle : time spent in the kernel idle handlerwa, IO-wait : time waiting for I/O completionhi : time spent servicing hardware interruptssi : time spent servicing software interruptsst : 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 = 100To 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 + stealTotal CPU Idle time since boot = idle + iowaitTotal 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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.