1Net::Server::PreForkSimUpsleer(3C)ontributed Perl DocumeNnetta:t:iSoenrver::PreForkSimple(3)
2
3
4
6 Net::Server::PreForkSimple - Net::Server personality
7
9 use base qw(Net::Server::PreForkSimple);
10
11 sub process_request {
12 #...code...
13 }
14
15 __PACKAGE__->run();
16
18 Please read the pod on Net::Server first. This module is a
19 personality, or extension, or sub class, of the Net::Server module.
20
21 This personality binds to one or more ports and then forks
22 "max_servers" child processes. The server will make sure that at any
23 given time there are always "max_servers" available to receive a client
24 request. Each of these children will process up to "max_requests"
25 client connections. This type is good for a heavily hit site that can
26 keep "max_servers" processes dedicated to the serving. (Multi port
27 accept defaults to using flock to serialize the children).
28
29 At this time, it does not appear that this module will pass tests on
30 Win32 systems. Any ideas or patches for making the tests pass would be
31 welcome.
32
34 Please see the sample listed in Net::Server.
35
37 In addition to the command line arguments of the Net::Server base
38 class, Net::Server::PreFork contains several other configurable
39 parameters.
40
41 Key Value Default
42 max_servers \d+ 50
43 max_requests \d+ 1000
44
45 serialize (flock|semaphore
46 |pipe|none) undef
47 # serialize defaults to flock on multi_port or on Solaris
48 lock_file "filename" File::Temp->new
49
50 check_for_dead \d+ 30
51
52 max_dequeue \d+ undef
53 check_for_dequeue \d+ undef
54
55 max_servers
56 The maximum number of child servers to start and maintain. This
57 does not apply to dequeue processes.
58
59 max_requests
60 The number of client connections to receive before a child
61 terminates.
62
63 serialize
64 Determines whether the server serializes child connections.
65 Options are undef, flock, semaphore, pipe, or none. Default is
66 undef. On multi_port servers or on servers running on Solaris, the
67 default is flock. The flock option uses blocking exclusive flock
68 on the file specified in lock_file (see below). The semaphore
69 option uses IPC::Semaphore (thanks to Bennett Todd) for giving some
70 sample code. The pipe option reads on a pipe to choose the next.
71 the flock option should be the most bulletproof while the pipe
72 option should be the most portable. (Flock is able to reliquish
73 the block if the process dies between accept on the socket and
74 reading of the client connection - semaphore and pipe do not). An
75 option of none will not perform any serialization. If "none" is
76 passed and there are multiple ports then a the default
77 serialization will be used insted of "none."
78
79 lock_file
80 Filename to use in flock serialized accept in order to serialize
81 the accept sequece between the children. This will default to a
82 generated temporary filename. If default value is used the
83 lock_file will be removed when the server closes.
84
85 check_for_dead
86 Seconds to wait before checking to see if a child died without
87 letting the parent know.
88
89 max_dequeue
90 The maximum number of dequeue processes to start. If a value of
91 zero or undef is given, no dequeue processes will be started. The
92 number of running dequeue processes will be checked by the
93 check_for_dead variable.
94
95 check_for_dequeue
96 Seconds to wait before forking off a dequeue process. The
97 run_dequeue hook must be defined when using this setting. It is
98 intended to use the dequeue process to take care of items such as
99 mail queues. If a value of undef is given, no dequeue processes
100 will be started.
101
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 max_servers 80
111
112 max_requests 1000
113
114 ### user and group to become
115 user somebody
116 group everybody
117
118 ### logging ?
119 log_file /var/log/server.log
120 log_level 3
121 pid_file /tmp/server.pid
122
123 ### access control
124 allow .+\.(net|com)
125 allow domain\.com
126 deny a.+
127
128 ### background the process?
129 background 1
130
131 ### ports to bind
132 host 127.0.0.1
133 port localhost:20204
134 port 20205
135
136 ### reverse lookups ?
137 # reverse_lookups on
138
139 #-------------- file test.conf --------------
140
142 Process flow follows Net::Server until the loop phase. At this point
143 "max_servers" are forked and wait for connections. When a child
144 accepts a connection, finishs processing a client, or exits, it relays
145 that information to the parent, which keeps track and makes sure there
146 are always "max_servers" running.
147
149 The PreForkSimple server has the following hooks in addition to the
150 hooks provided by the Net::Server base class. See Net::Server
151
152 "$self->run_n_children_hook()"
153 This hook occurs at the top of run_n_children which is called each
154 time the server goes to start more child processes. This gives the
155 parent to do a little of its own accountting (as desired). Idea
156 for this hook came from James FitzGibbon.
157
158 "$self->child_init_hook()"
159 This hook takes place immeditately after the child process forks
160 from the parent and before the child begins accepting connections.
161 It is intended for any addiotional chrooting or other security
162 measures. It is suggested that all perl modules be used by this
163 point, so that the most shared memory possible is used.
164
165 "$self->child_finish_hook()"
166 This hook takes place immediately before the child tells the parent
167 that it is exiting. It is intended for saving out logged
168 information or other general cleanup.
169
170 "$self->run_dequeue()"
171 This hook only gets called in conjunction with the
172 check_for_dequeue setting.
173
174 "$self->idle_loop_hook()"
175 This hook is called in every pass through the main process wait
176 loop.
177
179 Since version 2.000, the PreForkSimple server has accepted the TTIN and
180 TTOU signals. When a TTIN is received, the max_servers is increased by
181 1. If a TTOU signal is received the max_servers is decreased by 1.
182 This allows for adjusting the number of handling processes without
183 having to restart the server.
184
186 Tests don't seem to work on Win32. Any ideas or patches would be
187 welcome.
188
190 See Net::Server
191
193 Paul T. Seamons paul@seamons.com
194
196 See Net::Server
197
199 Please see also Net::Server::Fork, Net::Server::INET,
200 Net::Server::PreFork, Net::Server::MultiType, Net::Server::Single
201 Net::Server::SIG Net::Server::Daemonize Net::Server::Proto
202
203
204
205perl v5.34.0 2022-01-21 Net::Server::PreForkSimple(3)