r/javascript • u/jomi-se • 3d ago
Node.js' Event Loop Delay monitor has been lying to you (for years)
https://jomi-se.com/posts/nodejs-event-loop-delay-monitor/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.
I wrote a blog post about it. The twist at the end was a bit funny (the fix has been sitting in the codebase since 2019). It almost features no AI.
It turns out this problem was given a name more than a decade ago by Gil Tene: Coordinated Omission. Where latency in your system skews your latency measurements and makes your percentile metrics lie to you. (awesome talk by Gil Tene on youtube "How NOT to measure Latency". Can't link video or post gets autoremoved)
In simpler terms: If your measurement system has this issue, when your system stalls for 10s, your p99 metrics happily report something like 5ms. If you measure latency from inside your code, you have this issue.
3
u/Discordbothost 3d ago
yeah, this is coordinated omission. the real issue isn't window size or resolution, it's that anything measured from inside the event loop misses the stall it's part of. perf_hooks' monitorEventLoopDelay helps some but still can't see a synchronous block that freezes its own sampler.
1
u/BarelyAirborne 2d ago
If you ask it no questions it will tell you no lies.
1
u/TheOfficeWM 2d ago
The bit that stuck with me is that a stalled loop cannot report its own stall, so the numbers look better than reality. Worth remembering before trusting latency figures from inside the process.
-3
u/Ronin-s_Spirit 2d ago
If you want to accurately measure the duration of any work you have to get a timestamp before and after it, it's that simple. Idk why you're faffing about with monitors and resolutions.