简体   繁体   中英

Rails server start up time is very slow with upgrade

I am trying to upgrade rails app from v3 to v4. In v3, the server start time is less than a minute. but in v4, it is taking more than 30 mins. In logs, i can see that for each server start,

1/10 preloading assets...
2/10 preloading assets...
.
.
10/10 preloading aseets...
done

is being logged and this is the part taking up 99% of the time. I believe assets are being compiled every time while loading the classes. could someone please let me know which config is causing this ?

I have tried most of the suggested solutions related to asset config in stackoverflow but doesnt seem to get resolved.

current config:

config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.reload_classes_only_on_change = true
config.assets.digest = false
config.assets.debug = false
config.assets.compress = false

The best way to tackle this is to profile your app startup. There are several ways that you can take, some fairly technical, but not invasive (eg using DTrace), others more invasive, but easier to do (eg monkeypatch require ).

This page contains a couple of relevant sources: https://waynechu.cc/posts/196-profiling-rails-boot-time . I'd be surprised if none of the options proposed there help.

Another option can be found here: https://gist.github.com/robdimarco/e610b2b5c31c68bb13fe

The IMO easiest way to use this is as follows:

  • add ruby-prof to your Gemfile and run bundle install
  • boot an irb shell with it: bundle exec irb -rruby-prof
  • run the code from the snippet in the irb shell

The output there should give you a good indication where to start looking.

Thanks for pitching in folks. Just now, got it resolved. I am using turbo-sprockets-rails-4 in which preload assets is enabled by default for dev environments.

added below config in config/environments/development.rb

TurboSprockets.configure do |config|
  config.preloader.enabled = false
end

now server startup time is as fast as rails3

this is mentioned in their readme itself, but missed it while skimming through

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM