[mod_python] Sessions performance and some numbers

Jim Gallacher jg.lists at sympatico.ca
Thu Apr 7 22:27:08 EDT 2005

Nicolas Lehuen wrote:
> On Apr 7, 2005 10:59 PM, Nicolas Lehuen <nicolas.lehuen at gmail.com> wrote:
>>On Apr 7, 2005 9:39 PM, Jim Gallacher <jg.lists at sympatico.ca> wrote:
>>>Nicolas Lehuen wrote:
>>>>Your code seems perfect to me. We could indeed add an extra hash to
>>>>the directory name so that all sessions do not end in the same
>>>>directory ; but I guess this is not needed on modern FS like ReiserFS
>>>>or WinFS.
>>>>Also, the unlink call in do_delete needs an "os." to be correct...
>>>>If everybody is OK I could integrate your class into the Session.py
>>>>module, so that it becomes a standard session implementation in the
>>>>next release.
>>>Shouldn't a lock be aquired and released before reading and writing the
>>>session to a file?
>>Yeah, of course, though we could rely on the native filesystem locking
> [switching to python-dev]
> Woops, sorry, I did not see that the locking problem is handled in
> BaseSession. From what I read in the source code, the locking is
> handled with the granularity of one lock per session, am I right ? So,
> as we have one file per session, we can reuse the same locking
> mechanisms in do_load, do_save and do_delete. Does this sound OK to
> you ?

I read it the same way. Why not borrow the locking mechanism used by 
DbmSession? For example:

def do_save(self, dict):
     _apache._global_lock(self._req.server, None, 0)
     fp = file('%s/mp_sess_%s' % (tempdir, self._sid), 'w+')
         cPickle.dump(dict, fp)
         _apache._global_unlock(self._req.server, None, 0)

> I've seen a few problems in your implementation, so I've took the
> liberty of modifying it I've checked it in so that anybody with commit
> rights can modify the code. Here it is :
> http://svn.apache.org/repos/asf/httpd/mod_python/trunk/lib/python/mod_python/FileSession.py
> Basically, I've added a few try...finally to make sure that opened
> files are closed, but I've not done anything yet about the tempdir
> issue, the locking issue or changing the pickling protocol. It's
> coming soon.

I've also hacked together a (non-working) version that handles the 
locking and the tempdir issue. Brain a little fuzzy right now, but I'll 
fix it tomorrow and post it - unless you get to it first, Nicolas - :)


More information about the Mod_python mailing list