33

I was wondering if the GC tuning used for ruby 1.9.x is still relevant in 2.0 with the new implementation of the GC. If so, are there any new things that we can configure on the new version?

I am talking about the following setups

RUBY_HEAP_MIN_SLOTS=600000 
RUBY_GC_MALLOC_LIMIT=59000000
RUBY_HEAP_FREE_MIN=100000
Fernando Diaz Garrido
  • 3,995
  • 19
  • 22

2 Answers2

50

There's a fair bit of confusion about these GC tuning parameters. REE (which is a fork of Ruby 1.8.7) introduced its own parameters first, and later Ruby (starting in 1.9.2) introduced its own (similar) parameters. Ruby 1.9.3 made them customizable via environment variables, and Ruby 2.1.0 added a lot more.

This blog post goes into great detail about garbage collection in MRI and what all the tuning variables mean.

Here's a complete list of all the tuning variables for each Ruby version:

REE source

  • RUBY_HEAP_MIN_SLOTS
  • RUBY_HEAP_SLOTS_INCREMENT
  • RUBY_HEAP_SLOTS_GROWTH_FACTOR
  • RUBY_GC_MALLOC_LIMIT
  • RUBY_HEAP_FREE_MIN

Ruby 1.9.2 source source

(Hard-coded, but customizable via environment variables with this patch)

  • GC_MALLOC_LIMIT
  • HEAP_MIN_SLOTS
  • FREE_MIN

Ruby 1.9.3 source

  • RUBY_GC_MALLOC_LIMIT
  • RUBY_HEAP_MIN_SLOTS
  • RUBY_FREE_MIN

Ruby 2.0.0 source

Same as Ruby 1.9.3

Ruby 2.1.0 source

  • RUBY_GC_HEAP_INIT_SLOTS (obsoletes RUBY_HEAP_MIN_SLOTS)
  • RUBY_GC_HEAP_FREE_SLOTS (obsoletes RUBY_FREE_MIN)
  • RUBY_GC_HEAP_GROWTH_FACTOR (new)
  • RUBY_GC_HEAP_GROWTH_MAX_SLOTS (new)
  • RUBY_GC_MALLOC_LIMIT
  • RUBY_GC_MALLOC_LIMIT_MAX (new)
  • RUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR (new)
  • RUBY_GC_OLDMALLOC_LIMIT (new)
  • RUBY_GC_OLDMALLOC_LIMIT_MAX (new)
  • RUBY_GC_OLDMALLOC_LIMIT_GROWTH_FACTOR (new)

Ruby 2.1.1 source

  • RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR (new)
Benjamin
  • 10,085
  • 19
  • 80
  • 130
davogones
  • 7,321
  • 31
  • 36
  • Looks like [Ruby 1.9.2](https://github.com/ruby/ruby/blob/ruby_1_9_2/gc.c#L77-L79) does not have RUBY_GC_MALLOC_LIMIT. Instead it has GC_MALLOC_LIMIT that is initialized with the #define macro. This means we need to change the value in gc.c and recompile Ruby to control when the GC runs. – ardsrk Jul 18 '13 at 07:03
  • Also, none of these is settable in 1.9.2 via environment variables as far as I can tell. – Dylan Markow Aug 23 '13 at 14:26
  • Awesome overview! We are in the middle of an infrastructure upgrade and this helps heaps (hahaha) in keeping our tuning intact. – dhenze Jan 29 '14 at 13:19
14

From Ruby 2.1.x http://tmm1.net/ruby21-rgengc/

export RUBY_GC_HEAP_INIT_SLOTS=600000
export RUBY_GC_HEAP_FREE_SLOTS=600000
export RUBY_GC_HEAP_GROWTH_FACTOR=1.25
export RUBY_GC_HEAP_GROWTH_MAX_SLOTS=300000

or this

# Boost Ruby
export RUBY_GC_HEAP_INIT_SLOTS=1000000 # 1M
export RUBY_GC_HEAP_FREE_SLOTS=500000  # 0.5M
export RUBY_GC_HEAP_GROWTH_FACTOR=1.1
export RUBY_GC_HEAP_GROWTH_MAX_SLOTS=10000000 # 10M
export RUBY_GC_MALLOC_LIMIT_MAX=1000000000    # 1G
export RUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR=1.1
# export RUBY_GC_OLDMALLOC_LIMIT=500000000      # 500M
# export RUBY_GC_OLDMALLOC_LIMIT_MAX=1000000000 # 1G
# export RUBY_GC_OLDMALLOC_LIMIT_GROWTH_FACTOR=1.1

Performance MRI Ruby Patch

$ rvm install 2.1.2 --patch railsexpress -n railsexpress
$ rvm --default use 2.1.2-railsexpress
Denis Denisov
  • 661
  • 8
  • 17
  • 1
    Some commends in the 2nd snippet are misleading: `RUBY_GC_HEAP_INIT_SLOTS` & `RUBY_GC_HEAP_FREE_SLOTS` represent absolute numbers, not bytes. – Agis Jun 03 '15 at 13:14