我如何在Heroku上发现内存泄漏? [英] How can I find a memory leak on Heroku?

查看:136
本文介绍了我如何在Heroku上发现内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku Cedar上运行了Ruby 1.9.3的Rails 3.2.8应用程序。该应用程序启动时运行良好,但在连续使用一天左右后,我开始在日志中看到R14错误。一旦内存错误开始,它们就永远不会消失,即使应用程序闲置了几个小时。



不应该在一段时间后清理未使用的对象,并减少内存负载? Heroku似乎没有发生这种情况。一般来说,运行一些包含数千行数据的报表后,内存使用会开始增加,尽管结果是分页的。



如何查找内存泄漏?像bleak_house这样的插件已经过时,或者在Heroku环境中不会很好地运行。我可以调整GC设置,使其更具侵略性吗?

解决方案

GC应该完成清理工作,可能的确如此。 / p>

您可以用 GC.start 强制执行GC。如果很多对象没有收集到这个意志,但我怀疑这不是问题。



是否有可能以某种方式创建一堆对象并从不释放它们:保留缓存的副本或其他东西?



我不熟悉现有的工具来检查它,但您可能想要使用 ObjectSpace检查存在哪些对象。例如:

  ObjectSpace.each_object.with_object(Hash.new(0)){| obj,h | h [obj.class] + = 1} 
#=>一个Hash类的对象数

如果您的类中有一个意外的数字,例如,你可以更好地了解在哪里寻找。


I have a Rails 3.2.8 app running on Heroku Cedar with Ruby 1.9.3. The app runs fine when it launches but after a day or so of continuous use, I start to see R14 errors on my logs. Once the memory errors start, they never go away, even if the app is idle for several hours.

Shouldnt the garbage collector clean up unused objects after a while and reduce the memory load? It seems this is not happening on Heroku. Generally, memory usage starts to creep up after running some reports with several thousand rows of data, although results are paginated.

How can I find the memory leak? Plugins like bleak_house are way out of date or dont run nicely in the Heroku environment. Can I adjust the GC settings to make it more aggressive?

解决方案

The GC should do the clean up, and probably does.

You can force the GC with GC.start; if many objects were not collected this will, but I suspect that is not the issue.

Is it possible you somehow create a bunch of objects and never release them, by keeping cached copies or something?

I'm unfamiliar with the existing tools to check this, but you may want to check which objects exist using ObjectSpace. For example:

ObjectSpace.each_object.with_object(Hash.new(0)){|obj, h| h[obj.class] +=1 }
# => a Hash with the number of objects by class

If you get an unexpected number for one of your classes, for instance, you would have a better idea of where to look for.

这篇关于我如何在Heroku上发现内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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