改善 Rails 加载时间 [英] Improve Rails loading time

查看:55
本文介绍了改善 Rails 加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是上一个关于改进 Rails 控制台加载时间的问题的后续内容.

第一个很好的建议是找出哪些 gem 花费的时间太长.

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

下一个答案,建议使用 :require =>nil稍后加载这些 gem .

Next answer, suggested using :require => nil and loading those gems later.

然而,对于一些 gem,如何在不破坏事物的情况下实现这一点并不完全清楚.这是我们最大的罪犯"的列表,我想知道是否有人可以建议仅在必要时加载它们的最佳方法?

With some gems however, it's not entirely clear how to accomplish this without breaking things. Here's a list of our 'biggest offenders', I wonder if someone can suggest the best approach to loading them only when necessary?

require gon: 2.730000 (2.870059)
require omniauth-openid: 1.410000 (1.503858)
require cancan: 2.640000 (2.707467)
require fog: 2.730000 (2.846530)
require activeadmin: 3.650000 (3.923877)

当然还有更多需要大约 1 秒或更短的时间,这也加起来......但至少删除大的已经可以改善情况.

and of course there are many more that take around 1 second or less, which also adds up... but at least removing the big ones will already improve things.

推荐答案

虽然不能直接回答您的问题,但您可以尝试以下两件事:

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

首先,您是否尝试过 1.9.3 的 Falcon 补丁?这些补丁包括一些非常重要的加载时间改进.

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

如果您使用的是 RVM,则可以使用

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

rvm install 1.9.3 --patch falcon -n falcon

其次,确保您正在设置 GC 调整环境变量.默认情况下,Ruby 分配适合小型脚本的 GC 参数,但不适用于完整的 Rails 应用程序.以下是我的设置,但您可能希望根据应用程序的需要派生自己的设置:

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

以及我使用 ruby​​ 1.9.3-p286 的结果:

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%

设置 GC 调整参数有最大的改进,但我们可以通过使用 falcon 补丁获得另外约 26% 的性能改进.猎鹰补丁加上 GC 参数的组合导致启动时间减少了 75% 以上.

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.

这篇关于改善 Rails 加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆