开发者

Find memory leaks in a Rails application

开发者 https://www.devze.com 2023-04-05 04:47 出处:网络
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,R

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  开发者_StackOverflow社区-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'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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号