Rails 3 - speed up console loading time

I am wondering if there is a relatively easy way to speed up my console boot time, which is starting to approach 30 seconds. I have many subclasses whose methods do not affect reload! , so I end up opening and closing the console. IRB quickly loads lightning.

Do I have too many gems? How can I talk about download tasks so that I can see which takes the most time? As you can see, I already tried the dev-boost camcorder to no avail. The application is great in Passenger, it's just loading the console, which perverts me. Powered by OSP 10.6.6 MBP with 2.4 GHz and 4 GB RAM. Do not use RVM.

Versions:

 Ovid$ rails -v Rails 3.0.3 Ovid$ ruby -v ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10] 

Memory:

 Ovid$ vm_stat Mach Virtual Memory Statistics: (page size of 4096 bytes) Pages free: 118818. Pages active: 341320. Pages inactive: 99490. Pages speculative: 310576. Pages wired down: 112527. "Translation faults": 23097323. Pages copy-on-write: 1270961. Pages zero filled: 13836659. Pages reactivated: 36. Pageins: 165761. Pageouts: 0. Object cache: 28 hits of 760846 lookups (0% hit rate) 

Gemfile:

 source 'http://rubygems.org' gem 'rails', '3.0.3' gem 'mysql2' gem 'foreigner' gem 'haml' gem 'capistrano' gem 'nokogiri' #web services gem 'yammer4r' gem 'ruby-freshbooks' #authentication gems from nifty generator gem "bcrypt-ruby", :require => "bcrypt" gem "mocha", :group => :test gem 'authlogic' #dev group :development do gem 'rails-dev-boost', :git => 'git://github.com/thedarkone/rails-dev-boost.git', :require => 'rails_development_boost' end #testing group :test do gem 'database_cleaner' gem 'cucumber-rails' gem 'cucumber' gem 'rspec-rails' gem 'spork' gem 'launchy' gem 'machinist' gem 'faker' gem 'capybara' end 

Thank you very much!

+44
ruby ruby-on-rails ruby-on-rails-3 console
Jan 19 2018-11-11T00:
source share
6 answers

I finally found my launch bottlenecks using Benchmark. In particular, go to the gemstone of the bundle and in lib / bundler / runtime.rb find the line that Kernel.require does and end it as follows:

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

You may need to add a β€œbenchmark” somewhere in your application, for example, in config / boot.rb. This will show you how long it will take to require each gem. I can’t guarantee that your results will match mine, but I had a few gems that took more than a second to load compared to the sub-millisecond for most. Some of them were gems that I did not need for development, but I needed to perform some tasks in the development environment, for example. capistrano, shoulda. I compared other launch areas (initializers, etc.), but could not find any significant bottlenecks.

I still do not understand how to configure the application only to download those tasks where they are really needed. Perhaps I could create an environment called: speedy and use RAILS_ENV = speedy rails s / c to run when I know that I do not need these gems. Then in Gemfile I could use a group: quick to exclude these gems in certain cases.

All that said, the biggest annoyance for me is to download the whole environment to complete the rake task. I could rule out most of the stones for this, but the Gemfile will start to get confused, so I don't know if it's worth it.

+58
Feb 21 2018-11-21T00:
source share

A slightly adapted form suitable for copying wraps everything and provides sortable output:

 # Add this to the top of boot.rb require 'benchmark' def require(file) puts Benchmark.measure("") { super }.format("%t require #{file}") end 

Then you can do no-op to see them:

 rails runner 1 

Or sort them and show top 50:

 rails runner 1 | sort -nr | head -n 50 
+20
Nov 06
source share

You can speed it up by adding: require => nil to the slow Gemfile entries and require them manually. eg.

 gem 'jammit', :require => nil 

I also raised this issue during the meeting that I had. This seems like a bug in ruby ​​1.9.2 (see comments on this patch: https://gist.github.com/1008945 )

You can fix this by correcting your 1.9.2 entity that I just linked or upgraded to 1.9.2-head or 1.9.3-head .

+7
Aug 22 '11 at 11:31
source share

I can only suggest putting on your lab coat and halving the question. See if you are commenting that your gem requirements are speeding up (presumably this also involves commenting on code fragments that rely on these gems). If yes, comment half at a time, etc.

Sorry, this is not a real answer. You can try ruby-prof, suppose, for example, calling it with the rails runner and no-op script.

I tried ruby-prof script/rails runner 'nil' on my mac, but it looks like it just crashed :-)

EDIT

If you use git for your application, you can also try this bisect command and see if there is some point in time when everything becomes slow, and not just a common bloat.

+1
Jan 19 '11 at 15:50
source share

This is definitely about cleaning up your code and identifying bottlenecks, but once you have made these savings, it's worth looking at something like Zeus to speed up the time of your dev.

 gem install zeus 

https://github.com/burke/zeus (docs)

It is not without errors and sometimes requires a reboot, but I still see a general increase in development time due to a quick reboot of the server and console after minor code changes.

+1
Dec 20
source share

Reload! been a problem for some time. Take a look. There are some fixes that you could use, and some tips on how you might be able to get around your problem.

The reboot method is as follows.

 # reloads the environment def reload!(print=true) puts "Reloading..." if print ActionDispatch::Callbacks.new(lambda {}, false).call({}) true end 

You can always add an environment to this method to override this function and force the required reboot.

It worked for me, so let us know if it works for you. All the best.

0
Jan 19 '11 at 19:20
source share



All Articles