Skip to content

Commit

Permalink
rename overload to spare
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 4, 2017
1 parent 91fae2b commit 0c1b1ae
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Changes
@@ -1,9 +1,9 @@

7.35 2017-07-04
- Removed deprecated watch attribute from Mojo::Server::Morbo.
- Added overload attribute to Mojo::Server::Prefork.
- Added -o option to prefork command.
- Added overload setting to Hypnotoad.
- Added spare attribute to Mojo::Server::Prefork.
- Added -s option to prefork command.
- Added spare setting to Hypnotoad.
- Increased default graceful_timeout from 20 to 60 seconds in
Mojo::Server::Prefork.

Expand Down
20 changes: 10 additions & 10 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -26,7 +26,7 @@ sub configure {
$prefork->max_requests($c->{requests}) if $c->{requests};
defined $c->{$_} and $prefork->$_($c->{$_})
for qw(accepts backlog graceful_timeout heartbeat_interval),
qw(heartbeat_timeout inactivity_timeout listen overload pid_file workers);
qw(heartbeat_timeout inactivity_timeout listen pid_file spare workers);
}

sub run {
Expand Down Expand Up @@ -315,15 +315,6 @@ Setting the value to C<0> will allow connections to be inactive indefinitely.
Array reference with one or more locations to listen on, defaults to
C<http://*:8080>. See also L<Mojo::Server::Daemon/"listen"> for more examples.
=head2 overload
overload => 4
Temporarily spawn up to this number of additional workers if there is a need,
defaults to the value of L<Mojo::Server::Prefork/"overload">. This allows for
new workers to be started while old ones are still shutting down gracefully,
drastically reducing the performance cost of worker restarts.
=head2 pid_file
pid_file => '/var/run/hypnotoad.pid'
Expand All @@ -347,6 +338,15 @@ value of L<Mojo::Server/"reverse_proxy">.
Number of keep-alive requests per connection, defaults to the value of
L<Mojo::Server::Daemon/"max_requests">.
=head2 spare
spare => 4
Temporarily spawn up to this number of additional workers if there is a need,
defaults to the value of L<Mojo::Server::Prefork/"spare">. This allows for new
workers to be started while old ones are still shutting down gracefully,
drastically reducing the performance cost of worker restarts.
=head2 upgrade_timeout
upgrade_timeout => 45
Expand Down
28 changes: 14 additions & 14 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -13,8 +13,8 @@ has cleanup => 1;
has graceful_timeout => 60;
has heartbeat_timeout => 20;
has heartbeat_interval => 5;
has overload => 2;
has pid_file => sub { path(tmpdir, 'prefork.pid')->to_string };
has spare => 2;
has workers => 4;

sub DESTROY { unlink $_[0]->pid_file if $_[0]->cleanup }
Expand Down Expand Up @@ -94,9 +94,9 @@ sub _manage {
# Spawn more workers if necessary and check PID file
if (!$self->{finished}) {
my $graceful = grep { $_->{graceful} } values %{$self->{pool}};
my $overload = $self->overload;
$overload = $graceful ? $graceful > $overload ? $overload : $graceful : 0;
my $need = ($self->workers - keys %{$self->{pool}}) + $overload;
my $spare = $self->spare;
$spare = $graceful ? $graceful > $spare ? $spare : $graceful : 0;
my $need = ($self->workers - keys %{$self->{pool}}) + $spare;
$self->_spawn while $need-- > 0;
$self->ensure_pid_file($$);
}
Expand Down Expand Up @@ -402,16 +402,6 @@ stopped gracefully, defaults to C<20>. Note that this value should usually be a
little larger than the maximum amount of time you expect any one operation to
block the event loop.
=head2 overload
my $overload = $prefork->overload;
$prefork = $prefork->overload(4);
Temporarily spawn up to this number of additional workers if there is a need,
defaults to C<2>. This allows for new workers to be started while old ones are
still shutting down gracefully, drastically reducing the performance cost of
worker restarts.
=head2 pid_file
my $file = $prefork->pid_file;
Expand All @@ -420,6 +410,16 @@ worker restarts.
Full path of process id file, defaults to C<prefork.pid> in a temporary
directory.
=head2 spare
my $spare = $prefork->spare;
$prefork = $prefork->spare(4);
Temporarily spawn up to this number of additional workers if there is a need,
defaults to C<2>. This allows for new workers to be started while old ones are
still shutting down gracefully, drastically reducing the performance cost of
worker restarts.
=head2 workers
my $workers = $prefork->workers;
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Command/prefork.pm
Expand Up @@ -21,10 +21,10 @@ sub run {
'H|heartbeat-timeout=i' => sub { $prefork->heartbeat_timeout($_[1]) },
'i|inactivity-timeout=i' => sub { $prefork->inactivity_timeout($_[1]) },
'l|listen=s' => \my @listen,
'o|overload=i' => sub { $prefork->overload($_[1]) },
'P|pid-file=s' => sub { $prefork->pid_file($_[1]) },
'p|proxy' => sub { $prefork->reverse_proxy(1) },
'r|requests=i' => sub { $prefork->max_requests($_[1]) },
's|spare=i' => sub { $prefork->spare($_[1]) },
'w|workers=i' => sub { $prefork->workers($_[1]) };

$prefork->listen(\@listen) if @listen;
Expand Down Expand Up @@ -71,15 +71,15 @@ Mojolicious::Command::prefork - Pre-fork command
-m, --mode <name> Operating mode for your application,
defaults to the value of
MOJO_MODE/PLACK_ENV or "development"
-o, --overload <number> Temporarily spawn up to this number of
additional workers, defaults to 2
-P, --pid-file <path> Path to process id file, defaults to
"prefork.pid" in a temporary diretory
-p, --proxy Activate reverse proxy support,
defaults to the value of
MOJO_REVERSE_PROXY
-r, --requests <number> Maximum number of requests per
keep-alive connection, defaults to 100
-s, --spare <number> Temporarily spawn up to this number of
additional workers, defaults to 2
-w, --workers <number> Number of workers, defaults to 4
=head1 DESCRIPTION
Expand Down
6 changes: 3 additions & 3 deletions t/mojo/hypnotoad.t
Expand Up @@ -26,10 +26,10 @@ use Mojo::UserAgent;
heartbeat_timeout => 9,
inactivity_timeout => 5,
listen => ['http://*:8081'],
overload => 4,
pid_file => '/foo/bar.pid',
proxy => 1,
requests => 3,
spare => 4,
upgrade_timeout => 45,
workers => 7
};
Expand All @@ -46,10 +46,10 @@ use Mojo::UserAgent;
is_deeply $hypnotoad->prefork->listen, ['http://*:8081'], 'right value';
is $hypnotoad->prefork->max_clients, 1, 'right value';
is $hypnotoad->prefork->max_requests, 3, 'right value';
is $hypnotoad->prefork->overload, 4, 'right value';
is $hypnotoad->prefork->pid_file, '/foo/bar.pid', 'right value';
ok $hypnotoad->prefork->reverse_proxy, 'reverse proxy enabled';
is $hypnotoad->prefork->workers, 7, 'right value';
is $hypnotoad->prefork->spare, 4, 'right value';
is $hypnotoad->prefork->workers, 7, 'right value';
is $hypnotoad->upgrade_timeout, 45, 'right value';
}

Expand Down

0 comments on commit 0c1b1ae

Please sign in to comment.