Mitigate memleaks in fastcgi server (#1314)

This commit is contained in:
Maxime Besson 2020-02-12 13:20:08 +01:00
parent 683df5425a
commit 2b3413d1ab
2 changed files with 22 additions and 27 deletions

View File

@ -21,3 +21,14 @@ GROUP=__GROUP__
#ENGINE=FCGI::EV
#ENGINE=FCGI::Engine
#ENGINE=FCGI::Engine::ProcManager
# Process recycling
# When running with Perl 5.16, you might encounter memory
# leaks when running the FastCGI server
# By default, we restart each worker after 500 requests to mitigate
# the leak. You can finetune these settings here.
# See also FCGI::ProcManager::Constrained(3)
PM_MAX_REQUESTS=500
#PM_SIZECHECK_NUM_REQUESTS=10
#PM_MAX_SIZE=100000

View File

@ -10,9 +10,9 @@ use Lemonldap::NG::Handler::Main::Reload;
our $VERSION = '2.0.0';
our (
$foreground, $engine, $nproc, $pidFile,
$socket, $user, $listen, $group,
$customFunctionsFile, %plackOptions
$foreground, $engine, $nproc, $pidFile,
$socket, $user, $listen, $group,
$procmanager, $customFunctionsFile, %plackOptions
);
my %_apps;
@ -29,6 +29,9 @@ $user ||= $ENV{USER};
$group ||= $ENV{GROUP};
$customFunctionsFile ||= $ENV{CUSTOM_FUNCTIONS_FILE};
# If the user specified any PM_ constrains, run under ::Constrained
$procmanager = "FCGI::ProcManager::Constrained" if grep /^PM_/, keys %ENV;
#Getopt::Long::Configure ("bundling_values");
GetOptions(
'foreground' => \$foreground,
@ -93,7 +96,7 @@ my %builder = (
die "Unable to load $_[0]->{SCRIPT_FILENAME}";
}
return $_apps{$script}->(@_);
}
}
},
);
@ -126,6 +129,7 @@ $server->parse_options(
'--proc-title' => 'llng-fastcgi-server',
( $foreground ? () : '--daemonize' ),
'--no-default-middleware',
( $procmanager ? ( '--manager', $procmanager ) : () ),
%plackOptions,
);
@ -216,14 +220,10 @@ Plack::Handler engine, default to FCGI (see below)
=item --plackOptions:
other options to pass to Plack. This multi-valued parameter must have
"key=value" values.
other options to pass to the Plack handler. This multi-valued parameter must
have "key=value" values.
Example to use L<FCGI::ProcManager::Constrained> instead of default FCGI manager
(L<FCGI::ProcManager>):
llng-fastcgi-server -u nobody -g nobody -s /run/llng.sock -e FCGI -n 10 \
--plackOptions manager=FCGI::ProcManager::Constrained
See Plack::Handler::FCGI for a list of options for the default FCGI engine
=back
@ -236,22 +236,6 @@ other engines can be used:
It uses L<FCGI::ProcManager> as manager. Other managers:
=over
=item L<FCGI::ProcManager::Constrained>
Example to launch it:
llng-fastcgi-server -u nobody -g nobody -s /run/llng.sock -e FCGI -n 10 \
--plackOptions manager=FCGI::ProcManager::Constrained
You can then set environment values (in /etc/default/llng-fastcgi-server file
for example):
PM_MAX_REQUESTS=10000
PM_SIZECHECK_NUM_REQUESTS=100
PM_MAX_SIZE=300000
=item L<FCGI::ProcManager::Dynamic>
llng-fastcgi-server -u nobody -g nobody -s /run/llng.sock -e FCGI -n 10 \