Skip to content

Commit

Permalink
improved Hypnotoad log messages a little
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 5, 2012
1 parent 1185770 commit c9d48ca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

3.03 2012-07-05
- Improved Hypnotoad log messages.
- Improved documentation.
- Improved tests.
- Fixed small namespace detection bug in Mojo::DOM.
Expand Down
13 changes: 7 additions & 6 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -213,15 +213,15 @@ sub _manage {
# Workers
while (my ($pid, $w) = each %{$self->{workers}}) {

# No heartbeat (graceful stop)
# No heartbeat (graceful shutdown)
my $interval = $c->{heartbeat_interval};
my $timeout = $c->{heartbeat_timeout};
if ($w->{time} + $interval + $timeout <= time) {
if (!$w->{graceful} && ($w->{time} + $interval + $timeout <= time)) {
$self->{log}->info("Worker $pid has no heartbeat, restarting.");
$w->{graceful} ||= time;
$w->{graceful} = time;
}

# Graceful stop with timeout
# Graceful shutdown with timeout
$w->{graceful} ||= time if $self->{graceful};
if ($w->{graceful}) {
$self->{log}->debug("Trying to stop worker $pid gracefully.");
Expand Down Expand Up @@ -321,7 +321,7 @@ sub _spawn {
);
$loop->unlock(sub { flock $lock, LOCK_UN });

# Heartbeat
# Heartbeat messages (stop sending during graceful shutdown)
weaken $self;
$loop->recurring(
$c->{heartbeat_interval} => sub {
Expand Down Expand Up @@ -460,7 +460,8 @@ L<Mojolicious::Guides::Cookbook/"Hypnotoad"> for examples.
Maximum number of connections a worker is allowed to accept before stopping
gracefully, defaults to C<1000>. Setting the value to C<0> will allow workers
to accept new connections indefinitely.
to accept new connections indefinitely. Note that worker processes stop
sending heartbeat messages once this limit has been reached.
=head2 C<backlog>
Expand Down
13 changes: 7 additions & 6 deletions lib/Mojolicious/Guides/FAQ.pod
Expand Up @@ -111,12 +111,13 @@ response.

=head2 What does "Worker 31842 has no heartbeat, restarting" mean?

Hypnotoad worker processes send heartbeat messages to the manager process in
regular intervals to signal that they are still responsive. A blocking
operation such as an infinite loop in your application can prevent this, and
will force the affected worker to be restarted after a timeout. This
C<heartbeat_timeout> defaults to C<20> seconds and can be extended if your
application requires it.
As long as they are accepting new connections, Hypnotoad worker processes send
heartbeat messages to the manager process in regular intervals, to signal that
they are still responsive. A blocking operation such as an infinite loop in
your application (or active connections after a worker has stopped accepting
new connections) can prevent this, and will force the affected worker to be
restarted after a timeout. This C<heartbeat_timeout> defaults to C<20> seconds
and can be extended if your application requires it.

=head2 I think i have found a bug, what should i do now?

Expand Down

0 comments on commit c9d48ca

Please sign in to comment.