日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux测试磁盘io脚本,脚本分享:Linux下磁盘io测试

發布時間:2023/12/15 linux 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux测试磁盘io脚本,脚本分享: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, "

# 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 –w

即可完成開啟文件系統換的磁盤寫測試。程序執行完畢后會在當前目錄下創建.log文件用于記錄測試結果,下圖是蚊子測試的結果,我做成了表格。

總結

以上是生活随笔為你收集整理的linux测试磁盘io脚本,脚本分享:Linux下磁盘io测试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。