Tom Copeland's Recent Posts

RSS Feeds

« 20000 users on RubyForge | Main | An LOLCODE interpreter using JJTree »

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451d3c069e200e5505cd98d8833

Listed below are links to weblogs that reference Tracking down a Rails app memory leak:

Comments

The mem_inspect gets you most of the way there. Bleakhouse uses it to do its object counts. Its fairly time consuming to walk the heap and figure out how big everything is, though.

"But replacing that OpenStruct with a Hash causes the memory size to only go from 3 MB to 7 MB, which is a bit of an improvement over rising from 3 MB to 80 MB."

Does the memory go back down with a Hash, or not? What about a

class Fred
attr_accessor :first_name, :last_name, :hat_size, :country
end

which being a normal class might be better?
(I'm aware that your real OpenStruct may not suit a regular class, but I'm wondering if this tells us something useful about GC in Ruby, or just about OpenStruct.)

While trying to challenge assumptions, as one needs to at times like this: what happens if you use YAML instead of Marshal? I'd hope it makes no difference...

Check out LiteSpeed too, it will enforce hard and soft memory limits for your rails apps, and auto spawns/kills handlers as needed

Also check out Dike, which might be able to give you information down to the lines of code that cause the leak.

http://www.codeforpeople.com/lib/ruby/dike/

So...my question is why doesn't GC.start get it?

Roger - exactly! I have no idea... something for ruby-core, I suppose...

You could try making the heap chunk size small (and not grow exponentially) and see if ruby is able to reclaim that unused space

Roger - yup, I haven't been watching ruby-core lately, not sure what the status of this one is...

he MBARI patches might fix this. One can hope...

Indeed it would appear that more recent versions of 1.8.7 fix this:
with MBARI patches
before VmRSS: 156744 kB
after GC VmRSS: 90444 kB

and 1.8.7 trunk straight
before: VmRSS: 201724 kB
after: VmRSS: 24200 kB

but with 1.9
before: VmRSS: 59360 kB
after: VmRSS: 58852 kB

Not sure what's going on there. Perhaps 1.9 could use some MBARI love but it's hard to tell.

In reality what was going on in this example is that old references to "data" were still floating around like ghosts on the stack.

It seems odd to me that 10000 structs -> 100MB of memory, though. That's 10K of memory per single ostruct! Whoa!

The comments to this entry are closed.