2

My rails 3.2 environment used to load very slow, sometimes taking more than 100sec for all things - running tests, console, server and generators. So I upgraded to ruby 1.9.3 from 1.9.2 and things got little better with load times of upto 25-30sec.

Then I came across this post - https://stackoverflow.com/a/5071198/392345 and used this trick to check my gems load times

puts Benchmark.measure("require #{file}") {
  Kernel.require file
}.format("%n: %t %r")

results of this are as follows -

require rails: 0.000000 (0.000234)
require mysql2: 0.000000 (0.006835)
require uglifier: 0.080000 (0.067291)
require sass-rails: 0.010000 (0.017783)
require jquery-rails: 0.010000 (0.002467)
require devise: 0.840000 (0.855009)
require haml: 0.230000 (0.223640)
require activeadmin: 1.510000 (1.525017)
require paperclip: 0.170000 (0.179652)
require twitter-bootstrap-rails: 0.250000 (0.249430)
require config_reader: 0.000000 (0.001339)
require exception_notifier: 0.530000 (0.528327)
require httparty: 0.130000 (0.134162)
require uuid: 0.770000 (0.761883)
require useragent: 0.040000 (0.043415)
require aws-sdk: 0.090000 (0.093158)
require newrelic_rpm: 0.620000 (0.628278)
require omniauth-openid: 0.630000 (0.633982)
require c2dm: 0.040000 (0.037214)
require thin: 0.100000 (0.103781)
require rspec-rails: 0.000000 (0.001094)
/home/rtdp/.rvm/rubies/ruby-1.9.3-p125/bin/ruby -S rspec ./spec/model/app_spec.rb
No DRb server is running. Running in local process instead ...
require rails: 0.000000 (0.000184)
require mysql2: 0.020000 (0.018071)
require uglifier: 0.070000 (0.072325)
require sass-rails: 0.020000 (0.019724)
require jquery-rails: 0.040000 (0.042998)
require devise: 0.880000 (0.874613)
require haml: 0.200000 (0.212278)
require activeadmin: 1.600000 (1.612621)
require paperclip: 0.160000 (0.157090)
require twitter-bootstrap-rails: 0.260000 (0.260186)
require config_reader: 0.010000 (0.001366)
require exception_notifier: 0.490000 (0.496320)
require httparty: 0.100000 (0.095423)
require uuid: 0.690000 (0.695459)
require useragent: 0.010000 (0.011390)
require aws-sdk: 0.110000 (0.113553)
require newrelic_rpm: 0.480000 (0.481167)
require omniauth-openid: 0.600000 (0.609401)
require c2dm: 0.010000 (0.001735)
require rspec-rails: 0.000000 (0.000735)
require spork: 0.000000 (0.000175)
require factory_girl_rails: 0.160000 (0.170655)
.....

Finished in 0.28406 seconds
5 examples, 0 failures
bundle exec rake  26.12s user 1.20s system 81% cpu 33.504 total

As can be seen from this after that warning that DRb is server is not running, it again loads all the gems, so is this normal ? or does it really loading it twice ?

what is average load time for any rails 3.2 app ?

Community
  • 1
  • 1
rtdp
  • 2,067
  • 1
  • 17
  • 32
  • What command are you using to run RSpec? Do you have a .rspec file in either the project or home directory which has the --drb option included? Are you using Spork and is it failing to load? – nmott Mar 04 '12 at 07:41
  • I have .rspec and i am using spork. As my apps loads very slowly, i wanted to troubleshoot that. Even spork helps a bit while testing, other things like - migrations, scaffold generations and rakes are quite slow as well. – rtdp Mar 04 '12 at 09:47
  • Can you post your `spec_helper.rb` and `.rspec` files. – nmott Mar 05 '12 at 23:24
  • my spec_helper is here- https://gist.github.com/78634ec572c1cbf40490 and .rspec has - `--color --drb ` in it. – rtdp Mar 06 '12 at 13:00
  • Doesn't look like your `spec_helper.rb` is setup correctly - I will add one that should work in an answer below. – nmott Mar 07 '12 at 02:51

1 Answers1

0

Corrected spec_helper.rb file which should remove the loading twice behaviour. Give it a try.

spec_helper.rb

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|

    config.fixture_path = "#{::Rails.root}/spec/fixtures"

    config.use_transactional_fixtures = true

    config.infer_base_class_for_anonymous_controllers = false
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.
end
nmott
  • 9,454
  • 3
  • 45
  • 34