mysql iostat_通过『iostat -dx 1』命令监控IO性能
網站的很多性能問題最終都會歸結到IO頭上,所以說理解iostat命令是非常有必要的。
小技巧:你知道iostat是從哪里得到IO相關信息的嗎?使用strace命令能跟蹤到答案:shell> strace -eopen iostat
open("/proc/diskstats", O_RDONLY)
注:關于diskstats的說明,參見官方文檔(field1 ~ field11)。
我最常用的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,diskstats}.
參考資料:
您可能還對下面的文章感興趣:
總結
以上是生活随笔為你收集整理的mysql iostat_通过『iostat -dx 1』命令监控IO性能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 四年级下册语文优化132页怎么读?
- 下一篇: 网传的驱蚊方法哪些是不靠谱的?有科学依据