Search for memory leaks in a Rails application

I have a web application in Ruby on Rails. We use Mongro clusters running on apcahe httpd to run the application. We are faced with the problem of huge memory consumption in the application. (RedHat, Ruby 1.8.7, Rails 2.3.5, RAM 8GB)

The fact is that after we start the web server (start the mongrell clusters), the memory usage seems to increase. For example, if the free memory (RAM) at startup of the web server was 6 GB. After 2 days, free memory becomes 3 GB even when there is no traffic on the site. If the web server does not restart within a week, the memory seems to increase and use the full 8 gigabyte RAM and cause "no memory to allocate" problems for processes such as generating PDF using "PrinceXML" sending mail using sendmail ( I think this is Memory). When the web server restarts, free memory returns to 6 GB.

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

I use PrinceXML to create PDF reports and sendmail to send mail. This server also has an instance of Jasper Server. Someone please help .

Here is the result of the top command during 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 
+4
source share
1 answer

I would try using a passenger (who automatically restarts and manages instances of rails that become too large in memory - much easier than reloading mogrels that deviate from reasonable memory limits). In addition, you might be lucky with the ruby ​​corporate version 1.8.7 version, which supports some memory management fixes from version 1.9 (for example, allowing the virtual machine to shrink when it uses less memory) - this change could return to normal 1.8. 7 though, although I'm not sure. The claim with REE is that you can reduce memory consumption by 33% for rail applications.

Ruby stuff usually grows over time and requires a reboot, and the passenger automatically does this for you. It worked great for me, so I can recommend it.

http://www.modrails.com/

It also has good analytic memory functions.

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

+3
source

All Articles