###### tags: `Linux`, `SRE` # SRE 讀書會 Round 4 #02 - 線上讀書會共筆 ## 活動資訊 * Date: 05/07 (四) 20:00 - 21:30 * [導讀進度表](https://docs.google.com/spreadsheets/d/1Lgti3mILkvwxyzklX1vvLraaGD-7ePK9rkmlulfOknE/edit#gid=0) * [導讀 Guideline](https://study-area.sre.tw/GuideLine/) * Github: [study-area-docs](https://github.com/cross-community/study-area-docs) --- # 現場共筆 ## 基礎篇05: 某個應用的 CPU 使用率居然達到 100%, 我該怎麼辦? #### 工具分享 - top - htop: 與 TOP 差異是會把 loading 用圖示的方式顯示 - btop - atop - glances - pidstat 1 5 - 每個一秒鐘取樣一次,跑五次 #### 文章分享 * [Linux CPU利用率的這點事,身為DevOps的你有必要知道](https://kknews.cc/zh-tw/code/8ger29g.html):**推推** * [4.3. INTERRUPTS AND IRQ TUNING](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/performance_tuning_guide/s-cpu-irq) 龍星:我的老筆記 https://sites.google.com/site/ina2588book/ Verynice(包:verynice)服務通過調整進程nice(優先級)動態分配CPU資源。/etc/verynice.conf是配置文件,Verynice會分給其中goodexe(比如X、多媒體軟件)更多的CPU資源,badexe反之。 IOWait 放在 http://www.brendangregg.com/USEmethod/use-linux.html http://www.brendangregg.com/linuxperf.html #### 小結 - 碰到常規問題無法解釋的 CPU 使率⽤率情況時,⾸先要想到有可能是短時間應⽤導致的問題 - 比如是下⾯這兩種情況: 1. 應⽤裡直接調⽤了其它⼆進制程式,這些程式通常運⾏時間比較短,通過 top 等⼯具也不容易發現。 2. 應⽤本⾝在不停的崩潰重啟,⽽啟動過程的資源初始化,很可能會佔⽤相當多的 CPU #### 問題探討 **Q1: nice 為什麼 user 只能動 1~19?** A: 可能是因為系統層面有些部分還是需要更高的權限,類似 tcp port 1024 以下只有 root 可以開。 A2: [CAP_SYS_NICE](http://man7.org/linux/man-pages/man2/nice.2.html) 能力權限的控管 > The calling process attempted to increase its priority by supplying a negative inc but has insufficient privileges. Under Linux, the CAP_SYS_NICE capability is required. (But see the discussion of the RLIMIT_NICE resource limit in **Q2: irq 和 softirq 有什麼不同?** A2: softirq 應該是共用硬體 irq,軟中斷。 ## 案例06: 系統的 CPU 使用率很高,但為啥卻找不到高的 CPU 應用? **Nginx RPS (Request Per Seconds) 比較** 正常情況下:14540.80 (/seconds) 使用 ab 測試情況下: 280 (/seconds) <-- 因有問題導致 RPQ 過低 (沒有比較沒有傷害) * debug 需要有經驗 * 當在救火時,建議要有發言人,讓救火的人可以安心救火,不被打擾 * permission denied * userid of process =\= userid of file or directory * 有些 process 是短時間 process, 所以會不斷重啟, pid 會一直改變,這樣很難去偵測問題,所以要去找他的 parent process, 找到調用它的 process, 比較可以找到問題。 * 指令記得盡量用打的,不要 copy & paste * bandwidthd: 查看網路頻寬資訊的工具 irq: 硬體有關,通常是網路處理封包 ## 延伸討論話題 * https://github.com/michael-kehoe/sre-interview/blob/master/system-design.md --- # 參考資料 * [jiffies, HZ, ticks](https://eeepage.info/jiffies-kernel-timer/) * [execsnoop](http://www.brendangregg.com/blog/2014-07-28/execsnoop-for-linux.html) * download: https://github.com/brendangregg/perf-tools * [top](https://rickhw.github.io/2019/09/08/Linux/top/) * [execsnoop](https://github.com/brendangregg/perf-tools) * [bandwidthd](http://bandwidthd.sourceforge.net) * [LinkedIn 內部資深 SRE 所列舉的 SRE 面試題目](https://www.facebook.com/groups/sre.taiwan/permalink/1660123477486883/)