iostat | 通過『iostat -dx 1』命令監控IO效能
阿新 • • 發佈:2019-07-29
網站的很多效能問題最終都會歸結到IO頭上,所以說理解iostat命令是非常有必要的。 小技巧:你知道iostat是從哪裡得到IO相關資訊的嗎?使用strace命令能跟蹤到答案:
我最常用的iostat命令格式是:『iostat -dx 1』,意思是每隔一秒顯示一次IO擴充套件資訊。
shell> iostat -dx 1 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s sda 0.18 37.71 0.65 2.63 50.18 322.08 avgrq-sz avgqu-sz await svctm %util 113.46 0.35 107.49 1.67 0.55 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s sda 0.00 4208.00 0.00 165.00 0.00 163872.00 avgrq-sz avgqu-sz await svctm %util 993.16 119.54 1144.36 6.07 100.10
注:開頭顯示的是自系統啟動開始的平均值,後面顯示的是每段時間間隔裡的平均值。
介紹一下相關引數的含義:
rrqm/s:佇列中每秒鐘合併的讀請求數量
wrqm/s:佇列中每秒鐘合併的寫請求數量
r/s:每秒鐘完成的讀請求數量
w/s:每秒鐘完成的寫請求數量
rsec/s:每秒鐘讀取的扇區數量
wsec/s:每秒鐘寫入的扇區數量
avgrq-sz:平均請求資料的大小
avgqu-sz:平均請求佇列的長度
await:平均每次請求的等待時間
svctm:平均每次請求的服務時間
util:裝置的利用率
注:建議對照原始碼來記憶這些引數都是如何計算出來的。
關於這些引數,相對重要的是後面幾個,具體來說是:util,svctm,await,avgqu-sz:
util是裝置的利用率。如果它接近100%,通常說明裝置能力趨於飽和(並不絕對,比如裝置有寫快取)。有時候可能會出現大於100%的情況,這多半是計算時四捨五入引起的。\ svctm是平均每次請求的服務時間。這裡有一個公式:(r/s+w/s)*(svctm/1000)=util。舉例子:如果util達到100%,那麼此時svctm=1000/(r/s+w/s),假設IOPS是1000,則svctm大概在1毫秒左右,如果長時間大於這個數值,說明系統出了問題。 await是平均每次請求的等待時間。這個時間包括了佇列時間和服務時間,也就是說,一般情況下,await大於svctm,它們的差值越小,佇列時間越短,反之差值越大,佇列時間越長,說明系統出了問題。 avgqu-sz是平均請求佇列的長度。毫無疑問,佇列長度越短越好,這就不用多做解釋了。
提醒:如果是RAID等多盤系統,iostat結果的參考價值可能有變化,建議查閱相關資料。
說明:svctm引數在未來某個版本的iostat會被刪除,官方文件是這樣描述原因的:
The average service time (svctm field) value is meaningless, as I/O statistics are calculated at block level, and we don’t know when the disk driver starts to process a request. For this reason, this field will be removed in a future sysstat version.
另外,有時候iostat會顯示一些很離譜的結果,官方FAQ給出瞭如下的解釋:
Because of a Linux kernel bug, iostat -x may display huge I/O response times (svctm) and a bandwidth utilization (%util) of 100% for some devices. Indeed these devices have a value for the field #9 (beginning after the device name) in /proc/{partitions,diskstats} which is always different from 0, and even negative sometimes. Yet this field should go to zero, since it gives the number of I/Os currently in progress (it is incremented as requests are submitted, and decremented as they finish). To (temporarily) solve the problem, you should reboot your system to reset the counters in /proc/{partitions,