系統性能分析工具&&一些我對磁盤IOPS的簡單認識

系統管理必須知道怎樣去評判當前系統的性能,性能涉及cpu、內存、存儲、網絡等,使用工具統計分析並從中總結一些相關調節優化經驗

工具程序的安裝
+-------iostat vmstat iftop dstat --------+
yum -y install sysstat procps  iftop dstat

 ----------------------iostat-------------------------

作用:iostat是I/O statistics(輸入/輸出統計)的縮寫,iostat工具將對系統的磁盤操作活動進行監視。它的特點是彙報磁盤活動統計情況,同時也會彙報出CPU使用情況。

用法:iostat [ -c | -d ] [ -k ] [ -t ] [ -V ] [ -x [ device ] ] [ interval [ count ] ]
主要選項如下
-c:顯示CPU的使用情況。
-d:顯示磁盤的使用情況。
-k:表示按千字節每秒顯示數據。
-t:打印彙報的時間。
-v:表示打印出版本信息和用法。
-x device:指定要統計的設備名稱,默認爲所有的設備。
interval:指每次統計間隔的時間,count指按照這個時間間隔統計的次數。

示例及說明

 iostat -k -x /dev/sda 1 3

 

%iowait
    Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%idle
    Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
avgrq-sz
    The average size (in sectors) of the requests that were issued to the device.
avgqu-sz
    The average queue length of the requests that were issued to the device.
await
    The  average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by  the requests in queue and the time spent servicing them...(形象點比喻爲:某超市收款臺5分鐘內有3哥人需要結賬,每個人的等待時間(0ms、1ms,3ms),對應的結賬花費(1ms、2ms、1ms),該值爲[(0+1+3)+(1+2+1)]/3 -> 2.6)
svctm
    The average service time (in milliseconds) for I/O requests that were issued to the device..(形象點比喻爲:某超市收款臺5分鐘內有3個人需要結賬,該值爲收銀員在每個人身上結賬花(1ms、2ms、1ms)的平均時間,(1+2+1)/3 -> 1.3ms,收銀員的速度)
%util
    Percentage of CPU time during which I/O requests were issued to the device  (bandwidth  utilization  for  the  device).Device saturation occurs when this value is close to 100%
.(形象點比喻爲:某超市收款臺5分鐘內有3分鐘時間在排隊,3/5 -> 60%,上圖中的最後一次統計值爲0.8%)

----------vmstat  --------
參考文章:
http://linux.ccidnet.com/art/9513/20070730/1160333_1.html
http://hi.baidu.com/loveastyy/blog/item/29bdb2fa117f1e2b4f4aeade.html

----------iftop--------------
參考文章:
http://gaoxingf.blog.51cto.com/612518/188966

---------dstat---------------

---------說一下iops---------------------------
參考文章:
http://baike.baidu.com/view/2302083.htm?fr=ala0_1

重點摘錄:

1.吞吐量
不同的硬盤所能支撐的流量大小

10 K rpm 15 K rpm ATA
10MB/s 13MB/s 8MB/s

4塊“10K rpm”磁盤最大可支撐的流量=10*13MB/s=130M/s;一塊千兆網卡的實際速率=1024Mb/s / 8=128MB/s

2.IOPS
決定IOPS的主要取決與陣列的算法,cache命中率,以及磁盤個數。陣列的算法因爲不同的陣列不同而不同

每個物理硬盤能處理的IOPS是有限制的

10 K rpm 15 K rpm ATA
100 150 50

4塊“15 K rpm”硬盤,它能支撐的最大IOPS爲150*4=600;在raid5與raid10上,讀iops沒有差別,但是相同的業務,寫iops最終落在每塊磁盤上是有差別的,如果達到了每塊磁盤的寫的i0ps限制,性能會受到影響。

舉例,iops算法,假定有業務的iops爲10000,讀cache命中率爲30%,讀iops爲60%,寫iops爲40%,磁盤個數爲120,那麼分別計算在raid5與raid10的情況下,每塊磁盤的iops爲多少

raid5

單塊盤的iops = (10000*(1-0.3)*0.6 + 2 * (10000*0.4)*(1-0.3) + 2 * (10000*0.4))/120
 
  = (4200 + 5600 + 8000)/120
 
  = 148
 
計算出來單個盤的iops爲148個,基本達到磁盤極限

這裏的10000*(1-0.3)*0.6表示是讀的iops,4 * (10000*0.4) 表示寫的iops,因爲每一個寫,在raid5中,實際發生了4個io,raid5在寫操作的時候,那2個讀操作也可能發生命中

raid10

單塊盤的iops = (10000*(1-0.3)*0.6 + 2 * (10000*0.4))/120
 
  = (4200 + 8000)/120
 

  = 102

可以看到,因爲raid10對於一個寫操作,只發生2次io,所以,同樣的壓力,同樣的磁盤,每個盤的iops只有102個,還遠遠低於磁盤的極限iops。

從上述描述中你會有什麼啓示呢?我的啓示如下(如有不同意見,請指正)

1.如果我想充分利用一塊千兆網卡,那麼我的系統必須用4塊磁盤做個raid0

2.假設我實際的業務(case)的IOPS爲10000(這個值是怎麼來的呢,呵呵,業務運作後可通過相關監控統計來大概計算或者憑經驗),那麼我需要多少塊硬盤呢?上面有計算公式

3.根據業務來選擇相應的陣列類型,當我單塊磁盤的IOPS達到極限時,就需要增加硬盤了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章