quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gregory (Grisha) Trubetskoy" <gri...@modpython.org>
Subject Re: [mod_python] Sessions performance and some numbers
Date Thu, 07 Apr 2005 17:22:37 GMT


On Thu, 7 Apr 2005, Nicolas Lehuen wrote:

> Grisha, the dbm implementation is pickling to the dbm which stores in
> a file.

Indeen it does, I some for reason did not think about it.

As a sidenote, I think this shows how important it is to always explain 
everything in English (rather than code) and have lots of comments.

With this implementation - is there still any advantage to usnig a DBM at 
all?

I still think that security needs to be addressed slightly better - 
perhaps explicitely setting permissions - perhaps putting sessions in a 
subdirectory only readable, writable and executable by apache user would 
make it a bit cleaner. The current mod_python DBMSession does not 
explicitely set permissions which is a problem. (though inserting a bad 
pickle into dbm is slightly harder than just just writing a file and then 
calling a url that you know will cause mod_python to attempt to unpickle 
it)

Also, I don't see any locking here, I think it's needed.

Lastly - this discussion belongs on the python-dev@httpd list really :-)

Grisha


> 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@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@modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
>>
>

Mime
View raw message