[mod_python] Sessions performance and some numbers

Nicolas Lehuen nicolas.lehuen at gmail.com
Fri Apr 8 02:16:05 EDT 2005


On Apr 8, 2005 4:27 AM, Jim Gallacher <jg.lists at sympatico.ca> wrote:
> 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:
> >>>
> >>>>Hi,
> >>>>
> >>>>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
> >>capabilities.
> >>
> >>Regards,
> >>Nicolas
> >
> >
> > [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+')
>      try:
>          cPickle.dump(dict, fp)
>      finally:
>          fp.close()
>          _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 - :)
> 
> Regards,
> Jim
> 
> 

Well, I had a go last night, but my brain was a little fuzzy too, so I
don't mind a double-check. I didn't use the global lock n° 0, which
would serialize all access to all sessions, but a lock named after the
session, just like it was done in BaseSession.lock() and
BaseSession.unlock().

BTW, I'm not sure I understand the current locking system in
BaseSession : it looks to me as if the lock on the session was held
for the duration of the whole request (the lock being released during
the request cleanup). Grisha, is this true ? If this is so, then there
is no need to lock anything in FileSession, as the BaseSession already
ensure a proper level of locking.

Regards,
Nicolas



More information about the Mod_python mailing list