This project is archived and is in readonly mode.

#92 ✓stale
Andreas

[FEATURE] More efficient session handling

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

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.

Comments and changes to this ticket

  • Frederick Cheung

    Frederick Cheung May 2nd, 2008 @ 02:35 AM

    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)/

  • Andreas

    Andreas May 2nd, 2008 @ 01:12 PM

    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...

  • josh

    josh July 17th, 2008 @ 01:04 AM

    • State changed from “new” to “stale”
    • Tag set to actionpack, session

    Got patch?

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages