[mod_python] Session Storage : memory, file, dbm....Mysql?

Martijn Moeling martijn at xs4us.nu
Mon Nov 27 06:08:15 EST 2006


Hi,

I am building an application framework (yes!) with very specific needs.
One of the main problems I run into is session management, I'll explain:

My application (Running on Fedora) Is prepared for multiple front-end
servers communicating on an Internal backbone to a database server.
Think of it as some sort of web based Citrix able to run on all browsers
without the need of client-side software installation. Fully
programmable in python (even the front-end) and if the time gets there
even Visual. So build a browser based application within an application
with central storage and management. Mod Python is used to implement a
part of an OS if you wish to call it that way.

The front ends will be Apache servers with mod_python connected to the
Internet using round-robin DNS (Multiple ip addresses for one Host), In
theory a PC will do a DNS lookup and get the address of one of the
front-end, this PC will keep this address until the TTL makes it expire
in the DNS caches along the way, there is no problem since each session
will be served by the same front end.

But I need to find a way to get the session information into the MySQL
database in the backend server to enable central monitoring and inter
user communications etc. (think of a Messenger online userlist as an
example)

I can of course write stuff to maintain this sort of data in the MySQL
database but what if the session ends other than a user logging out
nicely (broken connection, browser close etc.)

It would be nice to have a MySQLsession object, an extra parameter could
be added like a MySQLdb cursor object, or am I wrong and are sessions
maintained by Apache (since modpython does not seem to keep track of
Session closing), or is there any way to "list" active sessions from
within modpython, so I can let the backend server send an http request
to the front-end and doing something like:
http://frontend1/getsessionlist which returns a comma separated list of
active session id's, so the stale session records in the database can be
removed.

I have been researching Session.py
Where I interestingly found:
(from def dbm_cleanup(data):)

If (time.time() - dict[_accessed]) > dict["_timeout]:
	old.append(key)
..
..
..
For key in old:
	Del db[key]

If I understand this right, this means that this is done to see if the
session is ended right? So It I alter Session.py I could make my own
MySQL Session right?

Would there be anyone else Interested in a MySQLSession object and what
do I need to take into account when modifying it?


Please feel free to comment on any of this,

Martijn Moeling



More information about the Mod_python mailing list