On Thu, Jul 19, 2001 at 04:03:24PM +0200, Anton Berezin wrote:
> Hi,
>
> What is the easiest way to achieve this goal, so that the master process
> will only provide watchdog functionality?
>
> It seems to me that it might be enough to do just that (the diff is
> relative to the samples/preforkedserver.perl), but I am not sure:
>
> --- preforkedserver.perl.orig Thu Jul 19 16:01:35 2001
> +++ preforkedserver.perl Thu Jul 19 16:02:11 2001
> @@ -154,10 +154,12 @@
> # change behavior for children
> $heap->{'is a child'} = 0;
> # fork the initial set of children
> - foreach (2..$processes) {
> + foreach (1..$processes) {
> # yield() posts events to this session
> $kernel->yield('fork');
> }
> +
> + delete $heap->{wheel};
>
> DEBUG && print "$$: master server has started\n";
> }
>
> Am I right?
Partly, I think. If I recall correctly, the child processes
eventually exit, requiring the parent to fork new ones. If you've
deleted the wheel in the parent, though, the new children will also
not have it. They won't listen for connections either, and eventually
your server will stop responding. It might go so far as to rapidly
spawn children which just exit, and that would be bad for overall
system performance. :)
The easiest workaround I can see is to have the parent process create
a listening socket (probably with IO::Socket::INET) and keep a copy of
it in its HEAP. Each child processe would immediately start a
ListenAccept wheel on the saved socket as their first task.
Mind you, the child processes don't have to exit if they don't leak
resources. I modelled the idea after Apache, which recycled child
processes now and then to prevent runaway daemons.
-- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sourceforge.net