diff options
author | jonesc <jonesc@a3e5c962-4219-0410-a828-e124f845ac39> | 2012-01-10 21:26:36 +0000 |
---|---|---|
committer | jonesc <jonesc@a3e5c962-4219-0410-a828-e124f845ac39> | 2012-01-10 21:26:36 +0000 |
commit | 224a0990f2e6db945923f1a42f7ecb0ddb80dbd5 (patch) | |
tree | 8c223340af68083ac9ec4a3aad756aeec72a3517 | |
parent | 91efcf22351b9fde05596285d7f6e411b397af4b (diff) | |
download | MPC-mpc_performance.tar.gz |
Tue Jan 10 21:22:32 UTC 2012 Chip Jones <jonesc@ociweb.com>mpc_performance
* modules/Options.pm:
* modules/WorkspaceCreator.pm:
Added error checks to command line options and
to generate_project_files_fork() subroutine.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | modules/Options.pm | 11 | ||||
-rw-r--r-- | modules/WorkspaceCreator.pm | 56 |
3 files changed, 57 insertions, 18 deletions
@@ -1,3 +1,11 @@ +Tue Jan 10 21:22:32 UTC 2012 Chip Jones <jonesc@ociweb.com> + + * modules/Options.pm: + * modules/WorkspaceCreator.pm: + + Added error checks to command line options and + to generate_project_files_fork() subroutine. + Tue Jan 10 05:10:23 UTC 2012 Chip Jones <jonesc@ociweb.com> * modules/Options.pm: diff --git a/modules/Options.pm b/modules/Options.pm index a9c07e42..5c83821a 100644 --- a/modules/Options.pm +++ b/modules/Options.pm @@ -502,6 +502,13 @@ sub options { if (!defined $workers_dir) { $self->optionError('-workers_dir requires an argument'); } + + if (! -d $workers_dir) { + $self->diagnostic("Creating temp directory $workers_dir"); + unless (mkdir $workers_dir) { + $self->optionError("Unable to create temp directory $workers_dir"); + } + } } elsif ($arg eq '-workers_port') { $i++; @@ -510,6 +517,10 @@ sub options { if (!defined $workers_port) { $self->optionError('-workers_port requires an argument'); } + + if ($workers_port < 0 || $workers_port > 65535) { + $self->optionError('valid -workers_port range is between 0 and 65535'); + } } elsif ($arg eq '-ti') { $i++; diff --git a/modules/WorkspaceCreator.pm b/modules/WorkspaceCreator.pm index 38581f2b..870f2a82 100644 --- a/modules/WorkspaceCreator.pm +++ b/modules/WorkspaceCreator.pm @@ -1783,7 +1783,7 @@ sub send_to_parent { } map { print $sock "$_\n"; } @$arr; - close $sock; + $sock->close(); } sub generate_project_files_fork_socket { @@ -1829,9 +1829,25 @@ sub generate_project_files_fork_socket { my $fin; my $num_prj_files = $#{$self->{'project_files'}} + 1; + + ## reduce the number of workers if necessary + ## what if $num_workers > SOMAXCONN?? (unlikely) + if ($num_workers > SOMAXCONN) { + $self->diagnostic("Multiprocess MPC reducing # workers from $num_workers to " . SOMAXCONN . ", the max # of queued connections"); + $num_workers = SOMAXCONN; + } + + if ($num_workers > $num_prj_files) { + # don't fork more workers than there are jobs + $self->diagnostic("Multiprocess MPC reducing # workers from $num_workers to $num_prj_files, the number of project files."); + $num_workers = $num_prj_files; + } + my $num_per_worker = int ($num_prj_files / $num_workers); my $num_lines_per_prj = 6; + $self->diagnostic("Multiprocess MPC using $num_workers workers to process $num_prj_files project files."); + for (my $wctr = 0; $wctr < $num_workers; ++$wctr) { $beg = $wctr * $num_per_worker; $fin = $beg + $num_per_worker - 1; @@ -1847,36 +1863,36 @@ sub generate_project_files_fork_socket { } + ## Setup listener. Do this before fork so that (in the rare case) + ## when child tries to send data before the accept(), the socket + ## is at least initialized. + my $sock = new IO::Socket::INET ( + LocalHost => 'localhost', + LocalPort => $wport, + Proto => 'tcp', + Listen => $num_workers, + Reuse => 1 + ); + if (!defined ($sock)) { + die "Error setting up parent listener"; + } + ## spawn the workers. my $id = 0; while ($id < $num_workers) { + # use pipes as barrier $pid = fork(); if ($pid != 0) { push @pids, $pid; } else { + ## after fork, child knows its id and which data to use. $self->{'pid'} = 'child'; last; } ++$id; } - ## after fork, child knows its id and know which data to use. if ($self->{pid} eq 'parent') { - ## setup listener - ## what if $num_workers > SOMAXCONN?? (unlikely) - - my $sock = new IO::Socket::INET ( - LocalHost => 'localhost', - LocalPort => $wport, - Proto => 'tcp', - Listen => $num_workers, - Reuse => 1 - ); - if (!defined ($sock)) { - # children should get the signal. - die "Error setting up parent listener"; - } - $self->diagnostic("Multiprocess MPC using port $wport."); # read the data from the kids @@ -1899,8 +1915,12 @@ sub generate_project_files_fork_socket { } } } + # all data has been read + $sock->close(); + } else { - ## This is the child. + ## This is the code the workers run. + undef $sock; ## generate projects my @cdata = ($id); foreach my $ofile (@{$wdata[$id]}) { |