2012-02-29 81 views
2

我的導軌3.2環境用於加載非常慢,有時會花費超過100秒來運行測試,控制檯,服務器和生成器。所以我從1.9.2升級到1.9.3,並且在25-30sec的加載時間情況下,情況變得更好了。導軌3.2的加載時間慢 - 調試顯示導軌加載兩次

然後,我遇到了這個職位 - 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應用程序的平均加載時間?

+0

您正在使用什麼命令運行RSpec的?您是否在包含--drb選項的項目或主目錄中有.rspec文件?您是否在使用Spork並且無法加載? – nmott 2012-03-04 07:41:43

+0

我有.rspec,我正在使用spork。由於我的應用程序加載非常緩慢,因此我想解決這個問題。即使在測試過程中,spork也會有所幫助,但其他一些事情 - 遷移,腳手架世代和耙子也非常緩慢。 – rtdp 2012-03-04 09:47:31

+0

你可以發佈你的'spec_helper.rb'和'.rspec'文件。 – nmott 2012-03-05 23:24:07

回答

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