5 $ENV{PATH}="/bin:/usr/bin";
8 use POSIX ":sys_wait_h";
18 # Don't try to run more than this many threads concurrently.
21 $SCRIPT_NAME = "create.pl";
23 # Initialize variables
25 my $use_mcreate = 1; # should we use mcreate or open?
26 my $num_files = 5; # number of files to create
32 # Get options from the command line.
33 GetOptions("silent!" => \$silent,
34 "use_mcreate=i" => \$use_mcreate,
35 "num_files=i" => \$num_files,
36 "mountpt=s" => \$mountpt,
37 "num_mounts=i" => \$num_mounts,
38 "iterations=i" => \$iterations,
39 "num_threads=i" => \$num_threads,
42 # Check for mandatory args.
48 if ($num_threads > $MAX_THREADS) {
49 print "\nMAX_THREADS is currently set to $MAX_THREADS.\n\n";
50 print "You will have to change this in the source\n";
51 print "if you really want to run with $num_threads threads.\n\n";
55 # Initialize rand() function.
56 srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
58 #########################################################################
61 for (my $i=1; $i<=$num_threads; $i++) {
62 my $status = &fork_and_create($i);
63 last if ($status != 0);
66 # Wait for all our threads to finish.
69 $child = waitpid(-1, WNOHANG);
75 #########################################################################
79 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";
80 print "\t--silent\tminimal output\n";
81 print "\t--use_mcreate=n\tuse mcreate to create files, default=1 (yes)\n";
82 print "\t--num_files=n\tnumber of files to create per iteration, default=5\n";
83 print "\t--iterations=n\tnumber of iterations to perform, default=1\n";
84 print "\t--num_threads=n\tnumber of thread to run, default=1\n";
85 print "\t--mountpt\tlocation of lustre mount\n";
86 print "\t--num_mounts=n\tnumber of lustre mounts to test across, default=-1 (single mount point without numeric suffix)\n\n";
87 print "example: $0 --mountpt=/mnt/lustre --num_mounts=2 --iterations=50\n";
88 print " will perform 50 iterations in /mnt/lustre1 and /mnt/lustre2\n";
89 print " $0 --mountpt=/mnt/lustre --num_mounts=-1 --iterations=50\n";
90 print " will perform 50 iterations in /mnt/lustre only\n\n";
94 #########################################################################
95 sub fork_and_create ($) {
96 my ($thread_num) = @_;
101 # child process pid is available in $pid
103 } elsif (defined $pid) { # $pid is zero here if defined
104 my $current_iteration=1;
105 while ($current_iteration <= $iterations) {
106 for (my $i=1; $i<=$num_files; $i++) {
108 if ($num_mounts > 0) {
109 $which = int(rand() * $num_mounts) + 1;
111 my $d = int(rand() * $num_files);
112 do_open("${mountpt}${which}/thread${thread_num}.${d}");
114 if ($num_mounts > 0) {
115 $which = int(rand() * $num_mounts) + 1;
117 $d = int(rand() * $num_files);
118 my $path = "${mountpt}${which}/thread${thread_num}.${d}";
119 print "$SCRIPT_NAME - Thread $thread_num: Unlink $path start [" . $$."]...\n" if !$silent;
121 print "$SCRIPT_NAME - Thread $thread_num: Unlink done [$$] $path: Success\n" if !$silent;
123 print "$SCRIPT_NAME - Thread $thread_num: Unlink done [$$] $path: $!\n"if !$silent;
126 if (($current_iteration) % 100 == 0) {
127 print "$SCRIPT_NAME - Thread $thread_num: " . $current_iteration . " operations [" . $$ . "]\n";
129 $current_iteration++;
133 if ($num_mounts > 0) {
134 $which = int(rand() * $num_mounts) + 1;
136 for (my $d = 0; $d < $num_files; $d++) {
137 my $path = "${mountpt}${which}/thread${thread_num}.${d}";
138 unlink("$path") if (-e $path);
141 print "$SCRIPT_NAME - Thread $thread_num: Done.\n";
145 } elsif ($! =~ /No more process/) {
146 # EAGAIN, supposedly recoverable fork error
151 die "Can't fork: $!\n";
157 #########################################################################
163 my $tmp = `./mcreate $path`;
165 print "$SCRIPT_NAME - Creating $path [" . $$."]...\n" if !$silent;
166 $tmp =~ /.*error: (.*)\n/;
167 print "$SCRIPT_NAME - Create done [$$] $path: $!\n" if !$silent;
169 print "$SCRIPT_NAME - Create done [$$] $path: Success\n"if !$silent;
172 print "$SCRIPT_NAME - Opening $path [" . $$."]...\n"if !$silent;
173 open(FH, ">$path") || die "open($path: $!";
174 print "$SCRIPT_NAME - Open done [$$] $path: Success\n"if !$silent;