天天看點

io負載高來源定位

前言: 在一般運維工作中經常會遇到這麼一個場景,伺服器的IO負載很高(iostat中的util),但是無法快速的定位到IO負載的來源程序和來源檔案導緻無法進行相應的政策來解決問題。 這個現象在MySQL上更為常見,在5.6(performance_schema提供io instrument)之前,我們通常隻能猜到是MySQL導緻的高IO,但是沒法定位具體是哪個檔案帶來的負載。 例如是ibdata的刷寫?還是冷門ibd的随機讀取? 本文就将介紹一個比較簡單的定位IO高負載的流程。

工具準備:

Step1 : iostat 檢視IO情況

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

io負載高來源定位

 Step2: iotop定位負載來源程序

 iotop的本質是一個python腳本,從proc中擷取thread的IO資訊,進行彙總。

從下圖可以看出大部分的IO來源都來自于mysqld程序。是以可以确定dfa的負載來源是資料庫

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負載高來源定位

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

io負載高來源定位

從上圖可以看出IO負載的主要來源是sbtest (sysbench的IO bound OLTP測試)。

并且壓力主要集中在讀取上。

本文轉自 小羅ge11 51CTO部落格,原文連結:http://blog.51cto.com/xiaoluoge/1589376,如需轉載請自行聯系原作者