5 $ENV{PATH}="/bin:/usr/bin";
8 use POSIX ":sys_wait_h";
17 # Don't try to run more than this many threads concurrently.
20 # Initialize variables
22 my $use_mcreate = 1; # should we use mcreate or open?
23 my $num_files = 5; # number of files to create
29 # Get options from the command line.
30 GetOptions("silent!" => \$silent,
31 "use_mcreate=i" => \$use_mcreate,
32 "num_files=i" => \$num_files,
33 "mountpt=s" => \$mountpt,
34 "num_mounts=i" => \$num_mounts,
35 "iterations=i" => \$iterations,
36 "num_threads=i" => \$num_threads,
39 # Check for mandatory args.
45 if ($num_threads > $MAX_THREADS) {
46 print "\nMAX_THREADS is currently set to $MAX_THREADS.\n\n";
47 print "You will have to change this in the source\n";
48 print "if you really want to run with $num_threads threads.\n\n";
52 # Initialize rand() function.
53 srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
55 #########################################################################
58 for (my $i=1; $i<=$num_threads; $i++) {
59 my $status = &fork_and_create($i);
60 last if ($status != 0);
63 # Wait for all our threads to finish.
66 $child = waitpid(-1, WNOHANG);
72 #########################################################################
76 print "\nUsage: $0 [--silent] [--use_mcreate=n] [--num_files=n] [--iterations=n] [--num_threads=n] --mountpt=/path/to/lustre/mount --num_mounts=n\n\n";
77 print "\t--silent\tminimal output\n";
78 print "\t--use_mcreate=n\tuse mcreate to create files, default=1 (yes)\n";
79 print "\t--num_files=n\tnumber of files to create per iteration, default=5\n";
80 print "\t--iterations=n\tnumber of iterations to perform, default=1\n";
81 print "\t--num_threads=n\tnumber of thread to run, default=1\n";
82 print "\t--mountpt\tlocation of lustre mount\n";
83 print "\t--num_mounts=n\tnumber of lustre mounts to test across, default=-1 (single mount point without numeric suffix)\n\n";
84 print "example: $0 --mountpt=/mnt/lustre --num_mounts=2 --iterations=50\n";
85 print " will perform 50 interations in /mnt/lustre1 and /mnt/lustre2\n";
86 print " $0 --mountpt=/mnt/lustre --num_mounts=-1 --iterations=50\n";
87 print " will perform 50 iterations in /mnt/lustre only\n\n";
91 #########################################################################
92 sub fork_and_create ($) {
93 my ($thread_num) = @_;
98 # child process pid is available in $pid
100 } elsif (defined $pid) { # $pid is zero here if defined
101 my $current_iteration=1;
102 while ($current_iteration <= $iterations) {
103 for (my $i=1; $i<=$num_files; $i++) {
105 if ($num_mounts > 0) {
106 $which = int(rand() * $num_mounts) + 1;
108 my $d = int(rand() * $num_files);
109 do_open("${mountpt}${which}/thread${thread_num}.${d}");
111 if ($num_mounts > 0) {
112 $which = int(rand() * $num_mounts) + 1;
114 $d = int(rand() * $num_files);
115 my $path = "${mountpt}${which}/thread${thread_num}.${d}";
116 print "Thread $thread_num: Unlink $path start [" . $$."]...\n" if !$silent;
118 print "Thread $thread_num: Unlink done [$$] $path: Success\n" if !$silent;
120 print "Thread $thread_num: Unlink done [$$] $path: $!\n"if !$silent;
123 if (($current_iteration) % 100 == 0) {
124 print STDERR "Thread $thread_num: " . $current_iteration . " operations [" . $$ . "]\n";
126 $current_iteration++;
130 if ($num_mounts > 0) {
131 $which = int(rand() * $num_mounts) + 1;
133 for (my $d = 0; $d < $num_files; $d++) {
134 my $path = "${mountpt}${which}/thread${thread_num}.${d}";
135 unlink("$path") if (-e $path);
138 print "Thread $thread_num: Done.\n";
142 } elsif ($! =~ /No more process/) {
143 # EAGAIN, supposedly recoverable fork error
148 die "Can't fork: $!\n";
154 #########################################################################
160 my $tmp = `./mcreate $path`;
162 print "Creating $path [" . $$."]...\n" if !$silent;
163 $tmp =~ /.*error: (.*)\n/;
164 print "Create done [$$] $path: $!\n" if !$silent;
166 print "Create done [$$] $path: Success\n"if !$silent;
169 print "Opening $path [" . $$."]...\n"if !$silent;
170 open(FH, ">$path") || die "open($path: $!";
171 print "Open done [$$] $path: Success\n"if !$silent;