Follow Along as I Stumble on the Path to Learning RoR

Performance

Getting Thin Gem to Work on Heroku When you Develop in Windows

Upgrading to Heroku’s Cedar stack, I had to install the Thin gem to prevent my app from running on Web Brick.  On the Bamboo stack this is injected so I need not worry, but with Cedar you need to install all the gems you need.

The problem is that I work on Windows in development and that one of the dependencies for the Thin gem is the Eventmachine gem.  However, Eventmachine isn’t really geared towards Windows environments (except gem install eventmachine –pre), so everytime went to run bundle install the install would fail because the dependency, eventmachine 0.12.10 could not install.

However, Heroku helped me find a solution.

Add this to the gemfile

group :production do
gem ‘thin’
end

and instead of ‘bundle install’, run ‘bundle install –without production’

Advertisements

Caching Rails 3 on Heroku

To learn about caching, I used a few different resources.

The three basic types of caching are:

  • page caching – mainly for static pages, it will not work if any filters are applied to the controller of the page (ie authorizations)
  • action caching – typically what you’d used to cache a page if they have filters
  • fragment caching – allows for caching of blocks of html on a page (if you can’t cache the whole page) or for partials

Since I’m on Heroku, the first place to learn was Heroku’s documentation.  It’s important to read the Heroku docs first because some standard Rails functions work differently on Heroku’ platform.  Mainly, for page caching (uses different syntax than standard rails) and action caching (mostly dependent on memcache, so you need to set your app up accordingly).

Overview of caching on Heroku
http://devcenter.heroku.com/articles/caching-strategies

http://devcenter.heroku.com/articles/building-a-rails-3-application-with-the-memcache-addon

There’s also a Rails Guide on Caching (just remember to ignore page caching part):
http://guides.rubyonrails.org/caching_with_rails.html

However, the most extensive (and useful) one for me was from Adam Hawkins at (especially for fragment caching):
http://broadcastingadam.com/2011/05/advanced_caching_in_rails

I also needed to learn about sweepers, in order to observe for changes that would impact another controller’s pages.  This Stack Overflow post helped me learn to put the sweeper in with the models and to ensure that I updated the correct controller:
http://stackoverflow.com/questions/2247410/action-caching-is-not-expiring-correctly-even-when-i-can-see-its-being-called


Consolidating Local Stylesheets and Javascript

For pre-Rails 3.1 apps (3.1 has functionality baked in), it can speed up the load process if your stylesheets and javascripts are consolidated.  Asset Packager is a plugin that helps do this by not only combining these, but also creating a smaller file (less requests and a smaller file to request).

https://github.com/sbecker/asset_packager