psini has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I'm sorry for my awful English, hope you'll forgive me.

I wrote a program using Net::Server::Prefork module that works fine but shows a strange quirk: I understand that whenever the server spawns more than max_spare_servers process, if I stop sending requests it should kill the exceeding processes.

Instead, this is what I find in syslog>

May 10 23:24:04 localhost tme[7967]: Processing diff (0), Waiting diff + (-2) May 10 23:24:04 localhost tme[7967]: Killing "2" children May 10 23:24:04 localhost tme[7967]: Starting "1" children May 10 23:24:04 localhost tme[8470]: Child Preforked (8470) May 10 23:24:04 localhost tme[7967]: Starting "1" children May 10 23:24:04 localhost tme[8471]: Child Preforked (8471) May 10 23:24:44 localhost tme[7967]: Processing diff (0), Waiting diff + (-2) May 10 23:24:44 localhost tme[7967]: Killing "2" children May 10 23:24:44 localhost tme[7967]: Starting "1" children May 10 23:24:44 localhost tme[8483]: Child Preforked (8483) May 10 23:24:44 localhost tme[7967]: Starting "1" children May 10 23:24:44 localhost tme[8484]: Child Preforked (8484)

And this go on indefinitely: every 40 seconds the server kills two children (but it was only one over the max_spare_servers quota) and then immediately respawns them!

I tried google, I read the (not so complete) documentation of the module and I even tried to browse the sources of the module but I found nothing.

Does anybody know if this is a known bug of the Net::Server or if there is a known condition in which this behavior is t be expected?

Thanks in advance

Replies are listed 'Best First'.
Re: net::server::prefork fork too much (config)
by tye (Sage) on May 11, 2008 at 04:11 UTC

    My first guess is just that you configured things badly. You don't include any information about how you configured things, so I'm left to guess. But, for example, if you set max_spare_servers to 0 and min_servers to 2, then you force it to repeatedly kill the two extra idle children and repeatedly add children to get back to the minimum of 2.

    Yes, you could patch the module to try to prevent this misbehavior when a user of the module misconfigures it.

    - tye        

      sorry, you're right, I forgot to post the config file.

      .This is the relevant portion:

      log_level 4 log_file Sys::Syslog syslog_logsock unix syslog_ident tmp syslog_logopt pid syslog_facility local1 pid_file /var/run/tmp.pid serialize flock min_servers 5 min_spare_servers 3 max_spare_servers 10 max_servers 30 max_request 100 child_communication 1 port 9999 host * proto tcp listen SOMAXCONN user www-data group www-data background 1 setsid 1

        I'd try setting min_servers and min_spare_servers to be equal. If that stops the thrash, then you should submit a patch for the module that improves its logic to prevent this problem.

        - tye