Node.js can handle many I/O-bound requests on a small number of JavaScript threads, but synchronous work still blocks the event loop. “Async” syntax does not make CPU-heavy computation non-blocking. Understanding which work runs where helps explain latency spikes.
Distinguish the sources of delay
JavaScript callbacks and promise continuations execute on the event loop. Some operations use libuv’s worker pool, while network I/O is generally handled through operating-system facilities. A long synchronous loop, large JSON parse, or expensive regular expression can delay unrelated requests even if those requests are waiting on I/O. Saturated worker-pool tasks can create a different queueing problem.
Measure event-loop delay and utilization alongside request latency and dependency timings. Sample CPU profiles during a representative slow period. Avoid adding a worker thread solely because one request is slow; first find whether the bottleneck is JavaScript CPU, a database, an external API, or the worker pool.
Keep request work bounded
Paginate large data, cap input sizes, and avoid unbounded synchronous transformations. Move substantial CPU work to worker threads or a separate job service when measurement shows the event loop is the constraint. Add queue limits and cancellation behavior so background work cannot grow without bound.
Test under realistic concurrency and payload size. A local microbenchmark may not reveal the effect of garbage collection, network waits, or production traffic patterns. The useful result is a diagnosis tied to a measured queue or blocked phase, not simply the fact that Node is single-threaded in one part of its execution model.
Watch synchronous work delay an asynchronous program
Node schedules timers, I/O callbacks and microtasks through different mechanisms. Its event-loop guide notes that starting with libuv 1.45.0, timers run after the poll phase rather than before and after it. A small print-order demo shows ordering within its own program, while scheduling among timers and I/O in a real service depends on the work that's pending. Node.js event-loop guide
In a local Node.js 24.16.0 run, a 50 ms synchronous spin produced a maximum event-loop-delay sample of about 52.7 ms using the perf_hooks histogram at 10 ms resolution. Record the resolution and duration before interpreting values. In a real API, check whether large JSON parsing, synchronous filesystem work, or application computation coincides with the delay. A slow request waiting on its database might instead leave the loop largely available. Node.js performance measurement reference
Worked example
Run this locally as an ES module. The deliberate busy loop gives the histogram a controlled period of synchronous work. The histogram reports nanoseconds, so the final output converts them to milliseconds.
jsimport { monitorEventLoopDelay, performance } from "node:perf_hooks"; import { setTimeout as sleep } from "node:timers/promises"; const histogram = monitorEventLoopDelay({ resolution: 10 }); histogram.enable(); await sleep(30); const started = performance.now(); while (performance.now() - started < 50) { // Deliberately occupy the local event-loop thread for this experiment. } await sleep(30); histogram.disable(); console.log({ maxDelayMs: histogram.max / 1e6 });




Community
Discussion
Loading comments…