1Net::Server::PreFork(3)User Contributed Perl DocumentatioNnet::Server::PreFork(3)
2
3
4

NAME

6       Net::Server::PreFork - Net::Server personality
7

SYNOPSIS

9           use base qw(Net::Server::PreFork);
10
11           sub process_request {
12               #...code...
13           }
14
15           __PACKAGE__->run();
16

DESCRIPTION

18       Please read the pod on Net::Server and Net::Server::PreForkSimple
19       first.  This module is a personality, or extension, or sub class, of
20       the Net::Server::PreForkSimple class which is a sub class of
21       Net::Server.  See Net::Server::PreForkSimple.
22
23       This personality binds to one or more ports and then forks
24       "min_servers" child process.  The server will make sure that at any
25       given time there are "min_spare_servers" available to receive a client
26       request, up to "max_servers".  Each of these children will process up
27       to "max_requests" client connections.  This type is good for a heavily
28       hit site, and should scale well for most applications.  (Multi port
29       accept is accomplished using flock to serialize the children).
30
31       At this time, it does not appear that this module will pass tests on
32       Win32 systems.  Any ideas or patches for making the tests pass would be
33       welcome.
34

SAMPLE CODE

36       Please see the sample listed in Net::Server.
37

COMMAND LINE ARGUMENTS

39       In addition to the command line arguments of the Net::Server base class
40       and the Net::Server::PreForkSimple parent class, Net::Server::PreFork
41       contains several other configurable parameters.  You really should also
42       see Net::Server::PreForkSimple.
43
44           Key                 Value                   Default
45           min_servers         \d+                     5
46           min_spare_servers   \d+                     2
47           max_spare_servers   \d+                     10
48           max_servers         \d+                     50
49           max_requests        \d+                     1000
50
51           serialize           (flock|semaphore
52                                |pipe|none)            undef
53           # serialize defaults to flock on multi_port or on Solaris
54           lock_file           "filename"              File::Temp->new
55
56           check_for_dead      \d+                     30
57           check_for_waiting   \d+                     10
58
59           max_dequeue         \d+                     undef
60           check_for_dequeue   \d+                     undef
61
62           child_communication 1                       undef
63
64       min_servers
65           The minimum number of servers to keep running.
66
67       min_spare_servers
68           The minimum number of servers to have waiting for requests.
69           Minimum and maximum numbers should not be set to close to each
70           other or the server will fork and kill children too often.
71
72       max_spare_servers
73           The maximum number of servers to have waiting for requests.  See
74           min_spare_servers.
75
76       max_servers
77           The maximum number of child servers to start.  This does not apply
78           to dequeue processes.
79
80       check_for_waiting
81           Seconds to wait before checking to see if we can kill off some
82           waiting servers.
83
84       check_for_spawn
85           Seconds between checking to see if we need to spawn more children
86
87       min_child_ttl
88           Minimum number of seconds between starting children and killing a
89           child process
90
91       child_communication
92           Enable child communication to parent via unix sockets.  If set to
93           true, will let children write to the socket contained in
94           $self->{'server'}->{'parent_sock'}.  The parent will be notified
95           through child_is_talking_hook where the first argument is the
96           socket to the child.  The child's socket is stored in
97           $self->{'server'}->{'children'}->{$child_pid}->{'sock'}.
98
99       serialize
100           See the documentation under Net::Server::PreForkSimple.
101

CONFIGURATION FILE

103       "Net::Server::PreFork" allows for the use of a configuration file to
104       read in server parameters.  The format of this conf file is simple key
105       value pairs.  Comments and white space are ignored.
106
107           #-------------- file test.conf --------------
108
109           ### server information
110           min_servers   20
111           max_servers   80
112           min_spare_servers 10
113           min_spare_servers 15
114
115           max_requests  1000
116
117           ### user and group to become
118           user        somebody
119           group       everybody
120
121           ### logging ?
122           log_file    /var/log/server.log
123           log_level   3
124           pid_file    /tmp/server.pid
125
126           ### access control
127           allow       .+\.(net|com)
128           allow       domain\.com
129           deny        a.+
130
131           ### background the process?
132           background  1
133
134           ### ports to bind
135           host        127.0.0.1
136           port        localhost:20204
137           port        20205
138
139           ### reverse lookups ?
140           # reverse_lookups on
141
142           ### enable child communication ?
143           # child_communication
144
145           #-------------- file test.conf --------------
146

PROCESS FLOW

148       Process flow follows Net::Server until the loop phase.  At this point
149       "min_servers" are forked and wait for connections.  When a child
150       accepts a connection, finishs processing a client, or exits, it relays
151       that information to the parent, which keeps track and makes sure there
152       are enough children to fulfill "min_servers", "min_spare_servers",
153       "max_spare_servers", and "max_servers".
154

HOOKS

156       The PreFork server has the following hooks in addition to the hooks
157       provided by PreForkSimple.  See Net::Server::PreForkSimple.
158
159       "$self->run_n_children_hook()"
160           This hook occurs at the top of run_n_children which is called each
161           time the server goes to start more child processes.  This gives the
162           parent to do a little of its own accountting (as desired).  Idea
163           for this hook came from James FitzGibbon.
164
165       "$self->parent_read_hook()"
166           This hook occurs any time that the parent reads information from
167           the child.  The line from the child is sent as an argument.
168
169       "$self->child_is_talking_hook()"
170           This hook occurs if child_communication is true and the child has
171           written to $self->{'server'}->{'parent_sock'}.  The first argument
172           will be the open socket to the child.
173
174       "$self->idle_loop_hook()"
175           This hook is called in every pass through the main process wait
176           loop, every "check_for_waiting" seconds.  The first argument is a
177           reference to an array of file descriptors that can be read at the
178           moment.
179
180       "$self->cleanup_dead_child_hook( $child )"
181           This hook is called when a dead child is detected.  A child is
182           considered dead when the pid does no longer exist.  This hook could
183           be used to cleanup possible temporary files or locks left over by a
184           dead child.  =back
185

HOT DEPLOY

187       Since version 2.000, the PreFork server has accepted the TTIN and TTOU
188       signals.  When a TTIN is received, the min and max_servers are
189       increased by 1.  If a TTOU signal is received the min max_servers are
190       decreased by 1.  This allows for adjusting the number of handling
191       processes without having to restart the server.
192

BUGS

194       Tests don't seem to work on Win32.  Any ideas or patches would be
195       welcome.
196

TO DO

198       See Net::Server
199

AUTHOR

201       Paul T. Seamons paul@seamons.com
202

THANKS

204       See Net::Server
205

SEE ALSO

207       Please see also Net::Server::Fork, Net::Server::INET,
208       Net::Server::PreForkSimple, Net::Server::MultiType, Net::Server::Single
209       Net::Server::SIG Net::Server::Daemonize Net::Server::Proto
210

POD ERRORS

212       Hey! The above document had some coding errors, which are explained
213       below:
214
215       Around line 683:
216           You forgot a '=back' before '=head1'
217
218
219
220perl v5.28.0                      2017-08-10           Net::Server::PreFork(3)
Impressum