Sort of fixing rails memory usage
I just love how powerful and beautifully ambiguous is the English language. Just write a naive comment here in the Rails API docs, then a how-to-do-it-better post in the Textdrive forums, which in time ends up promoted to Textdrive blog entry and by now we have seen a dogma born.
Is it because nil usually means don’t execute, that allowed a performance modification by Stephan Kaes to be regarded as a memory optimization by the Textdrive people? You know that magical application dependent number from public/dispatch.fcgi? The one that should be mystically set to 10-20-50 dependent on your application?
The one about making sure that the garbage collector runs when we ask it rather when ruby needs it? As if we would know better than ruby. I’m talking about this:
RailsFCGIHandler.process! nil, 50
You might be surprised but this says don’t run the garbage collector only after serving 50 requests! And the default that you have been advertised to change:
RailsFCGIHandler.process!
Says let ruby run the garbage collector when needed. I humbly believe that ruby knows better. The core rails developers probably also think the same, that is why this is the default.
You see when the garage collector runs, your application doesn’t: so forcing a run only after certain number of requests is a performance and not memory optimization. Heck it was introduced by Stephan Kaes the performance guy!
Apropos I have yet to see FCGI
dispatchers that consume just 7 Mb of memory. Sure I’m hoping to see
them, but until then I’ll just remember how to read the ps aux output:
strongspace 7143 0.0 0.9 32556 29364 p0- I Wed12PM 1:12.38 ruby /var/strongspace/web/public/dispatch.fcgi
strongspace 7145 0.0 1.0 38320 35096 p0- S Wed12PM 1:13.44 ruby /var/strongspace/web/public/dispatch.fcgi
strongspace 7146 0.0 0.8 31432 27996 p0- I Wed12PM 1:03.00 ruby /var/strongspace/web/public/dispatch.fcgi
strongspace 7147 0.0 0.9 32916 29416 p0- I Wed12PM 1:08.34 ruby /var/strongspace/web/public/dispatch.fcgi
strongspace 7148 0.0 0.9 33892 30672 p0- I Wed12PM 1:12.19 ruby /var/strongspace/web/public/dispatch.fcgi
strongspace 7149 0.0 1.0 35668 32444 p0- I Wed12PM 1:10.37 ruby /var/strongspace/web/public/dispatch.fcgi
The one from above is quoted from the Textdrive blog. And it says here are a bunch of rails FCGI dispatch processes all with pids in the range of 7143-7149. That consume in the range of 27-35 Mb with significant a variance between them. Quite a difference from what Julik says on the Textdrive blog!
Comments
-
You’re absolutely correct when you say that you should usually leave the GC frequency set to nil, unless you really know what you’re doing.
And I never promoted it as a cure for memory leaks.
The comment in the Rails source should have certainly be more detailed. But I didn’t write it.
