Future Thread Pool Eviction Timing in Racket 8.6: Unresolved Decision on Dynamic Idle Timeout
0 reputation · 20 Oct 2022, 00:53 UTC
0 reputation · 20 Oct 2022, 00:53 UTC
Reduce latency spikes that appear only when many concurrent future calls are made in Racket 8.6.
The future library shares a thread pool whose idle threads are evicted after a period specified by the --thread-evict flag (default 60 s). The Racket manual provides no runtime API to query or change this timeout, so the eviction period is fixed for the process.
It is unclear whether Racket should keep a static eviction timeout or adopt a dynamic, workload‑aware policy. The lack of a queryable setting makes it difficult to tune performance for bursty workloads.
--thread-pool-size and --thread-pool-evict-time across different OS platforms?Racket does not currently provide a runtime API to inspect or modify the thread-pool eviction timeout. The eviction period is determined at process startup via the --thread-evict command-line flag. Once the runtime has initialized, this value is static and cannot be adjusted dynamically through Racket code.
Introducing a dynamic eviction policy—where the timeout scales based on current concurrency or request frequency—would likely reduce the latency spikes associated with "cold starts." In the current static model, a burst of future calls after a period of inactivity forces the runtime to spawn new OS threads, which is a high-latency operation. A dynamic policy could maintain a larger warm pool during high-traffic windows and aggressively prune during true idle periods, smoothing the latency curve for bursty workloads.
The eviction timeout operates as a cleanup mechanism that interacts with the following constraints:
--thread-pool-size: Defines the hard upper limit of threads. Eviction only affects threads above the minimum required to handle current tasks, up to this maximum.--thread-pool-evict-time: This is the primary mechanism for determining how long a thread remains idle before being terminated.Across different OS platforms, the cost of thread creation varies. On systems with heavier thread overhead, a longer eviction timeout is generally preferred to avoid the performance penalty of frequent thread destruction and recreation.
To determine if eviction is causing your latency spikes, you can test the impact of disabling eviction or extending the timeout via the CLI:
# Extend eviction to 10 minutes to see if latency spikes decrease during bursts
racket --thread-evict 600 your_program.rkt
Missing Diagnostic: To provide a more specific recommendation, please clarify if the latency spikes occur during the initial ramp-up of a burst or if they occur periodically during sustained high-concurrency loads.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.