Node.js' Event Loop Delay monitor has been lying to you (for years)
In Node.js, if your event loop blocks for 30 seconds with a monitor that has a 60-second window and 50 milliseconds resolution, you'll get a p99 event loop delay of 52 milliseconds. And if you're lucky, the 30-second delay might show up in the max of the event loop delay monitor.
The event loop delay monitor lies.
Back in 2020, I was trying to measure the event loop in Node.js, and I came across the event loop delay monitoring function, monitorEventLoopDelay. And I said, oh, that's cool, let's test it out. I wrote a test to see how it works and how it reported. I tested a relatively simple case: you have the thing running, you block the event loop manually for a couple of seconds, and see what it reports.
Here's a realistic-ish code snippet that reproduces this issue clearly:
import http from 'node:http';
import { monitorEventLoopDelay } from 'node:perf_hooks';
import { Worker } from 'node:worker_threads';
const log = (...args) => console.log(new Date().toISOString().slice(11, 19), ...args);
const ms = (ns) => Math.round(ns / 1e6);
// 10 ms resolution: the default in prom-client and OpenTelemetry.
const delay = monitorEventLoopDelay({ resolution: 10 });
delay.enable();
// A /metrics endpoint that reads the monitor, then resets it, like prom-client does.
const server = http.createServer((req, res) => {
log(`/metrics: event loop delay max ${ms(delay.max)} ms, p99 ${ms(delay.percentile(99))} ms`);
delay.reset();
res.end();
});
// Outlive the AWS load balancer's 60 s idle timeout: the usual advice to avoid 502s.
server.keepAliveTimeout = 65_000;
server.listen(0, () => {
// Prometheus, on another thread: a scrape every 60 s, over a kept-alive connection.
new Worker(`
const http = require('node:http');
const agent = new http.Agent({ keepAlive: true });
setInterval(() => http.get({ port: ${server.address().port}, path: '/metrics', agent }, (res) => res.resume()), 60_000);
`, { eval: true });
});
// A 3 s block that happens to overlap the second scrape.
setTimeout(() => {
log('blocking the event loop for 3 s');
const end = Date.now() + 3000;
while (Date.now() < end);
log('done blocking');
}, 118_500);
If you run that, you will get results like this:
21:55:01 /metrics: event loop delay max 12 ms, p99 11 ms 21:55:59 blocking the event loop for 3 s 21:56:02 done blocking 21:56:02 /metrics: event loop delay max 13 ms, p99 11 ms 21:57:01 /metrics: event loop delay max 16 ms, p99 11 ms
Depending on how keepAliveTimeout is set up and how you report your stats, this problem can be exacerbated in a way that you even lose the stalls being reported on the max property returned by the event loop delay monitor.
I first reported this issue in 2020 (nodejs/node#34661). It's a big wall of text that explains the issue, but it practically boils down to this: the event loop delay monitor takes samples at a quick sample rate, and uses them to measure how much delay there is between those samples, expecting those delays to be relatively small compared to the sample rate. But when you get big stalls in Node.js, the statistics for those samples do not take into account that many of them were never taken, never measured, which skews the measurements towards the low side, hiding actual big stalls in the stats.
I opened the issue with a reproduction and a suggestion on how to unskew the statistics by filling in the estimated missing samples, if we want to measure event loop stalls that go over the sample rate.
The issue was picked up by the maintainers at the time and got a bit of interaction, but not much traction in the end. It stayed open for a while. I discussed with a maintainer the idea of recording skipped samples, but no one ever really built that, neither me nor them. And it probably didn't help that ELU was suggested as a complement to this monitor, as a better measure of how busy Node.js is, even though it's not a good replacement to catch what I was looking for, which is big stalls of the Node.js event loop. In the end, the issue was just closed by a stale bot. And that was it.
So in my case, at the time, I took the pragmatic road: I simply stopped using the built-in Node.js version and built my own, which handled this issue in a different way. And that was that for many years.
About 6 years later, we had had Datadog integrated with our codebase for quite a while, which meant that Datadog's own tracer library was already reporting event loop delay metrics, which was redundant with our hand-coded implementation. So we decided to just remove the handmade one, to stop sending these metrics and paying for them twice. And that was it, for a while.
Funnily, a few weeks after we deleted my monitor, I was trying to measure some code that I suspected would behave badly and block the event loop. I asked a Claude session to measure how bad it would be. So obviously, Claude reached out to the event loop delay monitor built into Node.js. That's the obvious approach. But it knew, by timing it in its test script, that the stall would be something like 400 milliseconds. I was multitasking, as one does with Claude, but for whatever reason I came back to the Claude session, took a look at the Claude traces and noticed it thinking to itself:
One thing doesn't add up: Node's event-loop delay monitor reported only 9 ms. I trust the direct timing, because it's a single synchronous function call.
When I saw that, I kind of lost it, and I told it:
HAH! I KNOW WHY! DON'T TRUST IT lmao. It has never been fixed.
It read the issue I linked, and a bit later I asked it: "Guess who wrote that?"
Ha, so you wrote it. I was checking your own bug report against you.
I had a good laugh about that moment, realizing that this was still an issue and that now even frontier models are still hitting it.
The twist: this is a known problem, and it's older than the Node.js monitor
The name for this problem comes from a talk named "How NOT to Measure Latency", by Gil Tene. He calls it coordinated omission: some coordinated behavior makes some recordings be omitted. Go watch it, it's pretty enlightening. I feel like it's kind of shouting into the void, saying: "Why is no one paying attention to this?"
The point is that if you measure latency this way, by taking recurrent measurements, this method only works if your delays are shorter than the sampling interval. But any delay that goes over it, if you don't take into account how it impacts your sampling, will skew your statistics over time.
Gil Tene argues that this is a very widespread problem.
He actually wrote HdrHistogram, a High Dynamic Range histogram, originally in Java, in the 2010s, which is a histogram built for latency. It's widely used in many languages, and someone called Michael Barker ported it to C. One function to record these values accepts an expected interval, and uses it to correct these values in case of bigger latency than expected. It's the one that should be used in many cases. What it does is, based on the expected interval, it will include the values that would have been missed by a stall. And a monitor like ours, specifically a Node.js monitor for event loop delay, is the perfect case for this correction, in which the interval is known by ourselves, because it's set by ourselves, and it's the reference to measure the event loop delay against.
And here's the kicker. In 2019, there was a commit that vendored this C library to build the event loop delay monitor, and it included this whole library, with the correction. But for whatever reason, the monitor tick calls the plain hdr_record_value, not the corrected one.
// src/node_perf.cc: the monitor's tick
bool ELDHistogram::RecordDelta() {
uint64_t time = uv_hrtime();
// ...
int64_t delta = time - prev_;
if (delta > 0) {
ret = Record(delta);
// ...
// src/histogram-inl.h
inline bool Histogram::Record(int64_t value) {
return hdr_record_value(histogram_, value);
}
// deps/histogram/src/hdr_histogram.h: same commit, same library
/**
* Record a value in the histogram and backfill based on an expected interval.
*
* Records a value in the histogram, will round this value of to a precision at or better
* than the significant_figure specified at contruction time. This is specifically used
* for recording latency. If the value is larger than the expected_interval then the
* latency recording system has experienced co-ordinated omission. This method fills in the
* values that would have occured had the client providing the load not been blocked.
* ...
*/
bool hdr_record_corrected_value(struct hdr_histogram* h, int64_t value, int64_t expexcted_interval);
And the best part: the same header with the corrected function has a comment that explains this problem, and even names it: coordinated omission. And it explains that this method fills in the values that would have occurred.
So the funniest thing about this whole story is that the issue I reported had a fix already existing inside Node.js itself, from the first time this monitor was ever implemented. And it's still there.
Anyone could have noticed it and fixed it, including me.
- Someone else independently reported the same skew on 2026-11-20: nodejs/node#67649, still open.
- Node v26.5.0 and v24.19.0 added a
samplePerIterationoption tomonitorEventLoopDelay. It takes one sample per event loop iteration instead of using a timer, which makes it immune to the loss shown in the snippet. A stall is still a single sample, though, so the percentiles still hide it. - Since August 2026 (nodejs/node#65024), the corrected recording function is exposed to JavaScript as
createHistogram().recordCorrected(value, expectedInterval). In Node's source it sits 25 lines above the monitor's call, which still records with the plain function. - Datadog's runtime metrics (dd-trace-js) don't lose the stall, but they hide it too. They use the
samplePerIterationmode on recent Node versions and flush every 10 s. Reproducing that pattern on Node 26.13.1 with a busy server and a 3 s stall: max 3001 ms, p95 0 ms, median 0 ms, average 1 ms. Only max sees it. (A reproduction of dd-trace's pattern, not dd-trace itself.)