ruby/ruby on rails 内存泄漏检测 [英] ruby/ruby on rails memory leak detection

查看:35
本文介绍了ruby/ruby on rails 内存泄漏检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ruby​​ on rails 编写了一个小型 Web 应用程序,其主要目的是上传、存储和显示 xml(文件最多可达到几 MB)文件的结果.运行大约 2 个月后,我注意到 mongrel 进程使用了​​大约 4GB 的内存.我做了一些关于调试 ruby​​ 内存泄漏的研究,但找不到太多.所以我有两个问题.

I wrote a small web app using ruby on rails, its main purpose is to upload, store, and display results from xml(files can be up to several MB) files. After running for about 2 months I noticed that the mongrel process was using about 4GB of memory. I did some research on debugging ruby memory leaks and could not find much. So I have two questions.

  • 有没有什么好的工具可以用来查找 Ruby/rails 中的内存泄漏?
  • 什么类型的编码模式会导致 ruby​​ 内存泄漏?

推荐答案

在 Rails 中查找内存泄漏的一些技巧:

Some tips to find memory leaks in Rails:

  • use the Bleak House plugin
  • implement Scout monitoring specifically the memory usage profiler
  • try another simple memory usage logger

第一个是对 ObjectSpace 中对象的内存使用情况的图形探索.

The first is a graphical exploration of memory usage by objects in the ObjectSpace.

最后两个将帮助您识别导致内存使用量膨胀的特定使用模式,您可以从那里开始工作.

The last two will help you identify specific usage patterns that are inflating memory usage, and you can work from there.

至于特定的编码模式,根据经验,您必须注意处理文件 io、图像处理、处理大量字符串等的任何事情.

As for specific coding-patterns, from experience you have to watch anything that's dealing with file io, image processing, working with massive strings and the like.

我会检查您是否使用了最合适的 XML 库 - 众所周知,ReXML 很慢并且被认为是有漏洞的(我没有证据证明这一点!).还要检查您是否可以 记忆 昂贵的操作.

I would check whether you are using the most appropriate XML library - ReXML is known to be slow and believed to be leaky (I have no proof of that!). Also check whether you can memoize expensive operations.

这篇关于ruby/ruby on rails 内存泄漏检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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