2 # This script is to be run on a client machine and will test all the
3 # OSTs to determine which is the fastest and slowest
4 # The current test method is as follows:
5 # -Create a directory for each OST
6 # -Use 'lfs setstripe' to set the Lustre striping such that IO goes to
8 # -Use 'dd' to write and read a file of a specified size
9 # -Compute the average, and Standard deviation
10 # -Find the slowest OST for read and write
11 # -Find the Fastest OST for read and write
14 $pname = $0; # to hold program name
15 $OSTS = 0; # Number of OSTS we will loop over
16 $BSIZE = 1024 * 1024; # Size of i/o block
17 $MBSIZE = 1024 * 1024; # One MB
18 $MNT = "/mnt/lustre"; # Location of Lustre file system
19 $CACHESZ = 0; # max_cached_mb parameter
20 $FSIZE = 30; # Number of i/o blocks
24 print "Usage: $pname [-s <size>] [-h] <Lustre_Path>\n";
26 print " -s: size of test file in MB (default $FSIZE MB)\n";
27 print " -h: To display this help\n";
28 print "example : $pname /mnt/lustre\n";
32 # ost_count subroutine sets global variable $OST with number of OSTs
33 # Also fills 1 for active OST indexes in ACTIVEOST_INX array.
35 $OSTS = `lctl get_param -n lov.$FSNAME-clilov-*.activeobd`;
37 die "Read lov.*-clilov-$FSNAME.activeobd error: $?\n";
39 print "Number of Active OST devices : $OSTS";
41 $numost = `lctl get_param -n lov.$FSNAME-clilov-*.numobd`;
43 die "Read lov.$FSNAME-clilov-*.numobd error: $?\n";
46 if ( $numost != $OSTS ) {
47 printf "Number of non active ots(s): %d\n", ( $numost - $OSTS );
51 $targets = `lctl get_param -n lov.$FSNAME-clilov-*.target_obd`;
53 die "Read lov.$FSNAME-clilov-*.target_obd error: $?\n";
57 foreach $line (split /\n/, $targets) {
58 my ($ost_num, $ost_name, $ost_status) = split(/\s+/, $line);
59 if ( $ost_status eq "ACTIVE" ) {
60 $ACTIVEOST_INX[$count] = 1;
66 # cache_mod subroutine sets global variable $CACHESZ and sets max_cached_mb
67 # to 256 * system page size in MB.
69 use POSIX qw(sysconf _SC_PAGESIZE);
70 $CACHESZ = `lctl get_param -n llite.$FSNAME-*.max_cached_mb`;
72 die "Read llite.$FSNAME-*.max_cached_mb error: $?\n";
75 $CACHESZ = `echo "$CACHESZ" | grep max_cached_mb | awk '{print \$2}'`;
76 my $pagesize = sysconf(_SC_PAGESIZE);
77 $req_cache_mb = ($pagesize * 256)/ $MBSIZE;
79 system("lctl set_param -n llite.$FSNAME-*.max_cached_mb=$req_cache_mb");
81 die "Set llite.$FSNAME-*.max_cached_mb error: $?\n";
85 # cache_return subroutine returns max_cached_mb to original value
87 system("lctl set_param -n llite.$FSNAME-*.max_cached_mb=$CACHESZ");
90 # make_dummy subroutine creates a dummy file that will be used for read operation.
94 system ("dd of=$tempfile if=/dev/zero count=$SIZE bs=$BSIZE 2> /dev/null");
97 # run_test subroutine actually writes and reads data to/from dummy file
98 # and computes corresponding time taken for read and write operation and
99 # byte transfer for the both operations.
100 # This subroutine also fill corresponding global arrays with above information.
105 my $tempfile = $_[3];
107 if ( !(-f $tempfile) && $ACTION eq "read" ) {
108 &make_dummy($SIZE, $tempfile);
111 my ($ts0, $tu0) = gettimeofday();
112 $tu0 = $ts0 + ($tu0 / 1000000);
113 if ( $ACTION eq "write" ) {
114 system("dd of=$tempfile if=/dev/zero count=$SIZE bs=$BSIZE 2> /dev/null");
115 } elsif ( $ACTION eq "read" ) {
116 system("dd if=$tempfile of=/dev/null count=$SIZE bs=$BSIZE 2> /dev/null");
118 print "Action is neither read nor write\n";
122 my ($ts1, $tu1) = gettimeofday();
123 $tu1 = $ts1 + ($tu1/1000000);
124 my $tdelta = $tu1 - $tu0;
125 my $delta = ($SIZE * $BSIZE / ( $tu1 - $tu0 )) / (1024 * 1024);
126 if ( $ACTION eq "write" ) {
127 $wTime[$INX] = $tdelta;
128 $wMBs[$INX] = $delta;
130 $rTime[$INX] = $tdelta;
131 $rMBs[$INX] = $delta;
135 # calculate subroutine compute following things and displays them.
136 # - Finds worst and best OST for both read and write operations.
137 # - Compute average of read and write rate from all OSTS
138 # - Compute Standard deviation for read and write form all OST's
150 my $min_mb = 999999999;
151 while ($count < $OSTS ) {
152 if ( $ACTIVEOST_INX[$count] ) {
153 $total = $total + $MBs[$count];
154 if ($max_mb < $MBs[$count] ) {
155 $max_mb = $MBs[$count];
158 if ($min_mb > $MBs[$count] ) {
159 $min_mb = $MBs[$count];
168 while ($count < $OSTS ) {
169 if ( $ACTIVEOST_INX[$count] ) {
170 $total = $total + ($MBs[$count] - $avg) * ($MBs[$count] - $avg);
174 $sd = sqrt($total/$OSTS);
175 printf "Worst %s OST indx: %d speed: %f\n", $op, $worst_OST, $min_mb;
176 printf "Best %s OST indx: %d speed: %f\n", $op, $best_OST, $max_mb;
177 printf "%s Average: %f +/- %f MB/s\n", $op, $avg, $sd;
180 # output_all_data subroutine displays speed and time information
181 # for all OST's for both read and write operations.
182 sub output_all_data () {
184 print "Ost# Read(MB/s) Write(MB/s) Read-time Write-time\n";
185 print "----------------------------------------------------\n";
186 while ( $count < $OSTS ) {
187 if ( $ACTIVEOST_INX[$count] ) {
188 printf "%d %.3f %.3f %.3f %.3f\n",$count,
189 $rMBs[$count], $wMBs[$count], $rTime[$count], $wTime[$count];
191 printf "%d Inactive ost\n",$count;
208 # Check number of arguments
209 my $numargs = $#ARGV + 1;
210 usage() if $numargs < 1;
212 # Command line parameter parsing
214 getopts('s:h') or usage();
216 $FSIZE = $opt_s if $opt_s;
223 print "ERROR: extra argument $_\n";
227 #Check for Time::HiRes module
228 my $CheckTimeHiRes = "require Time::HiRes";
229 eval ($CheckTimeHiRes) or die "You need to install the perl-Time-HiRes package to use this script\n";
230 my $LoadTimeHiRes = "use Time::HiRes qw(gettimeofday)";
231 eval ($LoadTimeHiRes);
233 use POSIX qw(strftime);
235 my $hostname = `lctl list_nids | head -1` or die "You need to install lctl to use this script\n";
237 print "$pname: ", strftime("%D", localtime($time_v));
238 print " OST speed survey on $MNT from $hostname\n";
240 # Get the file system name.
241 $FSNAME = `lfs getname $MNT`;
243 die "`lfs getname $MNT` error: $?\n";
253 $dirpath = "$MNT/ost_survey_tmp";
254 eval { mkpath($dirpath) };
256 print "Couldn't create $dirpath: $@";
262 while ($CNT < $OSTS) {
263 $filename = "$dirpath/file$CNT";
264 if ( $ACTIVEOST_INX[$CNT] ) {
265 # set stripe for OST number $CNT
266 system ("lfs setstripe -S 0 -i $CNT -c 1 $filename");
267 # Perform write for OST number $CNT
268 &run_test($FSIZE,$CNT,"write",$filename);
274 while ($CNT < $OSTS) {
275 $filename = "$dirpath/file$CNT";
276 if ( $ACTIVEOST_INX[$CNT] ) {
277 # Perform read for OST number $CNT
278 &run_test($FSIZE,$CNT,"read",$filename);
284 # if read or write performed on any OST then display information.
287 &calculate("Read",@rMBs);
288 &calculate("Write",@wMBs);
292 print "There is no active OST's found\n";
295 # Return cache to original size
298 eval { rmtree($dirpath) };
300 print "Warning: Couldn't remove $dirpath: $@";