IO負載高的來源定位 IO系列


 http://elf8848.iteye.com/category/281637

前言:

在一般運維工作中經常會遇到這么一個場景,服務器的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測試)。

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM