[mod_python] Session Cleanups - Still a mystery

Krishna Srinivasan krishna at ironport.com
Thu Jun 3 20:17:45 EDT 2004


Greetings.

When I said "cleanup", I meant session-deletion
when I explicitly call "sess.invalidate()".
(I apologize for the confusion).

I wrote some print(to file) statements into the
Session.py file and tested my app. Just one user(me),
doing one set of transactions - one login, few actions,
logout.

I find that when I call "sess.invalidate()" the code
goes all the way to "do_delete()" and then fails in
the try-clause (due to KeyError). 'self._sid' is not
there in the dbm. Why is this failing ? I see that
the code just does a 'pass' on that (key)error.

And I put in a print to show my session-id when it's
new - however, during one session, I get back two prints
- so there are two sessions. Could it be because of a
request to a different server for, say, an image ??
[Just a guess]

Here is one more question, I cannot read the
values of the dict from a python cli.

prompt> cd /tmp
prompt> python
>>> import bsddb
>>> a = bsddb.hashopen("mp_sess.dbm", "r")
>>> a.keys()
['55d6151503a8bb61251ce6027fbc065dd', 'afea89bd5eb5d836ec4939615dffa8b22']
>>> a['55d6151503a8bb61251ce6027fbc065dd']
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  KeyError: 55d6151503a8bb61251ce6027fbc065dd
>>>

However, I could say something like,
>>> a.first()
And I get back a pickled-object as str.
[I could keep doing a.next() too and it works]

Am I doing something wrong here ??

> Session cleanups should happen randomly

Thanks, I finally did RTFM and figured that out.
(and how to set it to a different number if I need to
via Session.CLEANUP_CHANCE)

> How big is the dmb getting that you are concerned with space?

Like I said, my problem is session-deletion is not getting
done properly. And since I store large-objects in the
session-dictionary, it gets large. And that's how I
noticed.

Looking forward to helpful suggestions/hints,

Thanks,
Krishna.





On Thu, 3 Jun 2004, Gregory (Grisha) Trubetskoy wrote:

> Date: Thu, 3 Jun 2004 20:35:32 -0400 (EDT)
> From: "Gregory (Grisha) Trubetskoy" <grisha at modpython.org>
> To: Krishna Srinivasan <krishna at ironport.com>
> Cc: Modpython <Mod_python at modpython.org>
> Subject: Re: [mod_python] Session Cleanups - Still a mystery
>
>
> Session cleanups should happen randomly with about 1 in 1000 chance (1 out
> of 1000 session requests will trigger a cleanup). During a cleanup, all
> expired sessions should get deleted from the dmb.
>
> How big is the dmb getting that you are concerned with space?
>
> Grisha
>
> On Thu, 3 Jun 2004, Krishna Srinivasan wrote:
>
> >
> > Greetings.
> >
> > Can someone please explain how exactly sessions are cleaned up ?
> > I am seeing a constant increase in the /tmp/mp_sess.dbm though
> > I believe I am doing a 'delete' (and cleanup).
> >
> > I had posted this question some days back, here :
> > http://modpython.org/pipermail/mod_python/2004-May/015706.html
> >
> > For each session, whenever a user does some action (which internally
> > involves creating objects and storing them in the session dictionary),
> > I do a "req.sess.save".
> > [Where req.sess = Session.Session()]
> >
> > And then when they do a 'logout' - I do this :
> > req.sess.delete()
> >
> > However,  the size of mp_sess.dbm in /tmp is on the rise
> > always. Can someone please tell me what else I should be doing ?
> >
> > I store everything in a simple dictionary.
> > req.sess["mydict"] = <mydictionary>
> > The 'mydictionary' object keeps expanding based on user-actions.
> > I even do a 'del' to remove objects from this 'mydictionary'
> > object to keep the space down.
> >
> > System - FreeBSD 4.7 - Apache 2.0.48 - Python 2.2.3 - ModPy 3.1.3
> >
> > Please let me know how to fix this.
> >
> > Thanks,
> > Krishna.
> >
> > _______________________________________________
> > 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