benoitc/gunicorn — pull request #502 by Glandos (2013-03-10 18:11:47+00:00)
Title: No active idle

The goal is the same as in #377, except that it tries to go further: when there is nothing to do, then nothing is done, nor in the master or in the workers.

This time, I've added a CLI option '--inactive-master', that is False by default. Without this option, the whole behavior is unchanged. At least, it should be.

When this option is defined, the following rules apply:
* When no requests are in progress, the master waits without timeout. So are workers.
* When at least one worker is working, the master waits for the remaining time before the oldest worker notification expires.

Technical details:
* This behavior is only implemented in sync workers. Using the option with other workers will result in workers not killed in case of timeout.
* The active state of the worker is saved inside the same temporary file that's used for last update check. I didn't found another way of achieving this without being more invasive.
* Whenever a worker goes active, it needs to wake up the master. For that, each worker has now a reference to the master writable pipe, to wake it up. It does it exactly the same way the master wake itself up.
* As in #377, the master will sleep for the maximum time it could, before checking if some worker is stalled.

Discussion's opened. Criticisms are welcomed.