Subject: | Add an option to vary PM_MAX_REQUESTS value |
Hello,
I've made a patch to add an option to vary PM_MAX_REQUESTS value between workers.
Under some conditions, where PM_MAX_REQUESTS and each request is relatively small, all workers reach the limit and exit suddenly. To prevent this issue PM_MAX_REQUESTS_VAR environment variable is added.
See the attached patch.
Please let me know if it needs any changes.
Thanks.
Subject: | pm-max-requests-var.patch |
From 51ecd9be66f3224cb0ea17cd6ed2481d35ec7407 Mon Sep 17 00:00:00 2001
From: Haruka Iwao <haruka@fout.jp>
Date: Thu, 14 Nov 2013 14:36:27 +0900
Subject: [PATCH 1/2] MaxRequests.pm: Add PM_MAX_REQUESTS_VAR variable to randomize counter
When set, PM_MAX_REQUESTS + random[0..PM_MAX_REQUESTS_VAR) is set to request_counter to prevent all processeS to shut down at once.
---
lib/FCGI/ProcManager/MaxRequests.pm | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/lib/FCGI/ProcManager/MaxRequests.pm b/lib/FCGI/ProcManager/MaxRequests.pm
index 84644e1..f89367c 100644
--- a/lib/FCGI/ProcManager/MaxRequests.pm
+++ b/lib/FCGI/ProcManager/MaxRequests.pm
@@ -9,6 +9,7 @@ sub new {
my $proto = shift;
my $self = $proto->SUPER::new(@_);
$self->{max_requests} = $ENV{PM_MAX_REQUESTS} || 0 unless defined $self->{max_requests};
+ $self->{max_requests_var} = $ENV{PM_MAX_REQUESTS_VAR} || 0 unless defined $self->{max_requests_var};
return $self;
}
@@ -18,6 +19,10 @@ sub handling_init {
my $self = shift;
$self->SUPER::handling_init();
$self->{_request_counter} = $self->max_requests;
+ if($self->{max_requests_var}) {
+ $self->{_request_counter} += (time ^ ($$ + ($$ << 15))) % $self->{max_requests_var};
+ }
+ $self->pm_info("Max request counter set to $self->{_request_counter}.");
}
sub pm_post_dispatch {
--
1.7.1
From a6bfadc486dd800bad66d481c5a67dde126f6cad Mon Sep 17 00:00:00 2001
From: Haruka Iwao <haruka@fout.jp>
Date: Fri, 22 Nov 2013 18:34:14 +0900
Subject: [PATCH 2/2] MaxRequests.pm: Add a note about PM_MAX_REQUESTS_VAR
---
lib/FCGI/ProcManager/MaxRequests.pm | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/lib/FCGI/ProcManager/MaxRequests.pm b/lib/FCGI/ProcManager/MaxRequests.pm
index f89367c..5d4e22d 100644
--- a/lib/FCGI/ProcManager/MaxRequests.pm
+++ b/lib/FCGI/ProcManager/MaxRequests.pm
@@ -67,6 +67,11 @@ number of requests, it simple exit, and manager starts another server process.
Maximum number of requests can be set from PM_MAX_REQUESTS environment variable,
max_requests - constructor argument and max_requests accessor.
+When PM_MAX_REQUESTS is relatively small and processing times of requests varies little,
+all of worker processes reach the limit and exit suddenly. To prevent this issue,
+you can use PM_MAX_REQUESTS_VAR environment variable so that each worker randomly
+chooses a value between [PM_MAX_REQUESTS, PM_MAX_REQUESTS + PM_MAX_REQUESTS_VAR).
+
=head1 OVERLOADED METHODS
=head2 new