#!/usr/bin/perl # # Run some raid benchmark tests # # For a short test # ---------------- # raid_tst.pl -Blk "1024 2048" -Chk "16 32" -doit -Mnt /Backup # # -doit if you want it to run the tests - will destroy the entire contents of your raid array # /Backup is the mountpoint of the raid array # # All results are logged to $LOG # # TODO # ---------------------------------------- # Currently only supports /dev/md0 # # Contributers: # ========================================= # alvin@Linux-Consulting.com - original author # paul@hibernia.spin.ie - he game me the concept and idea of this program # # # 22-Apr-99 amo Date of Birth # # # ------------------------------------------------------- # my ( $NM ) = "raid_tst.pl"; my ( $Args ) = ""; # my ( $Date ) = ` date `; chomp ( $Date ); # my ( $LOG ) = "/tmp/raid_tst.log"; # log file # my ( $RaidTemplate ) = "/tmp/Raid.raid_tst.template.conf"; my ( $RaidTabConf ) = "/tmp/Raid.raid_tst.conf"; my ( $RaidTab ) = "/etc/raidtab"; # # my ( $RaidMnt ) = "/Raid"; # where to mount the raid device my ( $RaidDev ) = "/dev/md0" ; my ( $RaidLvl ) = 0; # Raid level # # my ( $Sys ) = 0 ; # Show the system config my ( $Send ) = 0; # Send the result raid benchmark tests # my ( $Doit ) = 0; # Do NOT run the destructive raid tests, unless -doit is specified # # # Test Parameters # my ( $Chunk ) = "2 4 8 16 32 64 128" ; my ( $Block ) = "512 1024 2048 4096"; my ( $Str ) = 0; # blk/chk # # # log and continue on errors ?? # optionally send email of test run to "raid central benchmark repository" ? # # # Check the command line args # &chk_args ; # # # Show usage # ---------- # &usage; # # # Verify the System before beginning ( assumes that raid was able to at least boot before ) # ---------------------------------- # &system_check ; # # # Run some Raid comparson tests # ----------------------------- # for $Chk ( split ( / /, $Chunk ) ) { # # Change the chunk size - raid5 config file # ----------------------------------------- # ( extract raid device name from the config file ) # # &pr_msg ( "\n" ); &pr_msg ( "============================" ); &pr_msg ( "Testing ChunkSize=$Chk.." ); &pr_msg ( "============================" ); # &do_cmd ( " sed -e s/CHUNK/$Chk < $RaidTemplate > $RaidTabConf " ) ; # &do_cmd ( " raidstop $RaidDev " ) ; &do_cmd ( " mkraid -c $RaidTabConf --really-force $RaidDev " ) ; # ??? raidstart ??? # # for $Blk ( split ( / /, $Block ) ) { # # Change the block size and Format the raid array # ----------------------------------------------- # # why is it a *formula* ??? # $Str = $Blk/$Chk ; # &pr_msg ( "\nTesting BlockSize=$Blk.." ); &do_cmd ( " mke2fs -b $Blk -m 1 -R stride=$Str $RaidDev " ); # # &do_cmd ( " mount $RaidDev $RaidMnt" ); # # Run Bonnie tests # ---------------- # # AM GUESSING...bout bonnie syntax # &do_cmd ( " bonnie -s 512 -m 'raid${RaidLvl},$Blk' -d /zh " ); # # # Do a diff of some Huge files # ---------------------------- # &do_cmd ( " time dd if=/dev/null of=$RaidMnt/test1 count=40" ); # 00000 "); &do_cmd ( " time dd if=/dev/null of=$RaidMnt/test2 count=40" ); # 00000 "); &do_cmd ( " time dd if=/dev/null of=$RaidMnt/test3 bs=$Blk count=40" ); # 00000 "); &do_cmd ( " diff $RaidMnt/test1 $RaidMnt/test2 " ); &do_cmd ( " umount $RaidMnt" ); # } # Run block-size tests # } # Run chunk-size tests # # &pr_msg ( "\n-------------------------------------------------------------" ); # # Show usage # &usage; # # All done, where is the results # &pr_msg ( "--->>> Please see the raid test results: $LOG" ); &pr_msg ( "--->>> ================================\n" ); # exit 0; # done # # #=============================================================================== # # Subfunctions # #=============================================================================== # # usage options # sub usage { # &pr_msg ( "\n" ); &pr_msg ( "$NM [ options ] User defined options" ); &pr_msg ( "" ); &pr_msg ( "\t\t-h This Help file" ); &pr_msg ( "\t\t-sys Show the system configuration \n" ); &pr_msg ( "\t\t\t\t\t============" ); &pr_msg ( "\t\t-doit Run the DESTRUCTIVE raid tests" ); &pr_msg ( "\t\t\t\t\t============" ); &pr_msg ( "\t\t-TestFile N HugeTestFileSize is N" ); &pr_msg ( "\t\t-Blk ' i j k ' Only test these BlockSize=i,j,k tests" ); &pr_msg ( "\t\t-Chk ' l m n ' Only test these ChunkSize=l,m,n tests" ); &pr_msg ( "\n" ); &pr_msg ( "\t\t-send Send an email to Raid_Benchmark\@Linux-Consulting.com ??? \n" ); &pr_msg ( "\t\t\t\tYou can view/compare the incoming benchmark results: www.Linux-Consulting.com/Raid/Benchmarks ???" ); &pr_msg ( "\n" ); # &pr_msg ( "--->>> Checking/Checked BlockSize: -Blk ' $Block '" ); &pr_msg ( "--->>> Checking/Checked ChunkSize: -Chk ' $Chunk '" ); &pr_msg ( "\n" ); # } # usage # # # Check command line args # ----------------------- # sub chk_args { # my ( $arg ) = ""; my ( $id ) = 0; # while ( $id <= $#ARGV ) { # $arg = $ARGV[$id]; # $Args .= $arg . " " ; # Keep a List of Args # if ( $arg eq "-h" ) { &usage ; exit 0; # } elsif ( $arg eq "-doit" ) { $Doit = 1 ; # } elsif ( $arg eq "-sys" ) { $Sys = 1 ; # } elsif ( $arg eq "-Mnt" ) { $id += 1; $RaidMnt = $ARGV[$id] ; # use this mountpoint: mount /dev/md0 /RaidMnt $Args .= "$RaidMnt " ; # Keep a List of Args # } elsif ( $arg eq "-Blk" ) { $id += 1; $Block = "$ARGV[$id]" ; # BlockSize $Args .= "' $Block ' "; # Keep a List of Args # } elsif ( $arg eq "-Chk" ) { $id += 1; $Chunk = $ARGV[$id]; # ChunkSize $Args .= " '$Chunk' "; # Keep a List of Args # } # $id += 1; # } # args # return ( 0 ); # } # cmd_args # # # # Echo message to screen and to log file # -------------------------------------- # sub pr_msg { # my ( $msg ) = @_[0]; # printf "$msg\n" ; # printf Flog "$msg\n"; # } # pr_msg # # # # ---------------------------------------------===========----------- # Verify the system before proceeding with the destructive raid tests # ---------------------------------------------===========----------- # sub system_check { # my ( $id ) = 0; my ( $jd ) = 0; my ( @devices ) = ""; my ( @parm ) = ""; my ( $scsi ) = 0; # # # Create a log file # open ( Flog, "> $LOG" ); # &pr_msg ( "" ); &pr_msg ( " $NM : $Date" ); &pr_msg ( " $NM $Args" ); &pr_msg ( "" ); # # cat /proc/mdstat # umount $RaidMnt # # Create a RaidTemplate file I can change the chunk size # ------------------------------------------------------ # if ( ! -f $RaidTab ) { &pr_msg ( " $NM : Missing Raid config file : $RaidTab \n" ); exit 1 ; # Don't bother to continue } # # if ( ! -f $RaidTemplate ) { # &pr_msg ( " $NM : Found existing Raid template file : $RaidTemplate \n" ); # exit 1 ; # Don't overwrite it just in case - somebody wants it # } # # Create the Raid Template file # ----------------------------- # open ( FRD, "< $RaidTab" ); open ( FWR, "> $RaidTemplate" ); # don't bother checking for write errors # printf FWR "#\n"; printf FWR "# $NM : $Date..\n"; printf FWR "#\n"; printf FWR "# This temporary raid config file created by $NM from $RaidTab ..\n"; printf FWR "# ---------------------------------------------------------------------------\n"; printf FWR "#\n"; # while ( ) { # if ( s/chunk-size/chunk-size/i ) { # printf FWR "#\n"; printf FWR "# This chunksize is changed by $NM to test its effects\n"; printf FWR "chunk-size CHUNK\n"; printf FWR "# xx$_"; printf FWR "#\n"; } else { printf FWR "$_"; # keep the same data } } # printf FWR "#\n"; printf FWR "# End of this temporary raid config file created by $NM from $RaidTab ..\n"; printf FWR "#\n"; # close ( FRD ); close ( FWR ); # # # $level = `grep -i raid-level $RaidTab `; ( $key, $RaidLvl ) = split ( /\s+/, $level ); # Extract Raid leve # # # Now Check the Devices in the Raid array # --------------------------------------- # @devices = `grep -i device $RaidTab `; # $id = 0; while ( $id <= $#devices ) { # ( $key, $dev ) = split ( /\s+/, $devices[$id] ); # device /dev/hda1 # chop ( $dev ) ; # chop of trailing partition number # # # IDE drives or SCSI drives # $foo = $dev; if ( $foo =~ s/hd// ) { @parm = `hdparm -i $dev `; # ide } else { @parm = `cat /proc/scsi/scsi `; # SCSI drives -- UNtested $scsi = 1; } # $jd = 0; while ( $jd <= $#parm ) { printf Flog "$parm[$jd]"; $jd += 1; } # param # $id += 1; $id = 9999 if ( $scsi == 1 ); # } # each device # # } # system_check # # # Show what commands will be running # ----------------------------------- # sub do_cmd { # my ( $cmd ) = @_[0]; # &pr_msg ( "$cmd" ); # # Need to close it before we can append the command results to it # close ( Flog ) ; # ` $cmd 2>> $LOG ` if ( $Doit == 1 ); # open ( Flog, ">> $LOG" ); printf Flog "\n"; # } # do_cmd # # # end of file