查找 Rails 应用程序中的内存泄漏

发布于 2024-12-04 19:42:22 字数 2753 浏览 0 评论 0原文

我有一个 Ruby on Rails 中的 Web 应用程序。我们使用在 apcahe httpd 上启动的 mongrel 集群来运行应用程序。我们一直面临应用程序中内存消耗巨大的问题。 (RedHat,Ruby 1.8.7,Rails 2.3.5,RAM 8GB)

问题是在我们启动Web服务器(启动混合集群)后,内存使用量似乎在增加。例如,如果我启动 Web 服务器时的可用内存 (RAM) 是 6GB。 2天后,即使网站没有流量,可用内存也会变成3GB。如果网络服务器一周没有重新启动,内存似乎会增加并使用完整的 8GB RAM,并导致诸如使用“PrinceXML”生成 pdf、使用 sendmail 发送邮件等进程“无内存分配”的问题(我认为这些是记忆 )。当 Web 服务器重新启动时,可用内存将恢复到 6GB。

这是 Rails 应用程序内存泄漏的情况吗?如何检查应用程序是否存在内存泄漏?我找到了一个检查内存泄漏的工具 bleak_house 但是当我将其安装为 gem 时,如此链接所示,这是当我运行 'bleak /tmp/bleak.5979.000.dump' 进行分析时,给出 No command bleak found

我正在使用 PrinceXML 生成 PDF 报告并使用 sendmail 来发送邮件。该服务器还运行了一个 Jasper Server 实例。 请大家帮忙

这是内存过载时top命令的结果。

-bash-3.2$ top

top - 10:34:10 up 14 days,  7:40,  2 users,  load average: 0.24, 0.40, 0.39
Tasks: 181 total,   1 running, 177 sleeping,   2 stopped,   1 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   8173984k total,  8011564k used,   162420k free,    10044k buffers
Swap:  2096472k total,   152624k used,  1943848k free,  2012016k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
  858 **nt*rsc  15   0 12748 1168  832 R 173.5  0.0   0:00.36 top               
    1 root      15   0 10356  108   76 S  0.0  0.0   0:17.10 init               
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.10 migration/0        
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.09 ksoftirqd/0        
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0         
    5 root      RT  -5     0    0    0 S  0.0  0.0   0:00.12 migration/1        
    6 root      34  19     0    0    0 S  0.0  0.0   0:00.12 ksoftirqd/1        
    7 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/1         
    8 root      RT  -5     0    0    0 S  0.0  0.0   0:00.70 migration/2        
    9 root      34  19     0    0    0 S  0.0  0.0   0:00.07 ksoftirqd/2        
   10 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/2         
   11 root      RT  -5     0    0    0 S  0.0  0.0   0:00.67 migration/3        
   12 root      34  19     0    0    0 S  0.0  0.0   0:00.11 ksoftirqd/3        
   13 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/3         
   14 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 events/0           
   15 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 events/1           
   16 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 events/2

I have a web application in Ruby on Rails. We use mongrel clusters started on apcahe httpd to run the application. We have been facing an issue of huge memory consumption in the application. (RedHat,Ruby 1.8.7, Rails 2.3.5, RAM 8GB)

The thing is after we start the web server(start the mongrel clusters), the memory usage seems to be increasing. For example, if the free memory(RAM) when I started the web server was 6GB. After 2 days, the free memory becomes 3GB even at the time of no traffic in the site. If the web server is not restarted for a week, the memory seems to increase and use full 8GB RAM and cause issues of "no memory to allocate" for processes like pdf generation using "PrinceXML", mail sending using sendmail (I think these are memory ). When the web server is restarted, the free memory goes back to 6GB.

Is this a case of memory leak in the Rails application? How to check the application for memory leaks? I have found a tool for checking memory leaks bleak_house but when I install it as a gem as shown in this link, it is giving No command bleak found when I run 'bleak /tmp/bleak.5979.000.dump' to analyze.

I am using PrinceXML to generate PDF reports and sendmail for mail sending purposes. This server has also got a instance of Jasper Server running. Anyone please help.

Here is the result of the top command at the time of memory overload.

-bash-3.2$ top

top - 10:34:10 up 14 days,  7:40,  2 users,  load average: 0.24, 0.40, 0.39
Tasks: 181 total,   1 running, 177 sleeping,   2 stopped,   1 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   8173984k total,  8011564k used,   162420k free,    10044k buffers
Swap:  2096472k total,   152624k used,  1943848k free,  2012016k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
  858 **nt*rsc  15   0 12748 1168  832 R 173.5  0.0   0:00.36 top               
    1 root      15   0 10356  108   76 S  0.0  0.0   0:17.10 init               
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.10 migration/0        
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.09 ksoftirqd/0        
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0         
    5 root      RT  -5     0    0    0 S  0.0  0.0   0:00.12 migration/1        
    6 root      34  19     0    0    0 S  0.0  0.0   0:00.12 ksoftirqd/1        
    7 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/1         
    8 root      RT  -5     0    0    0 S  0.0  0.0   0:00.70 migration/2        
    9 root      34  19     0    0    0 S  0.0  0.0   0:00.07 ksoftirqd/2        
   10 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/2         
   11 root      RT  -5     0    0    0 S  0.0  0.0   0:00.67 migration/3        
   12 root      34  19     0    0    0 S  0.0  0.0   0:00.11 ksoftirqd/3        
   13 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/3         
   14 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 events/0           
   15 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 events/1           
   16 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 events/2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染墨丶若流云 2024-12-11 19:42:22

我会尝试使用乘客(它会自动重新启动并管理内存中增长过大的 Rails 实例 - 比重新启动偏离理智内存限制的杂种要容易得多)。另外,您可能会幸运地使用 1.8.7 的 ruby​​ 企业版分支,它从 1.9 向后移植了一些内存管理修复(例如允许虚拟机在使用较少内存时缩小) - 但该更改可能已经恢复到正常的 1.8.7 ,虽然我不确定。 REE 声称可以将 Rails 应用程序的内存消耗减少 33%。

Ruby 的东西通常会随着时间的推移而增长,并且需要重新启动,而乘客它会自动为您完成此操作。它对我来说非常有效,所以我真的可以推荐它。

http://www.modrails.com/

它还具有良好的内存分析功能

http://www.modrails.com/documentation/Users%20guide%20Apache.html#_analysis_and_system_maintenance

I'd try using passenger (which automatically restarts and manages rails instances that grow too large in memory - much easier than rebooting mongrels that have strayed off sane memory constraints). Also you might have luck with ruby enterprise edition fork of 1.8.7 which backports some memory management fixes from 1.9 (like allowing the VM to shrink when it's using less memory) - that change might have worked it's way back to normal 1.8.7 though, although I am not sure. The claim with REE is that you can reduce memory consumption with 33% for rails applications.

Ruby stuff generally tend to grow over time and need rebooting, with passenger it does that automatically for you. It's worked perfectly for me so I can really recommend it.

http://www.modrails.com/

It also has good memory analytic functions

http://www.modrails.com/documentation/Users%20guide%20Apache.html#_analysis_and_system_maintenance

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文