Feature #7472
closedAdd a mechanism to remove objects from the GC cycle
Description
For typical rails apps there is a huge largely static object graph in memory. Requests come in, some objects are added, and the GC runs.
The blocking nature of the GC introduces a jitter that stops all execution.
In our typicalish Rails application, we see approximately 500k objects in the object space, each request add about 150k objects. On our production machine this means the GC stops execution for 30-40ms on a fairly beefy box:
GC Profiler ran during this request, if it fired you will see the cost below:
GC 457 invokes.
Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC Time(ms)
1 11.169 13134480 17014400 425360 40.00200000000120326149
2 11.249 13350000 17014400 425360 32.00199999999853162080
It is clear that introducing a full scoped generational GC is a massive undertaking, but I was thinking that certain GC apis can make application servers like thin,unicorn or puma operate way more efficiently.
How about we add.
GC.skip(object) # remove object from GC cycle, essentially copy the ref to a place that is not scanned
GC.queue(object) # add an object back to the GC cycle
GC.skipped # list all the objects that are skipped
Careful use of these methods can reduce GC code by a very large amount as it would reduce fragmentation and logic required to determine if an object is alive or not.
Application servers could keep snapshots of object ids on regular intervals and decide which ones to skip. Sure memory usage would rise, but GC blocking would decrease.
Thoughts?