Published

Improving Session Performance in Rails

Ruby on Rails includes some options for handling sessions (see overview by Stefan Kaes (PDF)). Unfortunately the default ActiveRecord session handler is relatively slow which may have a big impact on your application (sessions tend to accumulate quickly). Fortunately for all of us, Stefan has created an alternative MySQL session handler whith hard coded SQL statements. His version is much quicker.

If your application uses the standard session handler there is really no reason not to implement Stefan’s solution. However, to make it work with the default session table created by Rails 1.1.2 you have to do some minor modifications (at least in version 0.2):

Published

In addition to the sql_session_store.rb file, I also had to modify statements referring to the sessid column in the mysql_session.rb file. I am somewhat of a newbie and I got stuck on this one for a while.