標籤:
前言:
在一般營運工作中經常會遇到這麼一個情境,伺服器的IO負載很高(iostat中的util),但是無法快速的定位到IO負載的來源進程和來源檔案導致無法進行相應的策略來解決問題。
這個現象在MySQL上更為常見,在5.6(performance_schema提供io instrument)之前,我們通常只能猜到是MySQL導致的高IO,但是沒法定位具體是哪個檔案帶來的負載。
例如是ibdata的刷寫?還是冷門ibd的隨機讀取?
本文就將介紹一個比較簡單的定位IO高負載的流程。
工具準備:
iotop: http://guichaz.free.fr/iotop/
pt-ioprofile:http://www.percona.com/downloads/percona-toolkit/2.2.1/
Step1 : iostat 查看IO情況
iostat -x 1 查看IO情況,從可以看到dfa這個磁碟的IO負載較高,接下來我們就來定位具體的負載來源
Step2: iotop定位負載來源進程
iotop的本質是一個python指令碼,從proc中擷取thread的IO資訊,進行匯總。
從可以看出大部分的IO來源都來自於mysqld進程。因此可以確定dfa的負載來源是資料庫
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負載的主要來源是sbtest (sysbench的IO bound OLTP測試)。
並且壓力主要集中在讀取上。
iotop,pt-ioprofile : mysql IO負載高的來源定位