#CPU性能評估linux
經過下面的命令能瞭解到CPU是否出現性能瓶頸,再結合top、ps等命令進一步檢查,便可定位到那些進程致使CPU負載過大ios
[blackfox@localhost ~]$ vmstat 2 3 # 間隔2s,打印3次 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 4 0 0 244824 932 497892 0 0 0 0 3 9 0 0 100 0 0 0 0 0 244824 932 497892 0 0 0 0 38 91 0 1 99 0 0 0 0 0 244824 932 497892 0 0 0 0 40 90 0 1 99 0 0
場景:在一個多CPU的系統中,CPU的總體使用率不高,可是系統應用響應緩慢。 結論:單線程只使用一個CPU,致使這個CPU佔用率爲100%,沒法處理其餘請求,而其餘的CPU卻閒置,這就致使了總體CPU使用率不高,而應用緩慢現象的發生。網絡
# sar -P 0 3 5 # 對第一個CPU進行統計 [blackfox@localhost ~]$ sar -u 3 5 # 顯示CPU利用率,間隔3s,顯示5次 Linux 3.10.0-327.el7.x86_64 (localhost.localdomain) 01/22/2017 _x86_64_ (1 CPU) 07:35:52 AM CPU %user %nice %system %iowait %steal %idle 07:35:55 AM all 0.00 0.00 0.00 0.00 0.00 100.00 07:35:58 AM all 0.00 0.00 0.34 0.00 0.00 99.66 07:36:01 AM all 0.34 0.00 0.34 0.00 0.00 99.32 07:36:04 AM all 0.00 0.00 0.34 0.00 0.00 99.66 07:36:07 AM all 0.34 0.00 0.00 0.00 0.00 99.66 Average: all 0.14 0.00 0.20 0.00 0.00 99.66
[blackfox@localhost ~]$ iostat -c Linux 3.10.0-327.el7.x86_64 (localhost.localdomain) 01/22/2017 _x86_64_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.13 0.00 0.23 0.01 0.00 99.63
經驗:8核CPU,load average三個值長期大於8,說明負載很高,會影響系統性能。dom
[blackfox@localhost ~]$ uptime 07:54:27 up 17 days, 16:56, 1 user, load average: 0.00, 0.02, 0.05
經驗:可用內存/物理內存<20%,說明內存緊缺,須要增長內存性能
[blackfox@localhost ~]$ free -m # -m 以MB爲單位,-s 時間段內不間斷監控 total used free shared buff/cache available Mem: 977 249 240 49 487 488 Swap: 2048 0 2048
vmstat命令:監控內存.net
sar -r命令:監控內存線程
經驗:code
一、正常svctm<await。接口
二、svctm接近await表示幾乎沒有I/O等待,性能很好進程
三、cpu/內存複合/過多請求都會使svctm增長
四、%util接近100%,表示I/O滿負荷。
[blackfox@localhost ~]$ sar -d Linux 3.10.0-327.el7.x86_64 (localhost.localdomain) 01/22/2017 _x86_64_ (1 CPU) 12:00:01 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util 12:10:01 AM dev8-0 0.10 0.00 0.89 9.03 0.00 3.97 1.10 0.01 12:20:01 AM dev8-0 0.05 0.00 0.35 7.56 0.00 64.63 61.70 0.28 12:30:01 AM dev8-0 0.02 0.00 0.16 7.08 0.01 254.77 128.
[blackfox@localhost ~]$ iostat -dx /dev/sda3 Linux 3.10.0-327.el7.x86_64 (localhost.localdomain) 01/22/2017 _x86_64_ (1 CPU) Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util sda3 0.00 0.01 0.01 0.05 0.21 0.34 17.98 0.00 41.36 30.56 42.60 7.77 0.05
ping命令:檢測網絡連通
netstat命令:-i 查看網絡接口信息,-r 檢測系統路由表信息
sar -n命令:顯示系統網絡運行狀態
[blackfox@localhost ~]$ sar -n DEV 2 3 # DEV:網絡接口,EDEV:網絡錯誤統計數據,SOCK:套接字信息,FULL:顯示全部 Linux 3.10.0-327.el7.x86_64 (localhost.localdomain) 01/22/2017 _x86_64_ (1 CPU) 09:26:26 AM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 09:26:28 AM eno16777736 0.00 0.00 0.00 0.00 0.00 0.00 0.00 09:26:28 AM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
[blackfox@localhost ~]$ watch -n 3 -d free # -n 重複執行時間,-d 高亮顯示變更 Every 3.0s: free Sun Jan 22 09:21:48 2017 total used free shared buff/cache available Mem: 1001332 256792 245500 50948 499040 498864 Swap: 2098172 0 2098172