1Net::Server::PreFork(3)User Contributed Perl DocumentatioNnet::Server::PreFork(3)
2
3
4
6 Net::Server::PreFork - Net::Server personality
7
9 use Net::Server::PreFork;
10 @ISA = qw(Net::Server::PreFork);
11
12 sub process_request {
13 #...code...
14 }
15
16 __PACKAGE__->run();
17
19 Please read the pod on Net::Server and Net::Server::PreForkSimple
20 first. This module is a personality, or extension, or sub class, of
21 the Net::Server::PreForkSimple class which is a sub class of
22 Net::Server. See Net::Server::PreForkSimple.
23
24 This personality binds to one or more ports and then forks
25 "min_servers" child process. The server will make sure that at any
26 given time there are "min_spare_servers" available to receive a client
27 request, up to "max_servers". Each of these children will process up
28 to "max_requests" client connections. This type is good for a heavily
29 hit site, and should scale well for most applications. (Multi port
30 accept is accomplished using flock to serialize the children).
31
32 At this time, it does not appear that this module will pass tests on
33 Win32 systems. Any ideas or patches for making the tests pass would be
34 welcome.
35
37 Please see the sample listed in Net::Server.
38
40 In addition to the command line arguments of the Net::Server base class
41 and the Net::Server::PreForkSimple parent class, Net::Server::PreFork
42 contains several other configurable parameters. You really should also
43 see Net::Server::PreForkSimple.
44
45 Key Value Default
46 min_servers \d+ 5
47 min_spare_servers \d+ 2
48 max_spare_servers \d+ 10
49 max_servers \d+ 50
50 max_requests \d+ 1000
51
52 serialize (flock|semaphore|pipe) undef
53 # serialize defaults to flock on multi_port or on Solaris
54 lock_file "filename" POSIX::tmpnam
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 child_communication
85 Enable child communication to parent via unix sockets. If set to
86 true, will let children write to the socket contained in
87 $self->{server}->{parent_sock}. The parent will be notified
88 through child_is_talking_hook where the first argument is the
89 socket to the child. The child's socket is stored in
90 $self->{server}->{children}->{$child_pid}->{sock}.
91
93 "Net::Server::PreFork" allows for the use of a configuration file to
94 read in server parameters. The format of this conf file is simple key
95 value pairs. Comments and white space are ignored.
96
97 #-------------- file test.conf --------------
98
99 ### server information
100 min_servers 20
101 max_servers 80
102 min_spare_servers 10
103 min_spare_servers 15
104
105 max_requests 1000
106
107 ### user and group to become
108 user somebody
109 group everybody
110
111 ### logging ?
112 log_file /var/log/server.log
113 log_level 3
114 pid_file /tmp/server.pid
115
116 ### access control
117 allow .+\.(net|com)
118 allow domain\.com
119 deny a.+
120
121 ### background the process?
122 background 1
123
124 ### ports to bind
125 host 127.0.0.1
126 port localhost:20204
127 port 20205
128
129 ### reverse lookups ?
130 # reverse_lookups on
131
132 ### enable child communication ?
133 # child_communication
134
135 #-------------- file test.conf --------------
136
138 Process flow follows Net::Server until the loop phase. At this point
139 "min_servers" are forked and wait for connections. When a child
140 accepts a connection, finishs processing a client, or exits, it relays
141 that information to the parent, which keeps track and makes sure there
142 are enough children to fulfill "min_servers", "min_spare_servers",
143 "max_spare_servers", and "max_servers".
144
146 The PreFork server has the following hooks in addition to the hooks
147 provided by PreForkSimple. See Net::Server::PreForkSimple.
148
149 "$self->run_n_children_hook()"
150 This hook occurs at the top of run_n_children which is called each
151 time the server goes to start more child processes. This gives the
152 parent to do a little of its own accountting (as desired). Idea
153 for this hook came from James FitzGibbon.
154
155 "$self->parent_read_hook()"
156 This hook occurs any time that the parent reads information from
157 the child. The line from the child is sent as an argument.
158
159 "$self->child_is_talking_hook()"
160 This hook occurs if child_communication is true and the child has
161 written to $self->{server}->{parent_sock}. The first argument will
162 be the open socket to the child.
163
165 Tests don't seem to work on Win32. Any ideas or patches would be
166 welcome.
167
169 See Net::Server
170
172 Paul T. Seamons paul@seamons.com
173
175 See Net::Server
176
178 Please see also Net::Server::Fork, Net::Server::INET,
179 Net::Server::PreForkSimple, Net::Server::MultiType, Net::Server::Single
180 Net::Server::SIG Net::Server::Daemonize Net::Server::Proto
181
182
183
184perl v5.12.0 2007-03-23 Net::Server::PreFork(3)