1. 程式人生 > >IO負載高的來源定位

IO負載高的來源定位

有用 orm util 參數 解決 als ron strac down

在一般運維工作中經常會遇到這麽一個場景,服務器的IO負載很高(iostat中的util),但是無法快速的定位到IO負載的來源進程和來源文件導致無法進行相應的策略來解決問題。

這個現象在MySQL上更為常見,在5.6(performance_schema提供io instrument)之前,我們通常只能猜到是MySQL導致的高IO,但是沒法定位具體是哪個文件帶來的負載。

例如是ibdata的刷寫?還是冷門ibd的隨機讀取?

工具準備:

iotop: http://guichaz.free.fr/iotop/

pt-ioprofile:http://www.percona.com/downloads/percona-toolkit/2.2.1/

step1 : iostat 查看IO情況

iostat -x -d 1 查看IO情況,從下圖可以看到dfa這個磁盤的IO負載較高,接下來我們就來定位具體的負載來源

Step2: iotop定位負載來源進程

iotop的本質是一個python腳本,從proc中獲取thread的IO信息,進行匯總

Step3 pt-ioprofile定位負載來源文件

pt-ioprofile的原理是對某個pid附加一個strace進程進行IO分析。

以下是摘自官網的一段警示:

However, it works by attaching strace to the process using ptrace(), which will make it run very slowly until strace detaches. In addition to freezing the server, there is also some risk of the process crashing or performing badly after strace detaches from it, or indeed of strace not detaching cleanly and leaving the process in a sleeping state. As a result, this should be considered an intrusive tool, and should not be used on production servers unless you are comfortable with that.

通過ps aux|grep mysqld 找到 mysqld進程對應的進程號,通過pt-ioprofile查看哪個文件的IO占用時間最多。

默認參數下該工具展示的是IO占用的時間。

對於定位問題更有用的是通過IO的吞吐量來進行定位。使用參數 --cell=sizes,該參數將結果已 B/s 的方式展示出來

IO負載高的來源定位