Performance

Event loop delay and throughput

Event loop delay measures how late scheduled loop activity occurs; throughput counts completed work per unit time. A busy JavaScript callback can delay other requests even when total CPU usage appears modest. Use `monitorEventLoopDelay({ resolution: 10 })` from `node:perf_hooks` to sample delay in nanoseconds. Enable the histogram before the workload and disable it afterwards; divide percentile values by 1e6 for milliseconds. `performance.eventLoopUtilization()` measures active versus idle event loop time, not host CPU percentage. Compare two snapshots for an interval. Throughput is completed successful operations divided by elapsed seconds; report failures separately. A short sample cannot establish a production p99. Collect enough observations under representative load and report workload, concurrency, duration and runtime. An average or a single short p99 is not a capacity guarantee. Do not equate event loop utilization with whole-machine CPU utilization. Sources: https://nodejs.org/download/release/v22.16.0/docs/api/perf_hooks.html.

Formal Syntax & Structure

nodejs syntaxnodejs
monitorEventLoopDelay(options); performance.eventLoopUtilization()

Working Example

Example Snippetnodejs
import {monitorEventLoopDelay, performance} from 'node:perf_hooks';import {setTimeout as sleep} from 'node:timers/promises';import assert from 'node:assert/strict';const h=monitorEventLoopDelay({resolution:10}); h.enable();try {  await sleep(50); const start=performance.now();  while(performance.now()-start<25) {} // intentionally bounded CPU work  await sleep(50);  assert.ok(h.count>0 && Number.isFinite(h.percentile(95)));  console.log('histogram sampled');} finally {h.disable();}
Node.js Reference