class IdleGC::IdleDetection

Defined in:

idle-gc/idle_detection.cr

Constant Summary

DEFAULT_IDLE_DETECTION_REPEAT = 1_u8
DEFAULT_IDLE_THRESHOLD = 100.microseconds

Class Method Summary

Class Method Detail

def self.enabled : Bool #

[View source]
def self.enabled=(v : Bool) : Nil #

Idle detection is enabled by default, but it is based on a heuristic which may be inaccurate, so you may wish to disable it by calling IdleGC::IdleDetection.enabled = false.

If disabled, then IdleGC::IdleDetection.process_is_idle? will always return true, so the IdleGC garbage collection will always run.

If your workload is not latency-sensitive, then running GC periodicially regardless of whether the system is idle may be optimal.


[View source]
def self.fiber_yield_time : Time::Span #

How long does it take for Fiber.yield to return?

This is a measure of whether there are other Fibers waiting to do work.


[View source]
def self.fiber_yield_time_ns : UInt64 #

[View source]
def self.idle_detection_repeat=(v : UInt8) : Nil #

To reduce idle false-positives, we can check multiple times in succession. Default is 1.


[View source]
def self.idle_threshold=(v : Time::Span) : Nil #

Set the idle threshold for comparing to IdleGC::IdleDetection.fiber_yield_time.

Experimentally, I found Fiber.yield took about ~5us when idle, and ~500us (or more) when busy, but this will depend on your workload.


[View source]
def self.process_is_idle? : Bool #

Return true if the process is idle, as determined by #fiber_yield_time compared to #idle_threshold=.


[View source]