What this thread does
Do first: enable monitorEventLoopDelay({ resolution: 20 }) around representative traffic, then distinguish CPU computation from waiting on I/O.
Short answer
As of November 2026, Node.js 26.13.1 LTS is the release baseline. Use a reusable, admission-bounded pool for CPU-heavy JavaScript.
Choose / don't choose
- Worker pool: choose sustained computation; don't create a worker per small request when startup and message overhead dominate.
- Async I/O: choose file/network waiting; don't add workers merely to wait on sockets.
- Separate process: choose when memory failure needs a stronger isolation boundary; don't treat a worker heap cap as a process memory cap.
Not for: locating a hot function with a CPU profile; see node-app-slow-find-cpu-hot-function-cpu-prof-cpuprofile.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
monitorEventLoopDelay.resolution | Start at the documented example's 20 ms; default 10; positive number | Current Node docs | perf API |
samplePerIteration | false for resolution-based sampling; true ignores resolution and changes measurement semantics | Current Node docs | perf API |
resourceLimits.maxOldGenerationSizeMb | Select a measured per-task heap budget in MB; process --max-old-space-size overrides it | Current Node docs | Worker |
resourceLimits.maxYoungGenerationSizeMb | Set young-heap budget in MB if needed; --max-semi-space-size overrides it | Current Node docs | Worker |
stackSizeMb | Default 4; undersizing can make the worker unusable | Current Node docs | Worker |
Delay samples use nanoseconds. Enable before traffic, record percentiles and reset between windows. Lower intervals require an overhead comparison under the actual load; no source supplies a universal optimum (perf API).
Order of operations
1. Separate synchronous parsing/computation from async dependencies. Bound task admission and payload size before queueing; pool size alone does not bound queued memory. 2. Use an AsyncResource for pool task tracking. Deliver success and failure through runInAsyncScope, then call emitDestroy() once. The example uses WorkerPoolTaskInfo objects for explicit tracking (AsyncResource example). 3. Register error and message handling before dispatch. Reject the task's promise on error, map that rejection to an HTTP outcome, remove the dead worker and replenish capacity. A single completion guard prevents an error followed by exit from settling twice; an exit with an outstanding task must also settle it (pool example). 4. At request cancellation or pool shutdown, account for queued and active tasks separately; dispose task resources on every completion path.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
error | Worker uncaught exception terminates its thread | Reject associated computation and replace worker; handle idle-worker errors too | Worker events, pool |
| Global out-of-memory | Heap limits do not cap external allocations; global out-of-memory may still abort the process | Bound inputs and concurrency; use process isolation for stronger containment | Worker limits |
| Heap cap overridden | Global process flags take precedence | Audit startup flags before relying on per-worker limits | jloleysens report |
Worker limits apply only to the JS engine, excluding ArrayBuffers. The two independent reports document whole-process OOM and surprising limit precedence; neither establishes containment for arbitrary computation.
Missing
- The linked source does not confirm: Async I/O avoids blocking while waiting
- The linked source does not confirm: wrapping CPU work in a promise does not move execution off the event loop.
- No universal resolution, heap size or worker count meets every latency and memory budget.
Checked
2026-11-12; Node.js release, perf, worker, AsyncResource and event-loop guidance read; KeunwooLee-at and jloleysens dated reports read. No application or load commands executed.
Started from a post by @Node.js, packaged by the editor. Original post