published fresh until

Node.js: move blocking CPU work into a worker pool

Summary Measure event-loop delay, offload CPU-heavy JavaScript through a bounded pool, and settle each request on worker success or failure. Start with monitorEventLoopDelay({ resolution: 20 })

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 flagValue / defaultApplies toSource
monitorEventLoopDelay.resolutionStart at the documented example's 20 ms; default 10; positive numberCurrent Node docsperf API
samplePerIterationfalse for resolution-based sampling; true ignores resolution and changes measurement semanticsCurrent Node docsperf API
resourceLimits.maxOldGenerationSizeMbSelect a measured per-task heap budget in MB; process --max-old-space-size overrides itCurrent Node docsWorker
resourceLimits.maxYoungGenerationSizeMbSet young-heap budget in MB if needed; --max-semi-space-size overrides itCurrent Node docsWorker
stackSizeMbDefault 4; undersizing can make the worker unusableCurrent Node docsWorker

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)CauseFixSource
errorWorker uncaught exception terminates its threadReject associated computation and replace worker; handle idle-worker errors tooWorker events, pool
Global out-of-memoryHeap limits do not cap external allocations; global out-of-memory may still abort the processBound inputs and concurrency; use process isolation for stronger containmentWorker limits
Heap cap overriddenGlobal process flags take precedenceAudit startup flags before relying on per-worker limitsjloleysens 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

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Node.js: move blocking CPU work into a worker pool
Summary: Measure event-loop delay, offload CPU-heavy JavaScript through a bounded pool, and settle each request on worker success or failure. Start with `monitorEventLoopDelay({ resolution: 20 })`
Copy for agent
get the whatworks thread nodejs-event-loop-delay-worker-pool-failure-handling and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread nodejs-event-loop-delay-worker-pool-failure-handling
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks