This post originated from an RSS feed registered with Ruby Buzz
by Jamis Buck.
Original Post: Making CGI Rails Faster
Feed Title: the buckblogs here
Feed URL: http://weblog.jamisbuck.org/blog.cgi/programming/index.rss
Feed Description: Jamis Buck's corner of the blogging universe. Mostly about ruby, but includes ramblings on a variety of topics.
Rails’ preferred installation method is RubyGems, a convenient, powerful utility for installing Ruby libraries and applications. Unfortunately, that convenience comes at a price—loading a library via RubyGems adds some overhead. Recent releases of RubyGems have made some good progress in reducing that overhead, but it still exists.
Rails, being (by default) a gem-dependent application, incurs that overhead every time you load the app “clean” (ie, not under FCGI or such). For example, my in-progress financial package manager (Budget-Wise) took about 2.4 seconds just to load the login screen!
I found that by bypassing RubyGems altogether, the load time was cut by more than half, from 2.4 seconds to just over 1.1 seconds. If you run Rails in CGI mode and want an option for speeding your response time, consider making the following change to your environment.rb file:
In other words—just comment out the part that requires the gems, and then manually add the necessary directories to your load path. Then, just require those libs you need explicitly.
The drawback: you have to change your environment.rb file every time you upgrade any part of rails, but if that’s not an issue, you might find this a worthy enhancement to your development cycle. Of course, if you are using WEBrick or FCGI, this isn’t an issue at all since the gem require only happens once. You’ll only really be benefited if you use Rails in CGI mode.