共計 2272 個字符,預計需要花費 6 分鐘才能閱讀完成。
丸趣 TV 小編給大家分享一下 Linux 下磁盤 io 測試怎么用,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
這兩天在測試 Dell 的 PS6000 存儲,在 linux 下也懶得去找測試工具了,就直接使用 dd 命令進行 I / O 測試,但因為需要測試的數據很多,從 512b 到 4M 的塊,每一檔都要進行讀寫的測試,這要是人肉來做,那就太累了,于是就產生了下面這個腳本。
本腳本使用 perl 編寫,根據測試用例,完成每次讀或寫測試。
本腳本共有 3 個參數,兩個是必選參數,一個是可選參數
-r 測試讀性能
-w 測試寫性能
-c 可選參數,用于關閉文件系統的緩存
#!/bin/evn perl
use JSON;
use Data::Dumper;
use Cwd;
use File::Basename;
our $cache_flag =
# 獲取腳本所在目錄
my $cwd;
if ( $0 =~ m{^/} ) {$cwd = dirname($0);
else {my $dir = getcwd();
$cwd = dirname( $dir/$0
# 獲得參數
if ( @ARGV 1 ) {
usage;
exit;
elsif ( @ARGV == 1 ) {if ( ( $ARGV[0] ne -r ) ( $ARGV[0] ne -w ) ) {
print Unrecognized Option\n
usage;
exit;
elsif ( @ARGV == 2 ) {if ( $ARGV[0] eq -r ) {
$cache_flag = iflag=direct,nonblock
elsif ( $ARGV[0] eq -w ) {
$cache_flag = oflag=direct,nonblock
elsif ( ( $ARGV[0] ne -r ) || ( $ARGV[0] ne -w ) ) {
print Unrecognized Option\n
usage;
exit;
my $opt = $ARGV[0];
# 使用幫助
sub usage {print Usage: iotest.pl [OPTION] [OPTION]\n
print \n
print -r\texecute read test\n
print -w\texecute write test\n
print -c\tiotest with local filesystem cache\n\n
# 檢查測試文件是否存在
sub check_file {if ( !-e ./iotest ) {
print The test file dose not exist,please run write test first\n
exit;
# 打開測試用例
open FH, $cwd/iotest.json
# Main #
while () {
chomp;
$json = new JSON;
# 將測試用例的 json 格式轉成 hash
my %strings = %{ $json- decode($_) };
if ( $opt eq -r ) {
check_file;
while ( ( $key, $value ) = each %strings ) {
open rfh, iotestr.log
my $cmd =
/bin/dd if=./iotest of=/dev/null bs=$key count=$value $cache_flag iotestr.log 2 1
print rfh IOTest Block: $key\n
`$cmd`;
print rfh \n
elsif ( $opt eq -w ) {while ( ( $key, $value ) = each %strings ) {
open wfh, iotestw.log
my $cmd =
/bin/dd if=/dev/zero of=./iotest bs=$key count=$value $cache_flag iotestw.log 2 1
print wfh IOTest Block: $key\n
`$cmd`;
print wfh \n
}
下面來看下測試用例的編寫格式。這里蚊子采用了 json 串的方式,這樣便于 perl 讀取,文件內容如下
{512 : 4096000 , 1K : 2048000 , 2K : 1024000 , 4K : 512000 , 8K : 256000 , 16K : 128000 , 32K : 64000 , 64k : 32000 , 128k : 16000 , 256k : 8000 , 512k : 4000 , 1M : 2000 , 2M : 1000 , 4M : 500}
該文件主要就分兩個字段,冒號前的是塊大小,冒號后的 count 數,通過塊大小和 count 數就能創建文件,蚊子這里統一生成的是 2G 大小的文件。該文件保存文件名為 iotest.json,將測試用例和測試腳本放到同一個目錄下即可。使用方面很簡單,進入到要測試的磁盤或目錄下,執行
#perl /dir/to/iotest.pl ndash;w
即可完成開啟文件系統換的磁盤寫測試。程序執行完畢后會在當前目錄下創建.log 文件用于記錄測試結果,下圖是蚊子測試的結果,我做成了表格。
以上是“Linux 下磁盤 io 測試怎么用”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注丸趣 TV 行業資訊頻道!