FU: Add randomized --max-reqs option

This commit is contained in:
Yorhel 2025-02-26 11:28:19 +01:00
parent 29dd09e809
commit 8dca0a22a9

16
FU.pm
View file

@ -507,7 +507,7 @@ sub _spawn {
$c{proc} = $1 if /^--proc=([0-9]+)$/; $c{proc} = $1 if /^--proc=([0-9]+)$/;
$c{monitor} = 1 if /^--monitor$/; $c{monitor} = 1 if /^--monitor$/;
$c{monitor} = 0 if /^--no-monitor$/; $c{monitor} = 0 if /^--no-monitor$/;
$c{max_reqs} = $1 if /^--max-reqs=([0-9]+)$/; $c{max_reqs} = $1 if /^--max-reqs=([0-9]+(?::[0-9]+)?)$/;
debug 1 if /^--debug$/; debug 1 if /^--debug$/;
debug 0 if /^--no-debug$/; debug 0 if /^--no-debug$/;
$ENV{FU_LOG_FILE} = $1 if /^--log-file=(.+)$/; $ENV{FU_LOG_FILE} = $1 if /^--log-file=(.+)$/;
@ -553,6 +553,7 @@ sub _spawn {
_supervisor \%c; _supervisor \%c;
} else { } else {
$c{supervisor_sock}->syswrite('r'.pack 'V', $$) if $c{supervisor_sock}; $c{supervisor_sock}->syswrite('r'.pack 'V', $$) if $c{supervisor_sock};
$c{max_reqs} = $1 >= $2 ? $1 : $1 + int rand $2-$1 if $c{max_reqs} =~ /^([0-9]+):([0-9]+)$/;
_run_loop \%c; _run_loop \%c;
} }
} }
@ -1387,12 +1388,19 @@ significant cost in performance - better not enable this in production.
=item FU_MAX_REQS=n =item FU_MAX_REQS=n
=item FU_MAX_REQS=min:max
=item --max-reqs=n =item --max-reqs=n
=item --max-reqs=min:max
Worker processes can automatically restart after handling a number of requests. Worker processes can automatically restart after handling a number of requests.
Set to 0 (the default) to disable this feature. This option can be useful when Set to 0 (the default) to disable this feature. When set as C<min:max>, the
your worker processes keep accumulating memory over time. A little pruning now number of requests is randomized in the given range, which is useful to avoid
and then can never hurt. restarting all worker processes around the same time.
This option can be useful when your worker processes keep accumulating memory
over time. A little pruning now and then can never hurt.
=item FU_DEBUG=0/1 =item FU_DEBUG=0/1