[mod_python] session data and shared memory

Jeff Stearns jeffstearns at attbi.com
Sun Jan 12 18:53:37 EST 2003


I've had good success with a dedicated "session server".  It's a small 
python server which stores key/value pairs in memory using a Python 
dictionary.

Each apache child maintains a persistent TCP connection to the server. 
It uses a simple RPC protocol to store and fetch key/value pairs. The 
protocol allows for arbitrary binary data of unlimited size.

The server ages out stale data after it hasn't been used for a while.

I also wrote a tiny client-side connection manager in C which handles 
all the details of making and re-establishing connections.

I've used this in commercial web sites. Performance is excellent 
because overhead is so small. (It was originally developed on an 
ancient SPARC.) I might be able to dig up the source if you're 
interested, but it's not hard to write your own.

-jeff stearns

On Sunday, January 12, 2003, at 05:35 PM, Lex Berezhny wrote:

> hello,
>
> I know the issue of session management has been brought up before, but 
> I
> have a more specific question on the topic. Is there a way to keep
> session state across threads/forked apache processes?
>
> Storing the session state in a database carries a lot of overhead since
> every request requires at least one query.
>
> Another solution I had in mind was to use the ZODB with ZEO, so that
> when a user logs in for example a session object will be created in the
> ZODB. But this seems like a great deal of hoops just to store a few
> attributes of session.
>
> I have also thought about implementing a very basic LDAP like session
> registry service. Each mod_python process would open a connection to
> this registry and be able to share session data with other processes.
>
> Has anyone else faced such a problem? Are there any other ways to
> synchronize data between mod_python instances?
>
> thanks in advance,
>
>  - lex
>
> -- 
> Lex Berezhny <LBerezhny at DevIS.com>




More information about the Mod_python mailing list