Acme-Ghost
view release on metacpan or search on metacpan
lib/Acme/Ghost.pm view on Meta::CPAN
This method returns L<Acme::Ghost::Log> object
=head2 ok
$g->ok or die "Interrupted!";
This method checks process state and returns boolean status of healthy.
If this status is false, then it is immediately to shut down Your process
as soon as possible, otherwise your process will be forcibly destroyed
within 7 seconds from the moment your process receives the corresponding signal
=head2 pid
print $g->pid;
This method returns PID of the daemon
=head2 set_gid
$g = $g->set_gid('1000 10001 10002');
lib/Acme/Ghost/Prefork.pm view on Meta::CPAN
Pre-forking ghost daemon (server)
=head1 ATTRIBUTES
This class inherits all attributes from L<Acme::Ghost> and implements the following new ones
=head2 graceful_timeout
graceful_timeout => 120
The maximum amount of time in seconds stopping a spirit gracefully may take before being forced to stop
B<Note that> this value should usually be a little larger than the maximum
amount of time you expect any one request to take
Defaults to C<120>
=head2 heartbeat_interval
heartbeat_interval => 5
Heartbeat interval in seconds, defaults to C<5>
=head2 heartbeat_timeout
heartbeat_timeout => 50
Maximum amount of time in seconds before a spirit without a heartbeat will be stopped gracefully
B<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
Defaults to C<50>
=head2 spare
spare => 2
lib/Acme/Ghost/Prefork.pm view on Meta::CPAN
my $interval = $self->{heartbeat_interval};
my $hb_to = $self->{heartbeat_timeout};
my $gf_to = $self->{graceful_timeout};
my $now = Time::HiRes::time;
my $log = $self->log;
for my $pid (keys %{$self->{pool}}) {
next unless my $w = $self->{pool}{$pid}; # Get spirit struct
# No heartbeat (graceful stop)
if (!$w->{graceful} && ($w->{time} + $interval + $hb_to <= $now)) {
$log->error("Spirit $pid has no heartbeat ($hb_to seconds), restarting");
$w->{graceful} = $now;
}
# Graceful stop with timeout
my $graceful = $w->{graceful} ||= $self->{gracefully_stop} ? $now : undef;
if ($graceful && !$w->{attempt}) {
$w->{attempt}++;
$log->info("Stopping spirit $pid gracefully ($gf_to seconds)");
kill 'QUIT', $pid or $self->_stopped($pid);
}
$w->{force} = 1 if $graceful && $graceful + $gf_to <= $now; # The conditions for a graceful stop by timeout were violated
# Normal stop
if ($w->{force} || ($self->{finished} && !$graceful)) {
$log->warn("Stopping spirit $pid immediately");
kill 'KILL', $pid or $self->_stopped($pid);
}
}
( run in 0.756 second using v1.01-cache-2.11-cpan-39bf76dae61 )