Event loop delay and throughput
Prerequisite: node-cpu-profiling. Objective: Measure bounded workload. Tested locally on Node.js 22.16.0 Linux. Each example is independent. Use a fresh disposable working directory, save as main.mjs, then run node main.mjs. The harness uses a five-second timeout and synthetic environment. These are static code blocks, not ByteMind interactive execution.
How it works
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.
Observe a bounded delay histogram
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();}Expected output:
histogram sampledThe delay histogram has samples; the test does not require an exact measured duration.
Calculate success throughput and failure count
const report={success:180,failed:20,seconds:4};console.log(report.success/report.seconds, report.failed);Expected output:
45 2045 successful operations per second; failures are not counted as successes.
Common mistakes
An average or a single short p99 is not a capacity guarantee. Do not equate event loop utilization with whole-machine CPU utilization.
Practice
Compare two intervals of equal load and record delay, successful throughput, error count and sample count.
Reference candidate: node-event-loop-delay-and-throughput-lookup (route unverified). Documentation: https://nodejs.org/download/release/v22.16.0/docs/api/perf_hooks.html (opened).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Event loop delay and throughput — knowledge check
Apply the lesson to a fresh scenario and explain the evidence boundary.
A histogram p95 is 15000000 ns. What is it in milliseconds?
A run completes 90 successes and 10 failures in 2 seconds. What is successful throughput?
What does high event loop utilization establish by itself?