工作是人生不可或缺的活動,沒有了它就覺得生活好像少了什麼,所以持續地工作到無法工作為止吧!! 不過辛苦工作之餘,也是需要玩樂來調劑身心呢!! ~~有意義的工作即是生活!!~~

星期日, 6月 25, 2006

■ Benchmark Tool - bonnie++

http://www.coker.com.au/bonnie++/readme.html
http://www.coker.com.au/bonnie++/
http://www.coker.com.au/bonnie++/experimental/

Bonnie++ is based on the code for Bonnie by Tim Bray. It is a benchmark suite that is aimed at performing a number of simple tests of hard drive and file system performance. Performing several I/O tests, including sequential and random input and output, randomseeks, and sequential and random creates and deletes.

Bonnie++ 是一個基於 Tim Bray 所發展的 Bonnie 硬碟效能測試程式改良而來的強化版,最主要的改進在於新增了對 2GB 以上檔案大小的測試,以及指定某子目錄下進行大量檔案或目錄的操作 (包含建立/刪除/覆寫 ...等等),且其 Testing items 比 bonnie 較多一些 。

■Download source , build and install.
# cd /share/apps
# mkdir benchmarks
# mkdir benchmarks/bonnie++
# cd benchmarks/bonnie++
# mkdir bin src
# cd src
# wget http://www.coker.com.au/bonnie++/bonnie++-1.03a.tgz
# tar -zxvf bonnie++-1.03a.tgz
# cd bonnie++-1.03a
# ./configure --prefix=/share/apps/benchmarks/bonnie++
# make ; make install

■bonnie++(V1.03)的使用方法。
usage: bonnie++ [-d scratch-dir] [-s size(Mb)[:chunk-size(b)]]
[-n number-to-stat[:max-size[:min-size][:num-directories]]]
[-m machine-name]
[-r ram-size-in-Mb]
[-x number-of-tests] [-u uid-to-use:gid-to-use] [-g gid-to-use]
[-q] [-f] [-b] [-p processes -y]

以下為常用的參數說明:
-d 生成測試檔案的路徑。
-s 生成測試檔案的大小,以M為單位(如果不使用-r參數,則要求文件大小至少是系統記憶體的2倍)。
-m 機器名,實際上可以認為是本次測試的方案名字,可以隨便定義。預設是本機的hostname。
-r 記憶體大小,指定記憶體大小,這樣可以透過-s參數創建 r*2 大小的文件,通常用於縮短測試時間,但是需要注意這樣由於記憶體的cache可能導致測試結果的不準確。
-x 測試的次數。
-u 測試檔案的屬主和群組,預設是執行bonnie++的當前用戶和當前群組。
-g 測試檔案的群組,預設是執行bonnie++的當前群組。
-b 在每次寫文件時調用fsync()函數,對於測試郵件伺服器或者數據庫伺服器這種通常需要
同步操作的情況比較適合,而不使用該參數則比較適合測試copy文件或者編譯等操作的效率。

■指令使用範例

bonnie++ -u 0 > bonnie.result
==>測試程式將以記憶體的兩倍大的預設值,進行檔案 create read erase rewrite 等動作。

Bonnie -m cfhat5 -n 50:0:0:50 -u 0 -r 4092 -s 0 -b -d $Dir
==> Testing with zero size files

bonnie++ -m cfhat5 -n 10:1000000:100000:10 -u 0 -r 4092 -s 0 -b -d $Dir
==> Testing with 100Kb to 1Mb files

bonnie++ -m cfhat5 -n 1:17000000:17000000:10 -u 0 -r 4092 -s 0 -b -d $Dir
==>Testing with 16MB size files

bonnie++ -d/work1 -s10 -r4 -u0
==>其對加載在/work1目錄下的文件系統進行了10Mb(-s10)的測試。因此在執行測試之前必須創建適當類型的文件系統並加載到目錄/work1下。其他的參數指定內存大小(-r4)的M數,和以root身份運行測試程序,測試結果如下: 每種測試都有兩組數據:文件系統速度(K/sec)和CPU佔用率(%CPU)。速度越高,文件系統越好。而對于CPU率來說,數字越小性能越好。

#bonnie++ -d /home -s 2048:16384 -n 0 -m nx7000.maxtor250gb72 -x 1 -r 1024 -u 0:0 -f
==>Write/Read tests on a 2Gb file using 16Kb blocks.

#bonnie++ -d /home -s 4096:32768 -n 0 -m nx7000.maxtor300gb54 -x 1 -r 1024 -u 0:0 -f
==>Write/Read tests on a 4Gb file using 32Kb blocks.

bonnie++ -u root -d /tmp
bonnie++ -s 2048 -d /var/tmp -u root
bonnie++ -s 1g -n 10 -x 5
bonnie++ -u 500:100 -s 250
bonnie++ -f -d . -s 3072 -n 10:100000:10:10 -x 1
bonnie++ -s 100 -r 50 -u root -n 0 -f -d /output_files
bonnie++ -d /testdata -m sun3510 -s 2048 -r 1024
bonnie++ -m cfhat5 -n 0 -u 0 -r 4092 -s $SIZE -f -b -d $Dir
bonnie++ -d $Dir -s 10g -n 5


■執行結果範例:

依次進行解讀,從Writing with putc()開始到Delete files in random order…結束,這是bonnie++作的12項測試,這12項測試依次對應12項結果,而這12項結果又被分為了5大類,分別是Sequential Output(寫測試),Sequential Input(讀測試),Random Seeks(讀寫測試),Sequential Create(順序讀寫文件測試)和Random Create(隨意讀寫文件測試)。
測試步驟和測試結果依次對應的順序如下︰
Writing with putc() -> Sequential Output的Per Chr
Writing intelligently -> Sequential Output的Block
Rewriting -> Sequential Output的Rewrite
Reading with getc() -> Sequential Input的Per Chr
Reading intelligently -> Sequential Input的Block
start 'em -> Random Seeks
Create files in sequential order -> Sequential Create的Create
Stat files in sequential order -> Sequential Create的Read
Delete files in sequential order -> Sequential Create的Delete
Create files in random order -> Random Create的Create
Stat files in random order -> Random Create的Read
Delete files in random order -> Random Create的Delete

每個結果中又包括了2項數值,一個是K位元組數或者檔案數,另一個是%CP,就是執行這項測試時CPU的平均佔用率。再來說明每個測試結果的含義︰

Sequential Output
1.Per Char
就是 Per-Character 的含義。使用putc()函數進行循環寫入,每次寫入的位元組很小,基本上可以放入任意一種 I-Cache 中,這種情況下的CPU消耗在處理putc()代碼和分發磁片文件空間上。
2.Block
使用write(2)函數創建文件。這種情況下的CPU消耗只是在分發磁片檔案空間上。
3.Rewrite
使用read(2)函數讀取文件,然後修改再用write(2)函數寫回。由於檔案的空間已經分發好,所以這種模式可以很有效地測試文件系統緩存和數據傳輸的速度。

Sequential Input
1.Per Char
使用getc()函數循環讀取檔案內容。
2.Block
使用read(2)函數循環讀取文件內容,有效測試磁片讀取的效率。

Random Seek
用read(2)函數讀取文件的block,同時有10%的操作是用write(2)函數將block修改以後寫回文件中。在這個測試中,如果記憶體容量大於所創建的檔案大小,那麼將會出現比較高的數值,而這個數值可能並不能準確反映磁片本身的I/O效率。

Sequential Create和Radom Create
這兩大類測試均是用創建,讀取,刪除大量的小檔案來測試磁片效率。文件名用7位數字和任意個數(0-12)的任意英文字母來組成。在 Sequential 部分,字母在數字之后,而 Random 部分則是字母在數字之前。創建檔案的最小值和最大值等參數可以在bonnie++命令行中用-n參數來控制。

■ Benchmark Tool - bonnie

http://www.textuality.com/bonnie/
http://www.textuality.com/bonnie/advice.html

Bonnie is a benchmark which measures the performance of Unix file system operations. Bonnie is concerned with identifying bottlenecks. Bonnie performs a series of tests on a file of known size. If the size is not pecified, Bonnie uses 100 Mb; but that probably isn't enough for a big modern server - you your file to be a lot bigger than the available RAM.

The testing items include:

■Sequential Output
※Per-Character:
The file is written using the putc() stdio macro. The loop that does the writing should be small enough to fit into any reasonable I-cache. The CPU overhead here is that required to do the stdio code plus the OS file space allocation.

※Block:
The file is created using write(2). The CPU overhead should be just the OS file space allocation.

※Rewrite:
Each Chunk (currently, the size is 16384) of the file is read with read(2), dirtied, and rewritten with write(2), requiring an lseek(2). Since no space allocation is done, and the I/O is well-localized, this should test the effectiveness of the filesystem cache and the speed of data transfer.

■Sequential Input:
※Per-Character:
The file is read using the getc() stdio macro. Once again, the inner loop is small. This should exercise only stdio and sequential input.

※Block:
The file is read using read(2). This should be a very pure test of sequential input performance.

■Random Seeks
This test runs SeekProcCount (currently 4) processes in parallel, doing a total of 4000 lseek()s to locations in the file computed using by random() in bsd systems, drand48() on sysV systems. In each case, the block is read with read(2). In 10% of cases, it is dirtied and written back with write(2). The idea behind the SeekProcCount processes is to make sure there's always a seek queued up.



■指令用法
./Bonnie [-d scratch-dir] [-s size-in-Mb] [-m machine-label] [-html]

[-d scratch-dir]
The name of a directory; Bonnie will write and read scratch files in this directory. Bonnie does not do any special interpretation of the directory name, simply uses it as given. Suppose you used -d /raid1/TestDisk; Bonnie would write, then read back, a file whose name was something like /raid1/TestDisk/Bonnie.34251.
If you do not use this option, Bonnie will write to and read from a file in the current directory, using a name something like ./Bonnie.35152.

Bonnie does clean up by removing the file after using it; however, if Bonnie dies in the middle of a run, it is quite likely that a (potentially very large) file will be left behind.

[-s size-in-Mb]
The number of megabytes to test with. If you do not use this, Bonnie will test with a 100Mb file. In this discussion, Megabyte means 1048576 bytes. If you have a computer that does not allow 64-bit files, the maximum value you can use is 2047.

[-m machine-label]
This is the label that Bonnie will use to label its report. If you do not use this, Bonnie will use no label at all.

[-html]
If you use this, Bonnie will generate a report in HTML form, as opposed to plain text. This is not all that useful unless you are prepared to write a table header.



■執行結果範例: 參考自 http://www.textuality.com/bonnie/advice.html
      
mystery:This test was run with the option -m mystery , "mystery" is the label for the test.
750:This test was run with the option
-s 750:Bonnie used a 750-Megabyte file to do the testing. For the numbers to be valid, the computer had better not have had more than about 200M of memory.
534:When writing the file by doing 750 million putc() macro invocations, Bonnie recorded an output rate of 534 K per second.
65.7:When writing the file by doing 750 million putc() macro invocations, the operating system reported that this work consumed 65.7% of one CPU's time. This is not very good; it suggests either a slow CPU or an inefficient implementation of the stdio interface.
1236:When writing the 750-Mb file using efficient block writes, Bonnie recorded an output rate of 1,236 K per second.
22.5:When writing the 750-Mb file using efficient block writes, the operating system reported that this work consumed 22.5% of one CPU's time.
419:While running through the 750-Mb file just creating, changing each block, and rewriting, it, Bonnie recorded an ability to cover 418 K per second.
17.5:While running through the 750-Mb file just creating, changing each block, and rewriting, it, the operating system reported that this work consumed 17.5% of one CPU's time.
564:While reading the file using 750 million getc() macro invocations, Bonnie recorded an input rate of 564 K per second.
74.3:While reading the file using 750 million getc() macro invocations, the operating system reported that this work consumed 74.3% of one CPU's time. This is amazingly high.
1534:While reading the file using efficient block reads, Bonnie reported an input rate of 1,534 K per second.
32.8:While reading the file using efficient block reads, the operating system reported that this work consumed 32.8% of one CPU's time.
35.0:Bonnie created 4 child processes, and had them execute 4000 seeks to random locations in the file. On 10% of these seeks, they changed the block that they had read and re-wrote it. The effective seek rate was 32.8 seeks per second.
8.3:During the seeking process, the operating system reported that this work consumed 8.3% of one CPU's time.

■ Benchmark Tool - hdparm

Hdparm 這個工具是用來設定 IDE 裝置的,包括如 DMA 模式、傳輸模式設定以及一些其他能改善硬碟及光碟機效能的設定。此工具程式可測試硬碟分別在DMA模式和Normal模式上的分別。

如果您的硬碟是有 DMA 模式功能的,但是系統卻沒有啟動他,那麼您的硬碟存取效能可能會降低一半以上。所以可以用 hdparm 啟動 DMA! 不過 hdparm 裡頭有很多很進階的參數設定值,一般來說不很建議隨意修訂,很容易造成硬碟掛點! 因此用這個指令時,最多是啟動 DMA 模式,以及測試硬碟的存取效能即可。 假設使用的 Linux 中沒有包含這個軟件,可從 ftp://metalab.unc.edu/pub/Linux/system/hardware 查找。

[root@linux ~]# hdparm [-icdmXTt] 磁碟裝置名稱

參數說明:
-i:
系統在開機的過程當中,會利用本身核心的驅動程式(模組)來測試硬碟,利用 -i 參數,可將這些測試值取出來,這些值不一定正確,僅做為提供一個參考值!

-c:
設定 32-bit (32位元)存取模式。這個 32 位元存取模式指的是在硬碟在與 PCI 介面之間傳輸的模式,而硬碟本身是依舊以 16 位元模式在跑得!預設的情況下,這個設定值都會被打開,建議直接使用 c1 即可!

-d:
設定是否啟用 dma 模式, -d1 為啟動, -d0 為取消;

-m:設定同步讀取多個 sector 的模式。一般來說,設定此模式,可降低系統因為讀取磁碟而損耗的效能,一般來說設定為 16/32 是最佳化,不過 WD 硬碟建議值則是 4/8。這個值的最大值,可以利用 hdparm -i /dev/hda 輸出的 MaxMultSect 來設定!一般如果不曉得,設定 16 是合理的!

-X:
設定 UtraDMA 的模式,一般來說 UDMA 的模式值加 64 即為設定值。而且硬碟與主機板晶片必須要同步,所以取最小的那個。一般來說:
33 MHz DMA mode 0~2 (X64~X66)
66 MHz DMA mode 3~4 (X67~X68)
100MHz DMA mode 5 (X69)

-T:測試暫存區 cache 的存取效能

-t:測試硬碟的實際存取效能(較正確!)

參考來源:鳥哥的 Linux 私房菜
http://linux.vbird.org/linux_basic/0230filesystem.php#hdparm

其它參考:
http://wiki.gentoo.tw/mediawiki/index.php/Hdparm
http://support.intel.com/support/tw/graphics/sb/CS-010515.htm
http://www.ibiblio.org/pub/linux/system/hardware/
ftp://metalab.unc.edu/pub/Linux/system/hardware/


【使用hdparm改善Linux系統性能】

如果你的Linux系統用於IDE硬碟,則可以使用 hdparm 工具來提升磁片I/O 的性能。不過使用hdparm要小心,因為有可能會損壞硬碟。所以在使用hdparm之前,仔細閱讀你的硬碟手冊。根據你實際硬碟規格來使用相應的 hdparm 開關參數。對一塊 Ultra ATA/66 EIDE 硬碟,其控制晶片支持多 PIO 模式和DMA,可以使用以下命令來調整磁碟效能︰ # /sbin/hdparm -x66 -d1 -u1 -m16 -c3 /dev/hda

選項說明︰
-c3︰
就是把硬碟的16位格式轉換為32位模式(32-bit mode w/sync)。控制數據如何從pci匯流排傳遞到控制單元。

-m16 ︰改變硬碟的多重磁區的讀功能,-m16可以使得硬碟在一次i/o中斷中讀入16個磁區的數據(據實際硬碟而定)。

-d1︰打開 DMA 模式。

-x66︰在支援 UDMA-capable 的硬碟中,這個參數可以支持雙DMA通道的數據傳輸模式。

-u1 ︰Linux在處理磁片中斷時,可以 unmask 其他的中斷或者附應其他中斷相關的任務。


查看以上的更改情況可以使用以下指令︰
# /sbin/hdparm /dev/hda

測試磁片I/O性能可以使用以下指令︰
# /sbin/hdparm -tT /dev/hda

如果磁碟效能有改進的話,可以使用以下指令來保存設置︰
# /sbin/hdparm -k1 /dev/hda

磁碟機ATA介面 (Advanced Technology Attachment)

通常ATA介面由後面所連接的數字來判斷其介面的傳輸規格。例如ATA/33意即其介面可以支援33MB/sec的資料傳輸速度,同理,ATA/66與ATA/100即為傳輸介面的名稱。 而所有有關ATA介面的規範,是由美國國家標準局(ANSI)來制定,包括ATA~ATA-5等規範。IDE介面除了在介面規格提升之外,介面與系統之間的傳輸規格也不斷翻新,從原來採Int 13中斷方式的PIO Mode 0、1、2、3、4,到後來採用DMA通道,以記憶體直接存取模式的DMA Mode 0、1、2、3、4、5,傳輸速率不斷地倍增。

ATA 的發展有 ATA-1、ATA-2(又稱Enhance IDE)、ATA-3、ATA-4、ATA-33、ATA-66、ATA-100、ATA-133、Serial ATA-150 等,ATA-33 至 ATA-133 是屬於 Ultra ATA,因為 Ultra ATA 屬於 DMA 的方式,所以又稱為 Ultra DMA。

ATAPI 即 ATA Programming Interface,是控制儲存裝置的程式編緝標準,所以安裝 CDROM、DVDROM 都無需額外安裝驅動程式,因為它們已支援ATAPI。下面為規格演進表,提供做為參考:



參考來源:
IDE (Integrated Drive Electrnics) 規格介紹
ATA磁碟機介面規格簡介



其實IDE比較正確的說法是ATA,但由於市面上都稱IDE,所以就習以為稱了。最早期的ATA每秒傳輸速率只有8.33MB(PIO Mode 2),但受限於ISA的頻寬,所以一秒只有4MB的速度。後來另外幾家廠商為了改善這些缺點,聯合幾家CD-ROM的廠商制定了 Enhanced IDE,在原來的ATA之外,支援可抽取存取設備(如光碟機等等)的ATAPI(ATA Packet Interface)規格,而且它提供了PIO Mode 3和 DMA Mode 1 的資料傳輸速率,在開啟 DMA Mode 1 時,最高傳輸速率可達13.3MB/sec,後來一些硬碟廠商又提出 Fast ATA 和 Fast ATA-2,Fast ATA 和 Enhanced IDE 差別在 Fast ATA 不支援可抽取存取設備,然而 Fast ATA-2 不但將 ATAPI 規格列入,也增加了 PIO Mode 4 和 DMA Mode 2,兩者最高傳輸速率都是16.6MB/sec,不管是哪些廠商提出所謂的 Enhanced IDE 或是 Fast ATA-2,在美國國家標準學會都稱之為 ATA-2(ATA Extension),後來又不斷的演進,又推出了ATA-4(因為ATA-3並沒有推出新的傳輸介面,所以不多做介紹),就是現在所謂的 Ultra DMA/33,Ultra DMA 是最新一代的ATA規格,將併入目前的ATA-4,新型的Ultra DMA/33 傳輸速率最高可達33MB/s,至於和 ATA-2/3 最大的差別是 Ultra DMA/33 是並列傳輸,所以比非並列的 ATA-2/3 快很多。

PIO (Programmed Input/Output ):早期傳輸方式,由CPU控制硬碟到系統間的資料傳輸,但CPU快,硬碟慢,需要等待,影響效能。

DMA (Direct Memory Access):由 DMA 控制器直接存取記憶體,不直接經過CPU,讓硬碟與記憶體之間溝通與傳輸作業,絕大部分由硬碟本身與驅動程式共同完成,兩者間的許多溝通與控制作業不再需要透過CPU來管理。所以除了硬碟需要支援DMA的存取方式外,IDE介面卡也要支援DMA方式驅動才可,再加上驅動程式。