Improve Rails loading time

前端 未结 1 909
滥情空心
滥情空心 2020-12-28 10:33

This is a bit of a follow-up from a previous question on improving rails console loading time.

The first great suggestion was to figure out which gems take too long.<

相关标签:
1条回答
  • 2020-12-28 10:54

    While not a direct answer to your question, there are two things you might try:

    First, have you tried the Falcon patches for 1.9.3? The patches include some pretty significant load time improvements.

    If you're using RVM, you can do a quick-and-dirty install with

    rvm install 1.9.3 --patch falcon -n falcon
    

    Second, make sure you're setting GC tuning environment variables. Ruby, by default, allocates GC parameters that are appropriate for small scripts, but not for full Rails apps. Here are my settings, though you'd want to derive your own based on your application's needs:

    % env | grep RUBY_
    RUBY_HEAP_MIN_SLOTS=800000
    RUBY_HEAP_FREE_MIN=100000
    RUBY_HEAP_SLOTS_INCREMENT=300000
    RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
    RUBY_GC_MALLOC_LIMIT=79000000
    

    And my results using ruby 1.9.3-p286:

                        Stock     Stock+GC  Falcon   Falcon+GC
                        27.13     8.43      8.63     6.69
    Stock       27.13   100.00%   31.07%    31.81%   24.66%
    Stock+GC    8.43    321.83%   100.00%   102.37%  79.36%
    Falcon      8.63    314.37%   97.68%    100.00%  77.52%
    Falcon+GC   6.69    405.53%   126.01%   129.00%  100.00%
    

    Setting the GC tuning parameters has the biggest improvement, but we can get yet another ~26% improvement performance by using the falcon patches. The combination of the falcon patches plus the GC parameters results in over a 75% reduction in boot time.

    0 讨论(0)
提交回复
热议问题