From 7f36c6eeb1d7ac466db83fc65a8384da5fbb1de1 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 12 Jun 2013 17:28:45 -0400 Subject: [PATCH] SIPHUP reloads max/min children, etc. settings (Perl) When a Perl listener processes receives a SIGHUP signal, we now reload the following additional configuration values from the opensrf.xml file: keepalive max_requests max_children min_children min_spare_children max_spare_children Signed-off-by: Bill Erickson --- src/perl/lib/OpenSRF/Server.pm | 40 +++++++++++++++++++++++++++++++++++++--- src/perl/lib/OpenSRF/System.pm | 8 +------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/perl/lib/OpenSRF/Server.pm b/src/perl/lib/OpenSRF/Server.pm index d8103b6..04eb7f2 100644 --- a/src/perl/lib/OpenSRF/Server.pm +++ b/src/perl/lib/OpenSRF/Server.pm @@ -50,15 +50,46 @@ sub new { $self->{stderr_log} = $self->{stderr_log_path} . "/${service}_stderr.log" if $self->{stderr_log_path}; - $self->{min_spare_children} ||= 0; + $self->load_max_min_settings; + + return $self; +} + +# ---------------------------------------------------------------- +# Load child process management settings directly from the +# settings server client. If $refresh, then kill the cached +# settings file and fetch the updated file. +# ---------------------------------------------------------------- +sub load_max_min_settings { + my ($self, $refresh) = @_; + + my $sclient = OpenSRF::Utils::SettingsClient->new; + $sclient->set_cache(0) if $refresh; + + my $getval = sub { + $sclient->config_value(apps => $self->{service} => @_); + }; + + $self->{keepalive} = $getval->('keepalive') || 5; + + # avoid re-fetching the settings file on each additional setting + $sclient->set_cache(1) if $refresh; + + $self->{max_requests} = $getval->(unix_config => 'max_requests') || 10000; + $self->{max_children} = $getval->(unix_config => 'max_children') || 20; + $self->{min_children} = $getval->(unix_config => 'min_children') || 1; + + $self->{min_spare_children} = + $getval->(unix_config => 'min_spare_children') || 0; + $self->{max_spare_children} = + $getval->(unix_config => 'max_spare_children'); $self->{max_spare_children} = $self->{min_spare_children} + 1 if $self->{max_spare_children} and $self->{max_spare_children} <= $self->{min_spare_children}; - - return $self; } + # ---------------------------------------------------------------- # Disconnects from routers and waits for child processes to exit. # ---------------------------------------------------------------- @@ -106,6 +137,9 @@ sub handle_sighup { # force-reload the logger config OpenSRF::Utils::Logger::set_config(1); + # update max/min children settings + $self->load_max_min_settings(1); + # copy active list into pending list for later cleanup $self->{sighup_pending} = [ @{$self->{active_list}} ]; diff --git a/src/perl/lib/OpenSRF/System.pm b/src/perl/lib/OpenSRF/System.pm index 7eb7120..a81481c 100644 --- a/src/perl/lib/OpenSRF/System.pm +++ b/src/perl/lib/OpenSRF/System.pm @@ -100,13 +100,7 @@ sub run_service { my $stderr_path = ($disable_stderr =~ /true/i) ? undef : $sclient->config_value(dirs => 'log'); my $server = OpenSRF::Server->new( - $service, - keepalive => $getval->('keepalive') || 5, - max_requests => $getval->(unix_config => 'max_requests') || 10000, - max_children => $getval->(unix_config => 'max_children') || 20, - min_children => $getval->(unix_config => 'min_children') || 1, - min_spare_children => $getval->(unix_config => 'min_spare_children'), - max_spare_children => $getval->(unix_config => 'max_spare_children'), + $service, stderr_log_path => $stderr_path ); -- 2.11.0