[mod_python] Sessions performance and some numbers

Nicolas Lehuen nicolas.lehuen at gmail.com
Thu Apr 7 13:03:39 EDT 2005


Grisha, the dbm implementation is pickling to the dbm which stores in
a file. It's an extra layer of implementation, so reduced performances
can be expected.

BTW, both implementation could save time and space by pickling with
the protocol 2 instead of the protocol 0.

Regards,
Nicolas

On Apr 7, 2005 6:26 PM, Gregory (Grisha) Trubetskoy
<grisha at modpython.org> wrote:
> 
> There is no way that pickling stuff into a file is faster than a dbm.
> 
> Do you know which DBM implementation you were using in your tests?
> 
> Grisha
> 
> On Thu, 7 Apr 2005, dharana wrote:
> 
> >
> >
> > Graham Dumpleton wrote:
> >>
> >> On 07/04/2005, at 8:08 PM, dharana wrote:
> >>
> >>> If you want I can send my modified Session.py with the new FileSession
> >>> class for review.
> >>
> >>
> >> There probably shouldn't have been a need for you to copy/modify the
> >> actual
> >> Session.py file which came with mod_python as your derived version could
> >> live quite happily in its own module and simply used the installed Session
> >> module.
> >>
> >
> > I presumptuously thought that it could fit into the official mod_python
> > package due to it's high performance when compared to DbmSession.
> >
> >>
> >> Anyway, by all means post your code as sure it will be of interest to
> >> someone, if not now then maybe in the future. If there are any problems
> >> in what you have done, someone is also bound to point it out.
> >>
> >
> > Here it goes. Please point out any obvious problem. Apart from being new to
> > mod_python I'm also new to Python in general. For example, I don't think the
> > exception handling I've put is completely correct.
> >
> >
> > In anticipation for any possible attachment problems i pasted it directly. (I
> > have read PEP 0008 and the 4 spaces indentation level recommendation but I'm
> > in a hurry right now, sorry.)
> >
> >
> > --- FileSession.py -----------------------------------------------------
> > import cPickle
> > import tempfile
> >
> > from mod_python import Session
> >
> > tempdir = tempfile.gettempdir()
> >
> >
> > class FileSession(Session.BaseSession):
> >
> >  def __init__(self, req, sid=0, secret=None, timeout=0, lock=1):
> >
> >    Session.BaseSession.__init__(self, req, sid=sid, secret=secret,
> >                         timeout=timeout, lock=lock)
> >
> >  def do_cleanup(self):
> >    import os
> >
> >    # is there any faster way of doing this?
> >    for f in os.listdir(tempdir):
> >      if f.find('mp_sess_', 0, 11) == -1:
> >        continue
> >
> >      fp = file('%s%s' % (tempdir, f))
> >      dict = cPickle.load(fp)
> >      fp.close()
> >
> >      if (time() - dict['_accessed']) > dict['_timeout']:
> >        os.unlink('%s%s' % (tempdir, f))
> >
> >
> >  def do_load(self):
> >    try:
> >    # again, is there a more pythonic way of doing this check?
> >      fp = file('%s/mp_sess_%s' % (tempdir, self._sid))
> >    except Exception:
> >      return None
> >    else:
> >      try:
> >        data = cPickle.load(fp)
> >        fp.close()
> >        return data
> >
> >      except Exception:
> >        fp.close()
> >        pass
> >
> >
> >  def do_save(self, dict):
> >    fp = file('%s/mp_sess_%s' % (tempdir, self._sid), 'w+')
> >    cPickle.dump(dict, fp)
> >    fp.close()
> >
> >
> >  def do_delete(self):
> >    try:
> >      unlink('%s/mp_sess_%s' % (tempdir, self._sid))
> >    except Exception:
> >      pass
> > ------------------------------------------------------------------------
> >
> > --
> > Juan Alonso
> > http://gamersmafia.com | http://laflecha.net
> >
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list