Reduce rail loading time

I found this blog about reducing rail loading times.

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 reduced loading time by half.

Now I would like to know why this reduced load time and what do these environment variables mean?

+4
source share
1 answer

RUBY_HEAP_MIN_SLOTS (default 10_000) - The initial number of heap slots and the minimum number of slots at any time. One slot for a heap can contain one Ruby object.

RUBY_HEAP_FREE_MIN (default 4_096) - the number of free slots that should be present after the garbage collector has completed assembly. If there are fewer than indicated, he allocates new ones in accordance with the parameters RUBY_HEAP_SLOTS_INCREMENT and RUBY_HEAP_SLOTS_GROWTH_FACTOR

RUBY_HEAP_SLOTS_INCREMENT ( 10_000 by default) - the number of new slots for distribution when all initial slots are used. Second pile.

RUBY_HEAP_SLOTS_GROWTH_FACTOR (default 1.8) - multiplication factor used to determine the number of new slots for distribution (RUBY_HEAP_SLOTS_INCREMENT * multiplication factor). For heaps No. 3 and further.

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

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

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

Here are some articles you might 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

+3
source

Source: https://habr.com/ru/post/1499020/


All Articles