| 1 |
NAME |
| 2 |
Parallel::Prefork - A simple prefork server framework |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use Parallel::Prefork; |
| 6 |
|
| 7 |
my $pm = Parallel::Prefork->new({ |
| 8 |
max_workers => 10, |
| 9 |
trap_signals => { |
| 10 |
TERM => 'TERM', |
| 11 |
HUP => 'TERM', |
| 12 |
USR1 => undef, |
| 13 |
} |
| 14 |
}); |
| 15 |
|
| 16 |
while ($pm->signal_received ne 'TERM') { |
| 17 |
load_config(); |
| 18 |
$pm->start(sub { |
| 19 |
... do some work within the child process ... |
| 20 |
}); |
| 21 |
} |
| 22 |
|
| 23 |
$pm->wait_all_children(); |
| 24 |
|
| 25 |
DESCRIPTION |
| 26 |
"Parallel::Prefork" is much like "Parallel::ForkManager", but supports |
| 27 |
graceful shutdown and run-time reconfiguration. |
| 28 |
|
| 29 |
METHODS |
| 30 |
new |
| 31 |
instantiation. Takes a hashref as an argument. Recognized attributes are |
| 32 |
as follows. |
| 33 |
|
| 34 |
max_workers |
| 35 |
number of worker processes (default: 10) |
| 36 |
|
| 37 |
spawn_interval |
| 38 |
interval in seconds between spawning child processes unless a child |
| 39 |
process exits abnormally (default: 0) |
| 40 |
|
| 41 |
err_respawn_interval |
| 42 |
number of seconds to deter spawning of child processes after a worker |
| 43 |
exits abnormally (default: 1) |
| 44 |
|
| 45 |
trap_signals |
| 46 |
hashref of signals to be trapped. Manager process will trap the signals |
| 47 |
listed in the keys of the hash, and send the signal specified in the |
| 48 |
associated value (if any) to all worker processes. If the associated |
| 49 |
value is a scalar then it is treated as the name of the signal to be |
| 50 |
sent immediately to all the worker processes. If the value is an |
| 51 |
arrayref the first value is treated the name of the signal and the |
| 52 |
second value is treated as the interval (in seconds) between sending the |
| 53 |
signal to each worker process. |
| 54 |
|
| 55 |
on_child_reap |
| 56 |
coderef that is called when a child is reaped. Receives the instance to |
| 57 |
the current Parallel::Prefork, the child's pid, and its exit status. |
| 58 |
|
| 59 |
before_fork |
| 60 |
after_fork |
| 61 |
coderefs that are called in the manager process before and after fork, |
| 62 |
if being set |
| 63 |
|
| 64 |
start |
| 65 |
The main routine. There are two ways to use the function. |
| 66 |
|
| 67 |
If given a subref as an argument, forks child processes and executes |
| 68 |
that subref within the child processes. The processes will exit with 0 |
| 69 |
status when the subref returns. |
| 70 |
|
| 71 |
The other way is to not give any arguments to the function. The function |
| 72 |
returns undef in child processes. Caller should execute the application |
| 73 |
logic and then call "finish" to terminate the process. |
| 74 |
|
| 75 |
The "start" function returns true within manager process upon receiving |
| 76 |
a signal specified in the "trap_signals" hashref. |
| 77 |
|
| 78 |
finish |
| 79 |
Child processes (when executed by a zero-argument call to "start") |
| 80 |
should call this function for termination. Takes exit code as an |
| 81 |
optional argument. Only usable from child processes. |
| 82 |
|
| 83 |
signal_all_children |
| 84 |
Sends signal to all worker processes. Only usable from manager process. |
| 85 |
|
| 86 |
wait_all_children() |
| 87 |
wait_all_children($timeout) |
| 88 |
Waits until all worker processes exit or timeout (given as an optional |
| 89 |
argument in seconds) exceeds. The method returns the number of the |
| 90 |
worker processes still running. |
| 91 |
|
| 92 |
AUTHOR |
| 93 |
Kazuho Oku |
| 94 |
|
| 95 |
LICENSE |
| 96 |
This program is free software; you can redistribute it and/or modify it |
| 97 |
under the same terms as Perl itself. |
| 98 |
|
| 99 |
See http://www.perl.com/perl/misc/Artistic.html |
| 100 |
|