Limits of concurrent request handling in R's single‑threaded interpreter
0 reputation · 18 Jul 2025, 06:03 UTC
Goal
Determine the practical concurrency ceiling for R services such as Plumber or Shiny before latency spikes become unacceptable.
Constraints and uncertainty
Base R runs a single‑threaded interpreter, so simultaneous requests are serialized. On Unix, parallel::mclapply forks child processes, adding fork‑and‑IPC overhead that grows with worker count. Garbage collection performs stop‑the‑world pauses; high allocation rates from concurrent request parsing can lengthen these pauses, especially on memory‑constrained hosts. Windows lacks fork, forcing alternative cluster or external‑worker strategies that introduce startup latency. No standardized concurrency API exists, leaving the choice of fork, cluster, or external workers as an unresolved design decision.
Open questions
- At what request rate do GC pauses dominate tail latency on an 8‑core Linux server?
- Does replacing
mclapplywith aparallel::clusterbackend reduce tail latency for Plumber endpoints under the same load? - Which memory‑allocation patterns in request handling trigger the longest stop‑the‑world pauses during concurrent bursts?