[Opensrf-commits] r2117 - branches/rel_2_0/src/perl/lib/OpenSRF (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Nov 29 15:16:26 EST 2010


Author: erickson
Date: 2010-11-29 15:16:21 -0500 (Mon, 29 Nov 2010)
New Revision: 2117

Modified:
   branches/rel_2_0/src/perl/lib/OpenSRF/Server.pm
Log:
don't clean up child attributes until we're done with them;  added pid map hash for easy/quick access to child via pid

Modified: branches/rel_2_0/src/perl/lib/OpenSRF/Server.pm
===================================================================
--- branches/rel_2_0/src/perl/lib/OpenSRF/Server.pm	2010-11-29 20:15:33 UTC (rev 2116)
+++ branches/rel_2_0/src/perl/lib/OpenSRF/Server.pm	2010-11-29 20:16:21 UTC (rev 2117)
@@ -40,6 +40,7 @@
     $self->{routers}        = []; # list of registered routers
     $self->{active_list}    = []; # list of active children
     $self->{idle_list}      = []; # list of idle children
+    $self->{pid_map}        = {}; # map of child pid to child for cleaner access
 
     $self->{stderr_log} = $self->{stderr_log_path} . "/${service}_stderr.log" 
         if $self->{stderr_log_path};
@@ -161,6 +162,16 @@
 sub perform_idle_maintenance {
     my $self = shift;
 
+    $chatty and $logger->internal(
+        sprintf(
+            "server: %d idle, %d active, %d min_spare, %d max_spare in idle maintenance",
+            scalar(@{$self->{idle_list}}), 
+            scalar(@{$self->{active_list}}),
+            $self->{min_spare_children},
+            $self->{max_spare_children}
+        )
+    );
+
     # spawn 1 spare child per maintenance loop if necessary
     if( $self->{min_spare_children} and
         $self->{num_children} < $self->{max_children} and
@@ -295,15 +306,17 @@
 
         $chatty and $logger->internal("server: reaping child $pid");
 
-        my ($child) = grep {$_->{pid} == $pid} (@{$self->{active_list}}, @{$self->{idle_list}});
+        my $child = $self->{pid_map}->{$pid};
 
         close($child->{pipe_to_parent});
         close($child->{pipe_to_child});
-        delete $child->{$_} for keys %$child; # destroy with a vengeance
 
-        $self->{num_children}--;
         $self->{active_list} = [ grep { $_->{pid} != $pid } @{$self->{active_list}} ];
         $self->{idle_list} = [ grep { $_->{pid} != $pid } @{$self->{idle_list}} ];
+
+        $self->{num_children}--;
+        delete $self->{pid_map}->{$pid};
+        delete $child->{$_} for keys %$child; # destroy with a vengeance
     }
 
     $self->spawn_children unless $shutdown;
@@ -347,8 +360,8 @@
 
     if($child->{pid}) { # parent process
         $self->{num_children}++;
+        $self->{pid_map}->{$child->{pid}} = $child;
 
-
         if($active) {
             push(@{$self->{active_list}}, $child);
         } else {



More information about the opensrf-commits mailing list