Rails 3应用服务器启动时间很长 [英] Rails 3 app server startup time is long
问题描述
更新2 这是Ruby 1.9.2加载文件的方式的已知错误/功能。 http://twitter.com/#!/rails/status/72801149769621504
UPDATE 2 This is a known bug/feature with the way Ruby 1.9.2 loads files. http://twitter.com/#!/rails/status/72801149769621504
更新:这最初是一个问题,但是经过一番努力之后,我认为它可能无法修复。我想我会发布此消息,以防万一其他人看到相同的东西并且想知道滑轨和捆扎机内部发生了什么。
update: This started out as a question, but after working on this for a bit I think it might not be fixable. I figured I would post this in case anyone else is seeing the same thing and is wondering what is going on inside rails and bundler.
其他人看到的加载时间较长吗?他们的Rails 3应用程序?我将计时器放在environment.rb,application.rb,boot.rb和railties / lib / rails / initializable.rb中。时间以秒为单位,经过时间是自上次记录时间以来的时间。生产加载时间需要更长的时间。部分原因是硬件较少,也来自eager_load! (也许来自Thin vs Mongrel)。看来Bundler占用了很大的加载时间,我想这是可以预期的。我在开发人员和产品中测试了其中一个应用程序,在开发人员中测试了一个空白应用程序。我测试了2个应用服务器,只是看它是否是Thin引起的。我在产品中也看到了与Passenger相似的情况(这使得2.2.15中的生成行为无法使用b / c)。我在Edge Rails上进行了测试,开发人员的性能从14.5s到14.2s稍差一些。如果删除测试依赖项,则可以节省2-3秒,但这对运行测试没有帮助。我想等待5分钟让所有Thin实例重新启动以及等待15秒才能进行测试只是有点烦人,但是由于我在Rails 3上获得了生产力,因此这是一个可以接受的折衷方案。加快速度的想法,我无所不能。测试结果如下:
Is anyone else seeing long load times in their Rails 3 apps? I placed timers in environment.rb, application.rb, boot.rb and railties/lib/rails/initializable.rb. Time is measured in seconds and the elapsed time is the time since the last recorded time. Production load time takes a bit longer. Partly because of less hardware and also from eager_load! (and maybe from Thin vs Mongrel). Looks like Bundler is taking up a big chunk of the load time and I guess that is to be expected. I tested one of the apps in dev and prod, and one blank app in dev. I tested 2 app servers just to see if it was Thin causing it. I am also seeing similar things with Passenger in prod (which makes it unusable b/c of spawning behaviour in 2.2.15). I tested against edge Rails and the performance in dev was slightly worse 14.5s vs 14.2s. If I remove my testing dependencies it saves 2-3 seconds, but this does not help when I am running tests. I guess it is just a bit annoying waiting 5 minutes for all my Thin instances to restart and also waiting 15 seconds before my tests run, but it is an acceptable tradeoff at this point because of productivity I gain with Rails 3. If anyone has any ideas to help speed things up, I am all ears. Here are the test results:
注意:我在Rails 2.3中的应用在不到3秒的时间内就在dev中加载了(尽管我已经进行了一些转换)自从移至rails3以来,向引擎添加了一些代码,并添加了haml和twitter_oauth gem。
Note: my app in Rails 2.3 loaded in less than 3 seconds in dev (although I have converted a little bit of the code to engines and added haml and twitter_oauth gems since the move to rails3)
**所有使用Rails 3RC和Ruby 1.9.2rc2进行的测试
**All tests conducted with Rails 3RC and Ruby 1.9.2rc2
带有Thin的产品-CentOS 5.5,Rackspace云服务器2GB实例
测试应用程序#1具有24个gem依赖项
Prod with Thin - CentOS 5.5, Rackspace cloud server 2GB instance
Test App #1 with 24 gem dependencies
start env.rb - Total=0
start app.rb - 0.00110546 elapsed. Total=0.001180052
start boot.rb - 0.000600488 elapsed. Total=0.00178644
end boot.rb - 0.7935529 elapsed. Total=0.795507318
start require rails/all - 0.000189127 elapsed. Total=0.795701199
end require rails/all - 1.086998364 elapsed. Total=1.882735263
start Bundler require - 0.000109708 elapsed. Total=1.88285043
end Bundler require - 8.955853243 elapsed. Total=10.838746673
end app.rb - 0.062975913 elapsed. Total=10.901753753
# /railties-3.0.0.rc/lib/rails/initializable.rb
start run initializers - 0.000145906 elapsed. Total=10.901910186
load_environment_config - 0.116689774 elapsed. Total=11.018632298
initialize_cache - 0.246161343 elapsed. Total=11.320543397
active_record.initialize_database - 0.080047485 elapsed. Total=11.400961893
bootstrap_hook - 1.034189984 elapsed. Total=12.451309104
active_support.initialize_time_zone - 1.969821814 elapsed. Total=14.448777651
action_controller.set_configs - 0.594991537 elapsed. Total=15.044692126
will_paginate.active_record - 0.324460921 elapsed. Total=15.386837641
will_paginate.action_view - 1.904889132 elapsed. Total=17.328981523
add_view_paths - 0.087811847 elapsed. Total=17.42011881
load_init_rb - 0.151282681 elapsed. Total=17.709093173
load_init_rb - 0.362241273 elapsed. Total=18.071865548
load_config_initializers - 0.144051305 elapsed. Total=18.217433492
build_middleware_stack - 2.569453884 elapsed. Total=20.826842081
eager_load! - 4.165919064 elapsed. Total=24.99280168
finisher_hook - 0.48795935 elapsed. Total=25.480807439
repopulate_roles - 0.504085662 elapsed. Total=25.984901297
end run initializers - ~0.00005 elapsed. Total=25.985617783
end env.rb - ~0.00006 elapsed. Total=25.985683903
带Mongrel的Dev-Max OSX 10.5.8、2.66 Core2duo,4GB RAM
具有24个gem依赖项的
测试应用程序#1
Dev with Mongrel - Max OSX 10.5.8, 2.66 Core2duo, 4GB RAM
Test App #1 with 24 gem dependencies
start boot.rb (Bundler.setup) - 2.0e-05 elapsed. Total=3.1e-05
end boot.rb (Bundler.setup) - 2.352435 elapsed. Total=2.352915
start app.rb - 0.084945 elapsed. Total=2.437866
start require rails/all - 0.000181 elapsed. Total=2.438049
end require rails/all - 0.489425 elapsed. Total=2.927485
start Bundler.require(:default, Rails.env) - 5.6e-05 elapsed. Total=2.927544
end Bundler.require(:default, Rails.env) - 5.16162 elapsed. Total=8.089177
end app.rb - 0.025972 elapsed. Total=8.11516
start env.rb - 0.084153 elapsed. Total=8.199329
# /railties-3.0.0.rc/lib/rails/initializable.rb
start run_initializers - 0.002709 elapsed. Total=8.202042
initialize_cache - 0.089231 elapsed. Total=8.518005
bootstrap_hook - 0.602342 elapsed. Total=9.192564
active_support.initialize_time_zone - 0.901676 elapsed. Total=10.10115
action_controller.set_configs - 0.375864 elapsed. Total=10.477565
will_paginate.active_record - 0.207447 elapsed. Total=10.694479
will_paginate.action_view - 1.041412 elapsed. Total=11.75974
load_init_rb - 0.051938 elapsed. Total=11.879547
load_init_rb - 0.082936 elapsed. Total=12.001311
load_init_rb - 0.18798 elapsed. Total=12.189555
load_config_initializers - 0.079461 elapsed. Total=12.269971
build_middleware_stack - 1.390042 elapsed. Total=13.729273
finisher_hook - 0.082274 elapsed. Total=13.811648
repopulate_roles - 0.350287 elapsed. Total=14.161941
end run_initializers - 3.0e-06 elapsed. Total=14.177869
end env.rb - 0.000127 elapsed. Total=14.178002
Dong与Mongrel
测试应用程序#2具有2个gem依赖项
Dev with Mongrel Test App #2 with 2 gem dependencies
start boot.rb (Bundler.setup) - Total=0
end boot.rb (Bundler.setup) - 1.724158 elapsed. Total=1.724199
start app.rb - 0.041006 elapsed. Total=1.765211
start require rails - 0.000151 elapsed. Total=1.765364
end require rails - 0.360051 elapsed. Total=2.125426
start Bundler.require(:default, Rails.env) - 5.5e-05 elapsed. Total=2.125485
end Bundler.require(:default, Rails.env) - 0.008396 elapsed. Total=2.133889
end app.rb - 0.007805 elapsed. Total=2.141704
start env.rb - 0.16541 elapsed. Total=2.307128
start run_initializers - 0.00031 elapsed. Total=2.307442
load_active_support - 0.24045 elapsed. Total=2.579421
active_support.initialize_time_zone - 0.206237 elapsed. Total=2.837663
action_controller.deprecated_routes - 0.210291 elapsed. Total=3.048634
build_middleware_stack - 0.220663 elapsed. Total=3.273035
end run_initializers - 3.0e-06 elapsed. Total=3.29339
end env.rb - 8.7e-05 elapsed. Total=3.293483
推荐答案
由于这是一个相当老的问题:您是否在发行版中对其进行了测试版本的Rails 3?
Since this is a fairly old question: Have you tested it with the release version of Rails 3?
那是很长一段时间,但最终毫无意义。我的Rails应用程序一次只能运行几个月,因此只占总运行时间的1%的一小部分。
That is a long time but ultimately meaningless. My rails apps stay up for months at a time so that is a fraction of a fraction of 1 percent of the total runtime.
您是否有大量依赖于Bundler的依赖项必须处理?在任何环境下,我都可以在不到2秒的时间内启动Rails 3应用程序,但是我使用的第三方gem很少。
Do you have a ton of dependencies that Bundler has to deal with? I can get my Rails 3 app started in less than 2 seconds in any environment, but I use very few third party gems.
这篇关于Rails 3应用服务器启动时间很长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!