19

I know about GC.enable/disable, but is there any way of controlling the Ruby 1.9 garbage collector in more detail?

When profiling my code (using perftools.rb) I notice that the GC stands for up to 30% of the total samples, and I'd like to see if it's possible to tune the GC to decrease this number. Are there any environment variables or other means by which you can set the number of heap slots, the malloc limit, etc. like you can with REE?

2 Answers 2

11

Yep, for short.

At first, basic constants, defining GC behavior (defaults value are shown) :

  • RUBY_GC_MALLOC_LIMIT = 8000000 # - Initial size of a new memory slab, which is allocated after consuming all available memory
  • RUBY_HEAP_MIN_SLOTS = 10000 #- Initial memory size, allocated at startup
  • RUBY_HEAP_SLOTS_GROWTH_FACTOR = 1,8 #- New slab of memory is X times bigger than previous after each allocation.
  • RUBY_HEAP_SLOTS_INCREMENT = 1 # Not sure, honestly :)

More details about GC, may help

A story from 37signals guys, which may definitively help you. They used manual GC calls (GC.start) on time, instead of memory size, and got huge boost.

2
  • Aman & Joe talk about these constants in their presentation, but from what I can tell they are actually the same REE settings I mentioned in my question. Am I wrong or can you give me an example of how to use them in a vanilla Ruby 1.9 VM?
    – Theo
    Feb 19, 2011 at 13:39
  • I'm pretty sure this is 1) only 1.8.7 and 2) even on 1.8.7 requires you to patch and compile a custom VM. There is a new patch for 1.9.2 that was released long after your answer, but it still requires you to compile a custom VM.
    – Theo
    Mar 14, 2011 at 20:47
1

No.

There is no way to tune the 1.9.0–1.9.2 GC. However, you can compile a custom VM that exposes more or less the same tuning parameters as REE with this patch.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.