导轨3.2的加载时间缓慢 - 调试显示导轨加载两次

时间:2012-02-29 19:47:04

标签: ruby-on-rails-3 ruby-on-rails-3.1 rspec-rails

我的rails 3.2环境用于加载非常慢,有时需要超过100秒的时间 - 运行测试,控制台,服务器和生成器。所以我从1.9.2升级到ruby 1.9.3,加载时间高达25-30秒,事情变得更好。

然后我发现了这篇文章 - https://stackoverflow.com/a/5071198/392345 并使用此技巧来检查我的宝石加载时间

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

结果如下 -

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

从警告DRb服务器没有运行之后可以看出,它再次加载所有宝石,这是正常的吗?还是真的装了两次?

任何rails 3.2 app的平均加载时间是多少?

1 个答案:

答案 0 :(得分:0)

更正spec_helper.rb文件,该文件应删除加载两次行为。试一试。

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