Ruby Performance. Part 1 (Garbage Collection)

1,475 views
1,405 views

Published on

Slides from meetup.com/madruby on tweaking Ruby GC settings. by Gleb Mazovetskiy (2010)

1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
1,475
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
3
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Ruby Performance. Part 1 (Garbage Collection)

  1. 1. Ruby Performance scaling your Ruby web app Part 1: Garbage collection
  2. 2. MRI/REE Facts • Mark & sweep GC • freelists • very expensive • All refs are on the heap • All code is on the heap
  3. 3. GC Settings RUBY_HEAP_MIN_SLOTS 10k RUBY_HEAP_SLOTS_GROWTH_FACTOR 1.8 Defaults startup + 20k + 10k + 18k ... 10k 10k + 10k 10k + 10k + 18k 10k + 10k + 18k + 32.4k ... RUBY_HEAP_SLOTS_INCREMENT 10k 10 000 20 000 38 000 70 400 128 720
  4. 4. A better strategy • Stabilize on 1-2 heaps RUBY_HEAP_MIN_SLOTS (480 000) • Linear increment to keep it tight RUBY_HEAP_SLOTS_GROWTH_FACTOR 1 RUBY_HEAP_SLOTS_INCREMENT (20 000)
  5. 5. Some tools memprof, gdb, scrap [68.63 MB] GET /stats/scrap Number of objects : 815266 (627150 AST nodes, 76.93%) Heap slot size : 20 GC cycles so far : 352 Number of heaps : 7 Total size of objects: 15923.16 KB Total size of heaps : 18036.55 KB (2113.39 KB = 11.72% unused) Leading free slots : 18545 (362.21 KB = 2.01%) Trailing free slots : 0 (0.00 KB = 0.00%) Number of contiguous groups of 16 slots: 2685 (4.65%) Number of terminal objects: 4697 (0.51%)
  6. 6. Thanks Gleb Mazovetskiy. github.com/glebm

×