1Parallel::Prefork::SparUesWeorrkCeornst(r3i)buted Perl DPoacruamlelnetla:t:iPornefork::SpareWorkers(3)
2
3
4

NAME

6       Parallel::Prefork::SpareWorkers - A prefork server framework with
7       support for (min|max)spareservers
8

SYNOPSIS

10         use Parallel::Prefork::SpareWorkers qw(:status);
11
12         my $pm = Parallel::Prefork::SpareWorkers->new({
13           max_workers       => 40,
14           min_spare_workers => 5,
15           max_spare_workers => 10,
16           trap_signals      => {
17             TERM => 'TERM',
18             HUP  => 'TERM',
19             USR1 => undef,
20           },
21         });
22
23         while ($pm->signal_received ne 'TERM') {
24           load_config();
25           $pm->start and next;
26
27           # do what ever you like, as follows
28           while (my $sock = $listener->accept()) {
29             $pm->set_status('A');
30             ...
31             $sock->close();
32             $pm->set_status(STATUS_IDLE);
33           }
34
35           $pm->finish;
36         }
37
38         $pm->wait_all_children;
39

DESCRIPTION

41       "Parallel::Prefork::SpareWorkers" is a subclass of "Parallel::Prefork"
42       that supports setting minimum and maximum number of spare worker
43       processes, a feature commonly found in network servers.  The module
44       adds to "Parallel::Prefork" several initialization parameters,
45       constants, and a method to set state of the worker processes.
46

METHODS

48   new
49       Instantiation.  "Parallel::Prefork::ShpareWorkers" recognizes the
50       following parameters in addition to those defined by
51       "Parallel::Prefork".  The parameters can be accessed using accessors
52       with same names as well.
53
54       min_spare_workers
55
56       minimum number of spare workers (mandatory)
57
58       max_spare_workers
59
60       maxmum number of spare workers (default: max_workers)
61
62       heartbeat
63
64       a fractional period (in seconds) of child amount checking. Do not use
65       very small numbers to avoid frequent use of CPU (default: 0.25)
66
67       scoreboard_file
68
69       filename of scoreboard.  If not set, "Parallel::Prefork::SpareWorkers"
70       will create a temporary file.
71
72   set_status
73       sets a single-byte character state of the worker process.  Worker
74       processes should set any character of their choice using the function
75       (but not one of the reserved characters) to declare that it is running
76       some kind of task.  Or the state should be set to "STATUS_IDLE" '_'
77       once the worker enters idle state.  The other reserved character is
78       "STATUS_NEXIST" '.' which should never be set directly by applications.
79

CONSTANTS

81   STATUS_NEXIST
82       scoreboard status character '.', meaning no worker process is assigned
83       to the slot of the scoreboard.  Applications should never set this
84       value directly.
85
86   STATUS_IDLE
87       scoreboard status character '_', meaning that a worker process is in
88       idle state
89

LICENSE

91       This program is free software; you can redistribute it and/or modify it
92       under the same terms as Perl itself.
93
94       See http://www.perl.com/perl/misc/Artistic.html
95
96
97
98perl v5.30.0                      2019-07-26Parallel::Prefork::SpareWorkers(3)
Impressum