代码之家  ›  专栏  ›  技术社区  ›  Pavel K.

尝试加速Rails应用程序时收到奇怪的加载时间报告

  •  1
  • Pavel K.  · 技术社区  · 14 年前

    我正在使用newrelic(开发人员模式)监视我的Rails应用程序。 奇怪的是,加载同一个页面会产生不同的加载结果,其中一个随机部分会不断地重写其余部分。

    例如(所有结果来自同一个页面,“messages/1”,只需刷新)

                                                 Exclusive         Total
    Administration#find_by_sql                269 ms  35%   276 ms    36%
    messages/show.html.erb Template           113 ms    15%     183 ms    24%
    MessagesController#show                   90 ms     12%     760 ms    99%
    events/_events_box.html.erb Template         24 ms  3%   24 ms     3%
    SQL/show                                     19 ms  2%   19 ms    2%
    User#find                                    19 ms  2%   19 ms    2%
    Remainder                                    234 ms 31%  234 ms    31%
    
    -------
    subscriptions/_subscribe.html.erb Template   266 ms    44%   272 ms   45%
    MessagesController#show                      61 ms  10%      606 ms   99%
    messages/show.html.erb Template              61 ms  10%   365 ms   60%
    SQL/other                                 24 ms     4%     24 ms  4%
    layouts/_header.html.erb Template         20 ms     3%     28 ms  5%
    events/_events_box.html.erb Template      19 ms     3%     19 ms  3%
    Remainder                                 160 ms    26%     160 ms  26%
    
    -------
    drafts/_js_and_sbox.html.erb Template      265 ms   44%       269 ms  45%
    MessagesController#show                    72 ms    12%       595 ms  100%
    messages/show.html.erb Template               57 ms    9%  356 ms  59%
    events/_events_box.html.erb Template          19 ms    3%     19 ms   3%
    layouts/_header.html.erb Template             18 ms    3%        28 ms   5%
    SQL/other                                  15 ms    2%     15 ms   2%
    Remainder                                  153 ms   26%     153 ms  26%
    

    有人知道为什么代码的一个随机部分(通常是无关紧要的,并且加载速度很快)会占用几乎一半的加载时间吗?可能是因为我在一些模板中执行查询?

    2 回复  |  直到 14 年前
        1
  •  2
  •   unsorted    14 年前

    这有点晚了,但也许会对其他人有所帮助…我认为这是因为垃圾收集会随机点击,并将页面加载时间增加约150毫秒,请参见 this article 更多讨论:

    Ruby Prof属性 垃圾收集到方法 GC被触发,而不是方法 分配内存。这就像 责怪最后一根稻草折断了 骆驼的背。

        2
  •  1
  •   Taryn East    14 年前

    另一个选项是,您的数据库在某些时候可能会有点过载-导致数据库查询/等待时间变慢。Newrelic有时不是很具体。

    如果你真的想调整你的行为,我会把newrelic的声明作为指导方针,指导你在哪里用更好的工具进行测试(例如ruby prof)。

    我谈过如何使用这些工具: http://skillsmatter.com/podcast/ajax-ria/making-your-rails-app-kick-ass-with-ruby-prof-and-kcachegrind