Acme-Ghost
view release on metacpan or search on metacpan
lib/Acme/Ghost/Prefork.pm view on Meta::CPAN
package Acme::Ghost::Prefork;
use warnings;
use strict;
use utf8;
=encoding utf-8
=head1 NAME
Acme::Ghost::Prefork - Pre-forking ghost daemon
=head1 SYNOPSIS
use Acme::Ghost::Prefork;
my $g = Acme::Ghost::Prefork->new(
logfile => '/tmp/daemon.log',
pidfile => '/tmp/daemon.pid',
spirit => sub {
my $self = shift;
my $max = 10;
my $i = 0;
while ($self->tick) {
$i++;
sleep 1;
$self->log->debug(sprintf("$$> %d/%d", $i, $max));
last if $i >= $max;
}
},
);
exit $g->ctrl(shift(@ARGV) // '');
=head1 DESCRIPTION
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
Temporarily spawn up to this number of additional spirits if there is a need
This allows for new spirits to be started while old ones are still shutting down gracefully,
drastically reducing the performance cost of spirit restarts.
Defaults to C<2>
=head2 spirits, workers
spirits => 4
Number of spirit processes.
A good rule of thumb is two spirit processes per CPU core for applications that perform mostly
non-blocking operations.
Blocking operations often require more amount of spirits and benefit from decreasing concurrency
(often as low as C<1>)
Defaults to C<4>
=head1 METHODS
This class inherits all methods from L<Acme::Ghost> and implements the following new ones
=head2 again
This method is called immediately after creating the instance and returns it
B<NOTE:> Internal use only!
=head2 healthy
my $healthy = $g->healthy;
This method returns the number of currently active live spirit processes (with a heartbeat)
=head2 startup
$prefork->startup;
This method starts preforked process (manager and spirits) and wait for L</"MANAGER SIGNALS">
=head2 tick
( run in 0.851 second using v1.01-cache-2.11-cpan-5837b0d9d2c )