usha
usha

Reputation: 29349

Decrease rails boot time

I found this blog about reducing rails boot time.

I set these environment variables in my bashrc.

export RUBY_HEAP_MIN_SLOTS=800000
export RUBY_HEAP_FREE_MIN=100000
export RUBY_HEAP_SLOTS_INCREMENT=300000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=79000000

And it did reduce my boot time by half.

Now i would like to know why this decreased my boot time and what do these environment variables mean?

Upvotes: 3

Views: 542

Answers (1)

RubeOnRails
RubeOnRails

Reputation: 1163

RUBY_HEAP_MIN_SLOTS (default 10_000) - the initial number of heap slots and minimum number of slots at all times. One heap slot can hold one Ruby object.

RUBY_HEAP_FREE_MIN (default 4_096) - the number of free slots that should be present after the garbage collector finishes running. If there are fewer than those defined, it allocates new ones according to RUBY_HEAP_SLOTS_INCREMENT and RUBY_HEAP_SLOTS_GROWTH_FACTOR parameters

RUBY_HEAP_SLOTS_INCREMENT (default 10_000) - the number of new slots to allocate when all initial slots are used. The second heap.

RUBY_HEAP_SLOTS_GROWTH_FACTOR (default 1.8) - multiplication factor used to determine how many new slots to allocate (RUBY_HEAP_SLOTS_INCREMENT * multiplication factor). For heaps #3 and onward.

RUBY_GC_MALLOC_LIMIT (default 8_000_000) - The number of C data structures that can be allocated before triggering the garbage collector.

The default settings for the Ruby garbage collector are not optimized for Rails, which uses a lot of memory and creates and destroys huge objects frequently. The optimal values depend on the application itself, and you can profile garbage collection under different settings: http://www.ruby-doc.org/core-2.0/GC/Profiler.html

You can also monitor the GC using New Relic, gdb.rb, or using gems like scrap (https://github.com/cheald/scrap/tree/master).

Here are some articles you may be interested in:

https://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/ http://technology.customink.com/blog/2012/03/16/simple-garbage-collection-tuning-for-rails/ http://snaprails.tumblr.com/post/241746095/rubys-gc-configuration

Upvotes: 2

Related Questions