Forum: Ruby on Rails Finding memory leaks?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bogdan I. (Guest)
on 2006-01-08 21:01
(Received via mailing list)
Where are the memory leaks and what is the way to fix them?
I'm working on a game that was fairly stable in terms the memory
consumption
and it was staying at around 200MB. Recently it has gone crazy, and
unless I
restart it, it goes straight up to 350-400+MB after 30 minutes-1hour.
I am using Apache 1.3+fcgi in production mode.
Also the dispatch.fcgi processes take a really high toll (3-5%) on the
CPU.
( 2.4GZ Xeon with 2 procs)
Since it's hosted (still) on a shared machine I have to constantly keep
an
eye on it.
Any ideas, suggestions?

Thanks,
Bogdan
Joe Van D. (Guest)
on 2006-01-08 23:45
(Received via mailing list)
On 1/8/06, Bogdan I. <removed_email_address@domain.invalid> wrote:
> Where are the memory leaks and what is the way to fix them?
> I'm working on a game that was fairly stable in terms the memory consumption
> and it was staying at around 200MB. Recently it has gone crazy, and unless I
> restart it, it goes straight up to 350-400+MB after 30 minutes-1hour.
> I am using Apache 1.3+fcgi in production mode.
> Also the dispatch.fcgi processes take a really high toll (3-5%) on the CPU.
> ( 2.4GZ Xeon with 2 procs)
> Since it's hosted (still) on a shared machine I have to constantly keep an
> eye on it.
> Any ideas, suggestions?

It used to be the case that Rails would leak memory when running in
development mode.  Not sure if it is anymore.
Bogdan I. (Guest)
on 2006-01-09 00:03
(Received via mailing list)
My application is running in production mode, so it can't be that
Tyler K. (Guest)
on 2006-01-09 04:40
(Received via mailing list)
Bogdan I. <bogdan.ionescu@...> writes:

>
> Where are the memory leaks and what is the way to fix them?I'm working on a
game that was fairly stable in terms the memory consumption and it was
staying
at around 200MB. Recently it has gone crazy, and unless I restart it, it
goes
straight up to 350-400+MB after 30 minutes-1hour.
> I am using Apache 1.3+fcgi in production mode.Also the dispatch.fcgi processes
take a really high toll (3-5%) on the CPU. ( 2.4GZ Xeon with 2
procs)Since it's
hosted (still) on a shared machine I have to constantly keep an eye on
it.
> Any ideas, suggestions?Thanks,Bogdan

Bogdan,

Two things to look at:

1. What garbage collection settings do you have in public/dispatch.fcgi?
If you
use this syntax:

RailsFCGIHandler.process! nil, 50

Then garbage collection will NOT run until after 50 requests.  This one
bit us a
while ago.  Use the default instead if your dispatch.fcgis are growing:

RailsFCGIHandler.process!

2.  Here's a good article on finding leaky objects in Ruby.  The tools
aren't
terribly sophisticated but they work just fine if you're willing to
spend a
little bit of time chasing your leak.

http://theexciter.com/articles/finding-leaking-ruby-objects

I got the best results out of using this code to analyze controller
methods
invoked through functional tests.  Don't be afraid to use vendor/plugins
to
override (and inject measurement code) into base Rails classes if the
leak
doesn't appear to be in your code.

Best of luck,

Tyler
Tom F. (Guest)
on 2006-01-09 06:08
(Received via mailing list)
Also, if you are using RMagick, then you will need to perform manual
garbage
collection to get all the used memory back.

I have a method that looks like this that I call after I do a bunch of
operations:

  def run_gc
    fDisabled = GC.enable
    GC.start
    GC.disable if fDisabled
  end
This topic is locked and can not be replied to.