Q17: What is Event Loop Delay (Lag) and how can you measure it in production?

Event Loop Delay (or lag) measures the latency between when a timer callback is scheduled to execute and when it actually gets invoked by the Event Loop. High delay indicates that synchronous operations are blocking the main thread, delaying asynchronous task processing. Production metrics can track this using perf_hooks with monitorEventLoopDelay(), which samples execution intervals and generates histogram percentiles (p50, p99) of Event Loop lag.

Key Takeaways
  • Event Loop lag indicates main thread blocking caused by heavy synchronous computation.
  • perf_hooks.monitorEventLoopDelay() samples and calculates precise latency histograms for monitoring.
Knowledge Check

Which core Node.js module contains monitorEventLoopDelay() for latency tracking?