My application code is a little leaky. Someday I hope to fix this, but in 
the meantime I have resorted to checking the process memory usage after a 
request has completed using the ExecuteOnCompletion2 wsgi filter 
from https://code.google.com/p/modwsgi/wiki/RegisteringCleanupCode

def rss_checker(rss_limit=None):
    log = logging.getLogger(__name__)
    process = psutil.Process()
 
    def callback(environ):
        rss = process.memory_info().rss
        if rss_limit and rss > rss_limit:
            msg = "Restarting process. Memory usage exceeds limit of %d: %d"
            log.error(msg, rss_limit, rss)
            process.kill()
 
    return callback

This seems to work well enough, mod_wsgi restarts the process for me and 
service is uninterrupted. It has an obvious limitation though in that it 
can only work when WSGIDaemonProcess threads=1. Could there be some 
mechanism to communicate to mod_wsgi that it should restart a daemon 
process gracefully, once all existing in-flight requests are served? I 
guess my ideal solution might involve a watchdog thread in my application 
that periodically checked resource usage and signalled mod_wsgi when it 
desired a graceful restart.

I measure resource usage rather than setting `maximum-requests` because 
different usage patterns have very different memory usage profiles.

Laurence

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to