Skip to main content

DRAIN_LINGER_ENV

Constant DRAIN_LINGER_ENV 

Source
pub const DRAIN_LINGER_ENV: &str = "NAPI_RUNTIME_DRAIN_LINGER_US";
Expand description

Environment variable overriding the MultiThread drainer idle-linger budget in MICROSECONDS (RuntimeOptions::drain_linger, consumed by MultiThreadExecutor::drain). After a drainer runs the runnable/blocking queues empty it parks on its own [DriverParker] (registered with parked_drivers) for up to this long before returning its thread to rayon. A wave of work arriving within the budget is resumed by ONE targeted condvar wake instead of a spawn_fifo respawn through rayon’s idle protocol – whose per-transition cost (a wake cascade plus 33 sched_yield rounds and a full steal sweep on EVERY worker that was woken) is what makes system CPU scale with the worker count under wave-shaped loads. 0 disables lingering (legacy exit-and-respawn on every empty queue); values above MAX_DRAIN_LINGER_MICROS are clamped. A frame’s TOTAL lingering residence is additionally capped at [DRAIN_LINGER_FRAME_FACTOR] times this budget so periodic sub-budget work cannot pin a rayon worker inside one drain frame forever.

Like PARK_DEADLINE_ENV, the runtime does NOT read this variable itself: it is resolved once at addon load into RuntimeOptions::drain_linger – by the napi adapter’s install (via resolve_drain_linger) for hosts that use it, while hosts owning their own env resolution may resolve their own variable into the same field. A present-but-non-numeric value keeps the host-provided field (which defaults to DEFAULT_DRAIN_LINGER_MICROS).