hakkr has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

With mod_perl shared variables you can store information in the web server between requests. This is kind of like how java application servers work storing session beans in the container.

So my question is do I have to roll my own mod_perl session code or is there a particular module well suited with standard session features like cookie management, session id encrypting, timeouts etc

Obviously for performance reasons I'd like to hit any storage system as little as possible for each request so storing session info and related cached user info in memory seems like a good idea as long as it can be 'garbage collected' when sessions expire so the server does not run out of memory.

So how do you/would you do this? which modules are best for caching info in memory? Thanks

Replies are listed 'Best First'.
Re: mod_perl session beans
by Thilosophy (Curate) on Jan 10, 2005 at 12:18 UTC
    The obvious problem with caching things in memory in mod_perl is that every Apache process has its own Perl interpreter , that they do not share (read-write) memory, and that you have no control over which process handles which request. All this makes in-memory session tracking a little difficult.

    You could have a look into using shared memory, for example with Apache::Session::SharedMem.

    Maybe this has changed in mod_perl2.

      Hi,

      Yes the only problem with shared memory variable is they have to be read only or they wont stay shared.

      Shame Apache::Session::SharedMem is not production ready, maybe it will make a good starting point anyway thanks

        I expect Apache::Session::SharedMem to be very slow, since it is built on the very slow IPC::Cache module. The caching modules I mentioned below are at least ten times as fast.
Re: mod_perl session beans
by perrin (Chancellor) on Jan 10, 2005 at 22:58 UTC
    Most of the frameworks have some kind of integrated session system, or you can use Apache::SessionManager. There are various other options on CPAN for different types of tracking (URI vs. cookie), etc.

    Caching between processes is tricky, and has to involve some kind of IPC. The modules Cache::FastMmap and BerkeleyDB are good for local use, while Cache::Memcached or careful use of MySQL are the fastest for clustered caching.

      Many thanks, I think a combination of Cache::Memcached and some choice SQL for updating the values stored should work well especially as scalability is important.

      I use CGI::Aplication and am interested in AxKit, which framework do you think is the best?

        The framework you will like best depends greatly on how you like to work. AxKit is a good one for people who want to work primarilly with XML. Apache::ASP is a good one people who like to use in-line perl code in pages. OpenInteract is good for people who want an MVC approach. Take a look and figure out which one is best suited to your style of working.