在Ruby on Rails项目中查找内存泄漏

时间:2023-02-06 07:56:42

I have a Ruby on Rails project with what seems to be a memory leak. It keeps using more and more memory until it crashes. Dumping the amount of objects per class using ObjectSpace I've found this:

我有一个Ruby on Rails项目,似乎是一个内存泄漏。它一直使用越来越多的内存,直到它崩溃。使用ObjectSpace转储每个类的对象数量我发现了这个:

Name                                                              Count
-----------------------------------------------------------------------
String                                                           649476
Hash                                                              59695
Array                                                             39407
ActiveSupport::Multibyte::Codepoint                               19337
FileNode                                                          17134
Time                                                               3391
Regexp                                                             1944
ActionController::Routing::DividerSegment                          1743
Proc                                                               1597
Gem::Version                                                       1545
Class                                                              1503
Gem::Requirement                                                   1479
ActiveRecord::DynamicFinderMatch                                   1021

I believe FileNode is the problem. It's a model. Any ideas how to find where the references to the 17k FileNodes are being kept?

我相信FileNode是个问题。这是一个模型。任何想法如何找到保存17k FileNodes的引用?

This is using Ruby 1.8.6 and Rails 2.2.0. Upgrading is not an option unfortunately.

这是使用Ruby 1.8.6和Rails 2.2.0。不幸的是,升级不是一种选择。

3 个解决方案

#1


7  

Charles Oliver "Headius" Nutter has recently written a series of blog posts on debugging memory leaks in Ruby using JVM tools:

Charles Oliver“Headius”Nutter最近撰写了一系列关于使用JVM工具调试Ruby内存泄漏的博客文章:

IIRC, there were also a couple of other blog posts on that same topic by other members of the JRuby community around the same time.

IIRC,JRuby社区的其他成员同时也在同一主题上发布了几篇其他博客文章。

Their basic argument (although they are too polite to spell it out that way) is that using anything other than JRuby to debug memory leaks is just plain stupid, simply because JRuby can use Java tools which have more engineering effort put into them than all Ruby profiling tools together. And the Ruby community gets those tools for free, because all the enterprise Java drones are paying for them.

他们的基本论点(虽然他们过于礼貌而无法用这种方式拼写)是使用JRuby以外的任何东西来调试内存泄漏只是简单的愚蠢,因为JRuby可以使用Java工具,这些工具比Ruby更多的工程工作量分析工具在一起。 Ruby社区免费获取这些工具,因为所有企业Java无人机都在为它们付费。

#2


5  

You might want to look at the presentation "Garbage Collection and the Ruby Heap":

您可能希望查看演示文稿“垃圾收集和Ruby堆”:

http://www.scribd.com/doc/32718051/Garbage-Collection-and-the-Ruby-Heap

http://www.scribd.com/doc/32718051/Garbage-Collection-and-the-Ruby-Heap

Starting from Slide 26 various useful tools (ltrace, bleak_house, memprof etc.) get explained.

从幻灯片26开始,解释了各种有用的工具(ltrace,bleak_house,memprof等)。

#3


2  

I think you'll find Debugging Ruby by Aman Gupta very helpful. He has also been working on finding and fixing memory leaks in Rails 3 so his debugging techniques will most certainly be helpful.

我想你会发现Aman Gupta的Debugging Ruby非常有帮助。他一直致力于在Rails 3中查找和修复内存泄漏,因此他的调试技术肯定会有所帮助。

http://www.scribd.com/doc/23548865/Debugging-Ruby

http://www.scribd.com/doc/23548865/Debugging-Ruby

#1


7  

Charles Oliver "Headius" Nutter has recently written a series of blog posts on debugging memory leaks in Ruby using JVM tools:

Charles Oliver“Headius”Nutter最近撰写了一系列关于使用JVM工具调试Ruby内存泄漏的博客文章:

IIRC, there were also a couple of other blog posts on that same topic by other members of the JRuby community around the same time.

IIRC,JRuby社区的其他成员同时也在同一主题上发布了几篇其他博客文章。

Their basic argument (although they are too polite to spell it out that way) is that using anything other than JRuby to debug memory leaks is just plain stupid, simply because JRuby can use Java tools which have more engineering effort put into them than all Ruby profiling tools together. And the Ruby community gets those tools for free, because all the enterprise Java drones are paying for them.

他们的基本论点(虽然他们过于礼貌而无法用这种方式拼写)是使用JRuby以外的任何东西来调试内存泄漏只是简单的愚蠢,因为JRuby可以使用Java工具,这些工具比Ruby更多的工程工作量分析工具在一起。 Ruby社区免费获取这些工具,因为所有企业Java无人机都在为它们付费。

#2


5  

You might want to look at the presentation "Garbage Collection and the Ruby Heap":

您可能希望查看演示文稿“垃圾收集和Ruby堆”:

http://www.scribd.com/doc/32718051/Garbage-Collection-and-the-Ruby-Heap

http://www.scribd.com/doc/32718051/Garbage-Collection-and-the-Ruby-Heap

Starting from Slide 26 various useful tools (ltrace, bleak_house, memprof etc.) get explained.

从幻灯片26开始,解释了各种有用的工具(ltrace,bleak_house,memprof等)。

#3


2  

I think you'll find Debugging Ruby by Aman Gupta very helpful. He has also been working on finding and fixing memory leaks in Rails 3 so his debugging techniques will most certainly be helpful.

我想你会发现Aman Gupta的Debugging Ruby非常有帮助。他一直致力于在Rails 3中查找和修复内存泄漏,因此他的调试技术肯定会有所帮助。

http://www.scribd.com/doc/23548865/Debugging-Ruby

http://www.scribd.com/doc/23548865/Debugging-Ruby