自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

腳本分享:Linux下磁盤io測試

運(yùn)維 系統(tǒng)運(yùn)維
這兩天在測試Dell的PS6000存儲,在linux下也懶得去找測試工具了,就直接使用dd命令進(jìn)行I/O測試,但因?yàn)樾枰獪y試的數(shù)據(jù)很多,從512b到4M的塊,每一檔都要進(jìn)行讀寫的測試,這要是人肉來做,那就太累了,于是就產(chǎn)生了下面這個腳本。本腳本使用perl編寫,根據(jù)測試用例,完成每次讀或?qū)憸y試。

 這兩天在測試Dell的PS6000存儲,在linux下也懶得去找測試工具了,就直接使用dd命令進(jìn)行I/O測試,但因?yàn)樾枰獪y試的數(shù)據(jù)很多,從512b到4M的塊,每一檔都要進(jìn)行讀寫的測試,這要是人肉來做,那就太累了,于是就產(chǎn)生了下面這個腳本。

本腳本使用perl編寫,根據(jù)測試用例,完成每次讀或?qū)憸y試。

本腳本共有3個參數(shù),兩個是必選參數(shù),一個是可選參數(shù)

-r 測試讀性能

-w 測試寫性能

-c 可選參數(shù),用于關(guān)閉文件系統(tǒng)的緩存

#!/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");
}
# 獲得參數(shù)
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格式轉(zhuǎn)成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讀取,文件內(nèi)容如下

{"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數(shù),通過塊大小和count數(shù)就能創(chuàng)建文件,蚊子這里統(tǒng)一生成的是2G大小的文件。該文件保存文件名為iotest.json,將測試用例和測試腳本放到同一個目錄下即可。使用方面很簡單,進(jìn)入到要測試的磁盤或目錄下,執(zhí)行

#perl /dir/to/iotest.pl –w

即可完成開啟文件系統(tǒng)換的磁盤寫測試。程序執(zhí)行完畢后會在當(dāng)前目錄下創(chuàng)建.log文件用于記錄測試結(jié)果,下圖是蚊子測試的結(jié)果,我做成了表格。

 

原文:http://www.wenzizone.cn/?p=405

【編輯推薦】

  1. Linux性能監(jiān)測:磁盤IO篇
  2. 詳解iostat -dx 1命令監(jiān)控IO性能
  3. 性能優(yōu)化的技巧
  4. iostat來對linux硬盤IO性能進(jìn)行檢測

 

責(zé)任編輯:黃丹 來源: 蚊子空間
相關(guān)推薦

2019-03-28 08:00:00

Linux磁盤IO監(jiān)控存儲設(shè)備

2010-12-21 09:58:37

Linux腳本自動關(guān)機(jī)任務(wù)管理

2019-08-23 06:22:47

LinuxShell監(jiān)控腳本

2010-10-09 09:18:59

Shell腳本

2010-12-22 13:17:47

Linux性能監(jiān)測磁盤IO

2011-11-08 21:51:43

Linux 監(jiān)控 IO

2021-06-21 11:11:29

LinuxIO磁盤IO

2019-07-25 07:14:03

LinuxSync操作系統(tǒng)

2013-08-15 14:10:24

云主機(jī)磁盤IO

2010-05-27 17:51:55

Linux查看磁盤空間

2021-02-21 11:48:30

內(nèi)存磁盤IO

2024-07-31 11:59:23

linux內(nèi)存磁盤

2022-03-01 20:26:12

PythonCSV腳本

2021-09-30 07:26:15

磁盤IO網(wǎng)絡(luò)

2017-06-16 15:18:15

虛擬化WindowsIO

2019-08-12 07:45:44

Linux腳本shell

2023-12-20 14:38:50

Linux磁盤IO

2010-09-06 14:14:32

ppp-on

2009-09-07 09:41:16

2010-12-17 09:52:32

bash命令
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號