1Parallel::Prefork(3)  User Contributed Perl Documentation Parallel::Prefork(3)
2
3
4

NAME

6       Parallel::Prefork - A simple prefork server framework
7

SYNOPSIS

9         use Parallel::Prefork;
10
11         my $pm = Parallel::Prefork->new({
12           max_workers  => 10,
13           trap_signals => {
14             TERM => 'TERM',
15             HUP  => 'TERM',
16             USR1 => undef,
17           }
18         });
19
20         while ($pm->signal_received ne 'TERM') {
21           load_config();
22           $pm->start(sub {
23               ... do some work within the child process ...
24           });
25         }
26
27         $pm->wait_all_children();
28

DESCRIPTION

30       "Parallel::Prefork" is much like "Parallel::ForkManager", but supports
31       graceful shutdown and run-time reconfiguration.
32

METHODS

34   new
35       instantiation.  Takes a hashref as an argument.  Recognized attributes
36       are as follows.
37
38       max_workers
39
40       number of worker processes (default: 10)
41
42       spawn_interval
43
44       interval in seconds between spawning child processes unless a child
45       process exits abnormally (default: 0)
46
47       err_respawn_interval
48
49       number of seconds to deter spawning of child processes after a worker
50       exits abnormally (default: 1)
51
52       trap_signals
53
54       hashref of signals to be trapped.  Manager process will trap the
55       signals listed in the keys of the hash, and send the signal specified
56       in the associated value (if any) to all worker processes.  If the
57       associated value is a scalar then it is treated as the name of the
58       signal to be sent immediately to all the worker processes.  If the
59       value is an arrayref the first value is treated the name of the signal
60       and the second value is treated as the interval (in seconds) between
61       sending the signal to each worker process.
62
63       on_child_reap
64
65       coderef that is called when a child is reaped. Receives the instance to
66       the current Parallel::Prefork, the child's pid, and its exit status.
67
68       before_fork
69
70       after_fork
71
72       coderefs that are called in the manager process before and after fork,
73       if being set
74
75   start
76       The main routine.  There are two ways to use the function.
77
78       If given a subref as an argument, forks child processes and executes
79       that subref within the child processes.  The processes will exit with 0
80       status when the subref returns.
81
82       The other way is to not give any arguments to the function.  The
83       function returns undef in child processes.  Caller should execute the
84       application logic and then call "finish" to terminate the process.
85
86       The "start" function returns true within manager process upon receiving
87       a signal specified in the "trap_signals" hashref.
88
89   finish
90       Child processes (when executed by a zero-argument call to "start")
91       should call this function for termination.  Takes exit code as an
92       optional argument.  Only usable from child processes.
93
94   signal_all_children
95       Sends signal to all worker processes.  Only usable from manager
96       process.
97
98   wait_all_children()
99   wait_all_children($timeout)
100       Waits until all worker processes exit or timeout (given as an optional
101       argument in seconds) exceeds.  The method returns the number of the
102       worker processes still running.
103

AUTHOR

105       Kazuho Oku
106

LICENSE

108       This program is free software; you can redistribute it and/or modify it
109       under the same terms as Perl itself.
110
111       See http://www.perl.com/perl/misc/Artistic.html
112
113
114
115perl v5.28.1                      2016-02-10              Parallel::Prefork(3)
Impressum