日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux系统的CPU使用率和Load

發(fā)布時(shí)間:2025/5/22 linux 167 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux系统的CPU使用率和Load 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??

好吧,我承認(rèn)這個(gè)話題是老生常談,我自己也在2009年剛接觸性能測試時(shí)就已經(jīng)開始關(guān)注并略知一二;然而,對(duì)于CPU使用率和系統(tǒng)負(fù)載Load的確切含義以及它們之間的關(guān)系,我相信不是每個(gè)人都說得清楚的(包括我自己)。也時(shí)常被了解性能測試的新手問道CPU使用率和Load方面的基本慨念,所以我決定還是自己寫篇文章吧,讓自己也梳理得更加清晰一點(diǎn)。

? ?Linux系統(tǒng)的CPU使用率的概念是比較容易理解的,顧名思義就是CPU的使用狀況,也就是一段時(shí)間之中,CPU用于執(zhí)行任務(wù)占用的時(shí)間與總的時(shí)間的比率。

? ?在top、sar、vmstat、mpstat等命令中可以看到CPU使用率通常包含如下幾種統(tǒng)計(jì)(摘自 man sar):

? ?

? ?%user ? ?Percentage ?of ?CPU ?utilization ?that ?occurred while executing at the user level (application). Note that this field includes time spent running virtual processors. (未標(biāo)志nice值的)用戶態(tài)程序的CPU占用率。

? ?%nice ? ?Percentage of CPU utilization that occurred while executing at the user level with nice priority. 標(biāo)志了nice值的用戶態(tài)程序的CPU占用率。

? ?%system ?Percentage ?of ?CPU ?utilization ?that ?occurred ?while ?executing ?at the system level (kernel). Note that this field includes time spent servicing hardware and software interrupts. 系統(tǒng)態(tài)(內(nèi)核)程序的CPU占用率。

? ?%iowait ?Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. I/O等待的CPU占用率。

? ?%steal ? Percentage ?of ?time ?spent ?in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor. 這個(gè)一般是在虛擬機(jī)中才能看到數(shù)值,比如:我的VPS供應(yīng)商CPU overcommitment很嚴(yán)重,故我偶爾能看到%steal值有點(diǎn)高。

? ?%idle ? ?Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. %idle越高,說明CPU越空閑。

? ?

? ?查看CPU使用率,推薦如下Linux命令:

[root@jay-linux?~]#?top [root@jay-linux?~]#?sar?-u?1?5 [root@jay-linux?~]#?vmstat?-n?1?5 [root@jay-linux?~]#?mpstat?-P?ALL?1?5

Linux的Load(系統(tǒng)負(fù)載),是一個(gè)讓新手不太容易了解的概念。top/uptime等工具默認(rèn)會(huì)顯示1分鐘、5分鐘、15分鐘的平均Load。具體來說,平均Load是指,在特定的一段時(shí)間內(nèi)統(tǒng)計(jì)的正在CPU中運(yùn)行的(R狀態(tài))、正在等待CPU運(yùn)行的、處于不可中斷睡眠的(D狀態(tài))的任務(wù)數(shù)量的平均值。

我估計(jì)也沒說的太清楚,看下wikipedia上的一段話吧:An idle computer has a load number of 0. Each process using or waiting for CPU (the ready queue or run queue) increments the load number by 1. Most UNIX systems count only processes in the running (on CPU) or runnable (waiting for CPU) states. However, Linux also includes processes in uninterruptible sleep states (usually waiting for disk activity), which can lead to markedly different results if many processes remain blocked in I/O due to a busy or stalled I/O system.

還有man sar中的解釋:The load average is calculated as the average number of runnable or ?running tasks (R state), and the number of tasks in uninterruptible sleep (D state) over the specified interval.

對(duì)于一個(gè)系統(tǒng)來說,多少的Load算合理,多少又算Load高呢?

一般來說,對(duì)于Load的數(shù)值不要大于系統(tǒng)的CPU核數(shù)(或者開啟了超線程,超線程也當(dāng)成CPU core吧)。當(dāng)然,有人覺得Load等于CPU core數(shù)量的2倍也沒事,不過,我自己是在Load達(dá)到CPU core數(shù)量時(shí),一般都會(huì)去查看下是什么具體原因?qū)е耹oad較高的。

Linux中查看Load的命令,推薦如下:

[root@jay-linux?~]#?top [root@jay-linux?~]#?uptime [root@jay-linux?~]#?sar?-q?1?5

最后,說一下CPU使用率和Load的關(guān)系吧。如果主要是CPU密集型的程序在運(yùn)行(If CPU utilization is near 100 percent (user + nice ?+ ?system), the workload sampled is CPU-bound.),那么CPU利用率高,Load一般也會(huì)比較高。而I/O密集型的程序在運(yùn)行,可能看到CPU的%user, %system都不高,%iowait可能會(huì)有點(diǎn)高,這時(shí)的Load通常比較高。同理,程序讀寫慢速I/O設(shè)備(如磁盤、NFS)比較多時(shí),Load可能會(huì)比較,而CPU利用率不一定高。這種情況,還經(jīng)常發(fā)生在系統(tǒng)內(nèi)存不足并開始使用swap的時(shí)候,Load一般會(huì)比較高,而CPU使用率并不高。

本文就簡單說這么多了,想了解更全面的信息,可參考以下方法:

1. man sar, man top ?(認(rèn)真看相關(guān)解析,定有收獲)

2. wikipedia:http://en.wikipedia.org/wiki/Load_%28computing%29

3. 幫助理解Load:http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages

4. 幫助理解load的中文博客:http://www.blogjava.net/cenwenchu/archive/2008/06/30/211712.html



轉(zhuǎn)載于:https://my.oschina.net/fdhay/blog/661941

總結(jié)

以上是生活随笔為你收集整理的Linux系统的CPU使用率和Load的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。