Linux硬碟效能檢測

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   os   ar   使用   for   

對於現在的電腦來講,整個電腦的效能主要受磁碟IO速度的影響,記憶體、CPU包括主板匯流排的速度已經很快了。

基礎檢測方法1、dd命令

dd命令功能很簡單,就是從一個源讀取資料以bit級的形式寫到一個目標地址,通過這種方式我們就可以檢測我們實際磁碟在linux系統中的讀寫效能,不需要經過任何檢測軟體而就是去讀取資料,一般來講用dd來檢測磁碟的效能也被認為是最接近真實情況。

用法:dd if[資料從哪裡讀取,一般來講從dev下的zero裝置,這個裝置不斷返回0作為資料來源]  of[把讀取的檔案寫入哪個檔案] bs[block size,每次讀寫基本快的大小] count[總共讀寫多少個bs] conv=fdatasync[在linux中有很強的記憶體緩衝機制,為了提高系統效能,linux會大量使用記憶體作為硬碟讀寫緩衝,所以這裡用這個參數來保證資料是直接寫入硬碟]

樣本:

dd if=/dev/zero of=testfile bs=1M count=512 conv=fdatasync

在我的虛擬機器上結果如下:

[[email protected] ~]# dd if=/dev/zero of=testfile bs=1M count=512 conv=fdatasync512+0 records in512+0 records out536870912 bytes (537 MB) copied, 19.6677 s, 27.3 MB/s

一般建議多次運行這個命令取平均值,在每次執行上面的命令前,建議用下面的命令來清除緩衝:

echo 3 > /proc/sys/vm/drop_caches

通過dd命令測試往往不是很嚴謹也不是很科學,因為可能會受cpu使用率和後台服務影響。

2、hdparm命令

hdparm命令專門用來去擷取修改測試磁碟資訊。hdparm必須在管理員權限下運行。

用法:hdparm -t 要測試的磁碟

樣本:

# hdparm -t /dev/sda

結果:

[[email protected] ~]# hdparm -t /dev/sda/dev/sda: Timing buffered disk reads: 444 MB in  3.01 seconds = 147.35 MB/sec[[email protected] ~]# hdparm -t /dev/sda/dev/sda: Timing buffered disk reads: 808 MB in  3.00 seconds = 269.21 MB/sec

可以看到兩次運行結果差距比較大,所以建議多次運行取平均值。

 

用這兩種方式測試出來的結果是非常簡單,專業測試磁碟效能時,不僅需要知道讀寫效能,還要區分讀寫資料大小(4k/16k/32k),還要測試是順序讀寫還是隨機讀寫,如果是機械硬碟還要測試內磁軌和外磁軌的速率差距等等。

進階檢測方法1、bonnie++

可通過yum安裝(不包含在linux預設的yum源中,建議安裝repoforge源):

yum install -y bonnie++

用法:bonnie++ -u 使用者名稱 -s 測試讀寫檔案大小

樣本:

bonnie++ -u root -s 2g

預設情況下,會寫一個4G大小的檔案,分為4份,會通過讀寫隨機操作對系統IO進行全面測試,由於寫的檔案比較大,所以時間會比較長。

結果:

[[email protected] ~]# bonnie++ -u root -s 2gUsing uid:0, gid:0.Writing a byte at a time...doneWriting intelligently...doneRewriting...doneReading a byte at a time...doneReading intelligently...donestart ‘em...done...done...done...done...done...Create files in sequential order...done.Stat files in sequential order...done.Delete files in sequential order...done.Create files in random order...done.Stat files in random order...done.Delete files in random order...done.Version  1.96       ------Sequential Output------ --Sequential Input- --Random-Concurrency   1     -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CPlocalhost.locald 2G   287  99 31885  20 59035  15  2795  99 514292  64  9491 421Latency             42230us    2804ms     284ms    8198us    5820us    4819usVersion  1.96       ------Sequential Create------ --------Random Create--------localhost.localdoma -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--              files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP                 16 20946  92 +++++ +++ +++++ +++ 23169  94 +++++ +++ +++++ +++Latency              2539us     853us     993us    1675us     284us    1234us1.96,1.96,localhost.localdomain,1,1414376948,2G,,287,99,31885,20,59035,15,2795,99,514292,64,9491,421,16,,,,,20946,92,+++++,+++,+++++,+++,23169,94,+++++,+++,+++++,+++,42230us,2804ms,284ms,8198us,5820us,4819us,2539us,853us,993us,1675us,284us,1234us

這個格式實在有點亂,不過好在這個軟體還提供了把結果轉換成html表格的工具(用最後一行轉換):

echo 1.96,1.96,localhost.localdomain,1,1414376948,2G,,287,99,31885,20,59035,15,2795,99,514292,64,9491,421,16,,,,,20946,92,+++++,+++,+++++,+++,23169,94,+++++,+++,+++++,+++,42230us,2804ms,284ms,8198us,5820us,4819us,2539us,853us,993us,1675us,284us,1234us | bon_csv2html >> bon_result.html

bon_result.html的顯示如下:

這個就好看多了,簡單解釋一下:

Sequential Output(順序輸出,實際是寫操作)下的 Per Char是值用putc方式寫,毫無疑問,因為cache的line總是大於1位元組的,所以不停的騷擾CPU執行putc,看到cpu使用率是99%.寫的速度是0.3MB/s,非常慢了。

Sequential Output下的block是按照block去寫的,明顯CPU使用率就下來了,速度也上去了,是31MB/s,跟上面用dd測試的差不多。

Sequential Input(順序輸入,實際是讀操作)下的Per Char是指用getc的方式讀檔案,速度是2.5MB/s,CPU使用率是99%。

Sequential Input下的block是指按照block去讀檔案,速度是50MB/s,CPU使用率是64%。

Random Seeks是隨機定址,每秒定址9000多次還算可以的。

Sequential Create(順序建立檔案)

Random Create(隨機建立檔案)

有的結果是很多+號,這表示bonner++認為值不可靠,於是不輸出。一般來說是因為執行的很快,一般來說不是系統瓶頸,所以不用擔心。

2、iozone

iozone提供的資訊更全面和精確,所以iozone是系統效能測試中用的最多的工具之一。

iozone使用略複雜,這裡只用最常用的一些參數:

-l:最小的進程數量,用於並發測試,不想測多進程可以設定為1。

-u:最大的進程數量,用於並發測試,不想測多進程可以設定為1。

-r:預設讀寫基本單位,如16k,這個值一般跟測試的應用有關,如要測試資料庫,這個值就跟資料庫的塊大小一致。

-s:預設讀寫的大小,建議這個值大一些(一般為2倍記憶體大小),因為iozone並不會規避低層的緩衝,所以如果值比較小,可能直接在記憶體中就完成了。

-F:指定快取檔案

樣本:

iozone -l 1 -u 1 -r 16k -s 2g -F tempfile

結果:

Children see throughput for  1 initial writers  =   31884.46 kB/secParent sees throughput for  1 initial writers   =   30305.05 kB/secMin throughput per process          =   31884.46 kB/sec Max throughput per process          =   31884.46 kB/secAvg throughput per process          =   31884.46 kB/secMin xfer                    = 2097152.00 kBChildren see throughput for  1 rewriters    =  102810.49 kB/secParent sees throughput for  1 rewriters     =   95660.98 kB/secMin throughput per process          =  102810.49 kB/sec Max throughput per process          =  102810.49 kB/secAvg throughput per process          =  102810.49 kB/secMin xfer                    = 2097152.00 kBChildren see throughput for  1 readers      =  450193.59 kB/secParent sees throughput for  1 readers       =  450076.28 kB/secMin throughput per process          =  450193.59 kB/sec Max throughput per process          =  450193.59 kB/secAvg throughput per process          =  450193.59 kB/secMin xfer                    = 2097152.00 kBChildren see throughput for 1 re-readers    =  451833.53 kB/secParent sees throughput for 1 re-readers     =  451756.47 kB/secMin throughput per process          =  451833.53 kB/sec Max throughput per process          =  451833.53 kB/secAvg throughput per process          =  451833.53 kB/secMin xfer                    = 2097152.00 kBChildren see throughput for 1 reverse readers   =   61854.02 kB/secParent sees throughput for 1 reverse readers    =   61851.88 kB/secMin throughput per process          =   61854.02 kB/sec Max throughput per process          =   61854.02 kB/secAvg throughput per process          =   61854.02 kB/secMin xfer                    = 2097152.00 kBChildren see throughput for 1 stride readers    =   43441.66 kB/secParent sees throughput for 1 stride readers     =   43439.83 kB/secMin throughput per process          =   43441.66 kB/sec Max throughput per process          =   43441.66 kB/secAvg throughput per process          =   43441.66 kB/secMin xfer                    = 2097152.00 kBChildren see throughput for 1 random readers    =   47707.72 kB/secParent sees throughput for 1 random readers     =   47705.00 kB/secMin throughput per process          =   47707.72 kB/sec Max throughput per process          =   47707.72 kB/secAvg throughput per process          =   47707.72 kB/secMin xfer                    = 2097152.00 kBChildren see throughput for 1 mixed workload    =   50807.69 kB/secParent sees throughput for 1 mixed workload     =   50806.24 kB/secMin throughput per process          =   50807.69 kB/sec Max throughput per process          =   50807.69 kB/secAvg throughput per process          =   50807.69 kB/secMin xfer                    = 2097152.00 kBChildren see throughput for 1 random writers    =   45131.93 kB/secParent sees throughput for 1 random writers     =   43955.32 kB/secMin throughput per process          =   45131.93 kB/sec Max throughput per process          =   45131.93 kB/secAvg throughput per process          =   45131.93 kB/secMin xfer                    = 2097152.00 kB

從上面的結果中可以看到各種方式下系統磁碟的讀寫效能。

PS:其實下面還有結果,只是我的虛擬機器磁碟滿了,崩潰了。

參考文檔

1、Linux硬碟效能檢測

2、瞭解你的磁碟之使用bonnie++測試磁碟效能

Linux硬碟效能檢測

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.