The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Making CGI Rails Faster

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jamis Buck

Posts: 184
Nickname: minam
Registered: Oct, 2004

Jamis Buck is a C/Java software developer for BYU, and hacks in Ruby for fun.
Making CGI Rails Faster Posted: Jan 22, 2005 11:32 AM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jamis Buck
Latest Posts From the buckblogs here

Advertisement

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:


  # Require Rails gems.
  #require 'rubygems'
  #require_gem 'activerecord'
  #require_gem 'actionpack'
  #require_gem 'actionmailer'
  #require_gem 'rails'

  GEM_DIR = "/usr/local/lib/ruby/gems/1.8/gems" 

  $:.push "#{GEM_DIR}/activerecord-1.5.1/lib" 
  $:.push "#{GEM_DIR}/actionpack-1.3.1/lib" 
  $:.push "#{GEM_DIR}/actionmailer-0.6.1/lib" 
  $:.push "#{GEM_DIR}/rails-0.9.4.1/lib" 

  require 'active_record'
  require 'action_controller'
  require 'action_view'
  require 'action_mailer'

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.

Read: Making CGI Rails Faster

Topic: Make your Ta-da list today Previous Topic   Next Topic Topic: Ruby.org Mockup

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use