[mod_python] Session Hanging Problems

Harish Agarwal harish at octopart.com
Mon Nov 26 13:39:27 EST 2007

I'm using session handling with ModPython 3.3.1.  Originally I was  
using DbmSession and have since transitioned to a custom MySQL Session  
handler.  With both session types, however, I've noticed that session  
initialization intermittently hangs (not forever, but takes as long as  
four minutes to complete), at a low-ish (a handful of times every  
hour, while receiving, say, on order of a thousand or so requests  
every hour) frequency which seems to scale with the amount of traffic  
we're receiving.  I had read that long DbmSession cleanups can cause  
problems, which is why I transitioned to the MySQL system, which takes  
< 1 second to complete, but I'm still noticing the long session init  

I put some debugging statements into the code and it seems to be  
related to session locking.  In particular, it is this function call  
in the lock method of the BaseSession class:

_apache._global_lock(self._req.server, self._sid)

which is taking some time to complete. I'm not familiar with  
_apache._global_lock (is it used to apply a mutex lock to the  
session?) and am having trouble finding information describing its  
usage - but it seems likely that this is the root cause.  In the past  
I've had problems with session locking but have since transitioned the  
code to ensure that only one session is created per request, as such:

if not hasattr(req,'session'):
             req.session = Session.MySQLSession(req)

Can anyone tell me if this kind of behavior is normal or is indicative  
of some common configuration or coding error?  Any help would be  
greatly appreciated.


More information about the Mod_python mailing list