助手在 rails 3(.2) 中使用大量内存 [英] Helpers use a lot of memory in rails 3(.2)

查看:40
本文介绍了助手在 rails 3(.2) 中使用大量内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将 rails 2 应用程序迁移到 rails 3 时,我遇到了所用内存的大幅增加.经过一番研究,我发现助手是问题所在.取消注释视图中的任何助手会加快一切.

While migrating a rails 2 app to rails 3 I encountered a huge increase in memory used. After some research I found out the helpers were the problem. Uncommenting any helpers in the view would speed everything up.

我试图找出真正问题的事情:

Things I tried to find the real issue:

  • include_all_helpers = false
  • 禁用部分帮助文件
  • 通过将 Model.all 用法重构为一些更快的代码来清理代码

我现在有一个理论,一些助手可能会被重命名或删除,rails 开始搜索它们并开始搜索模型/控制器作为救援.

I got a theory now that some helpers might be renamed or deleted, rails starts to search for them and starts searching models / controllers as rescue.

页面请求最多需要 5 秒,并使用 2 GB 内存.

A page request takes up to 5 seconds and using 2 GB of memory.

有人知道导致此问题的原因以及如何修复或调试吗?

Anyone got a clue what causes this issue and how to fix or debug it?

推荐答案

通过将其放置在 config/initializers/anti_freeze_hack.rb 中修复:

Fixed by placing this in config/initializers/anti_freeze_hack.rb :

module ActionDispatch
  module Routing
    class RouteSet
      alias inspect to_s
    end
  end
end

感谢 Amala 为我提供了正确的主题:D

Credits to Amala for linking me the right topic :D

这篇关于助手在 rails 3(.2) 中使用大量内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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