Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[FEATURE] More efficient session handling

#92

Problem:

  • Some applications end up with huge amounts of empty sessions.
  • Activating sessions can hurt performance even for requests that do not depend on session information.

Reasons:

  • The session is looked up in the store, even if the request did not contain a session cookie.
  • The session is retrieved from the store, even if the data is not needed for handling the request.
  • After the request the session is created, even if it is empty.
  • After the request the session is saved, even if the data was not changed.

Proposed solution:

  • Look up the session from the store only when the "session" function is called and the client actually submitted a session cookie.
  • Instead of saving an empty session, delete it from the store (or don't create it if it does not yet exist).
  • Save a non-empty session only if it was changed during the request handling.

Reported by Andreas · May 2nd, 2008 @ 02:07 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Frederick Cheung
    Frederick Cheung

    Sounds intriguing. Most of this isn't really relevant if you're using the cookie store, but for everyone else this could be a win.

    Not loading the session until it's first touched is a no brainer. I'd be wary about not saving the session/deleting empty sessions though, as I reckon there's scope for getting your self into trouble if you're handling simultaneous requests from the same user (although to be fair the session stores that ship with rails are all vulnerable to that)/

    May 2nd, 2008 @ 02:35 AM

  2. Andreas
    Andreas

    I know, there might be some problems depending on how you want the sessions to behave transaction-wise, but Rails sessions don't seem to have a defined behaviour for concurrent requests anyway.

    Another problem with not saving unchanged session is that the timestamp does not get updated.

    I just found this project which implements some of the changes I suggested: http://code.google.com/p/rails-f...

    May 2nd, 2008 @ 01:12 PM

  3. josh
    josh
    • State changed from new to stale
    • Tag set to actionpack, session

    Got patch?

    July 17th, 2008 @ 01:04 AM