Diagnose Node.js Event Loop Delays

8 steps · about 3 h 30 min · Intermediate

  1. Recognize work that blocks Node.js (guide, Node.js Documentation, 30 min)

    Understand how expensive callbacks and worker-pool tasks harm throughput and latency.

  2. Measure event-loop delay (reference, Node.js Documentation, 25 min)

    Collect a histogram of scheduling delays instead of inferring blockage only from request latency.

  3. Publish low-overhead diagnostic context (reference, Node.js Documentation, 20 min)

    Observe application events through named diagnostic channels without coupling probes to business logic.

  4. Capture a CPU profile with Linux perf (guide, Node.js Documentation, 30 min)

    Find hot JavaScript, native and system frames during a reproducible slow interval.

  5. Inspect active process resources (reference, Node.js Documentation, 25 min)

    Check process resource and timing information that can explain why the event loop remains busy.

  6. Trace asynchronous resource lifecycles (reference, Node.js Documentation, 30 min)

    Relate callbacks to the async resources that created and triggered them when control flow is unclear.

  7. Move CPU-heavy work to worker threads (reference, Node.js Documentation, 30 min)

    Isolate suitable computation from the main event loop while accounting for messaging overhead.

  8. Repeat profiling through the inspector (reference, Node.js Documentation, 20 min)

    Capture comparable CPU profiles before and after a change to verify that the hot path and delay actually improved.