Module: NakayoshiFork

Included in:
Object
Defined in:
lib/nakayoshi_fork.rb,
lib/nakayoshi_fork/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Method Summary collapse

Instance Method Details

#fork(nakayoshi: true, cow_friendly: true, &b) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nakayoshi_fork.rb', line 4

def fork(nakayoshi: true, cow_friendly: true, &b)
  if nakayoshi && cow_friendly
    h = {}
    4.times{ # maximum 4 times
      GC.stat(h)
      live_slots = h[:heap_live_slots] || h[:heap_live_slot]
      old_objects = h[:old_objects] || h[:old_object]
      remwb_unprotects = h[:remembered_wb_unprotected_objects] || h[:remembered_shady_object]
      young_objects = live_slots - old_objects - remwb_unprotects

      # p [[live_slots, old_objects, remwb_unprotects], [young_objects]]

      break if young_objects < live_slots / 10

      disabled = GC.enable
      GC.start(full_mark: false)
      GC.disable if disabled
    }
  end

  super(&b)
end