How do you diagnose high CPU usage in Node.js?

Start by determining whether the CPU usage is caused by application JavaScript, garbage collection, native work, or external dependencies. CPU profiles, flame graphs, event-loop monitoring, application metrics, and system-level tools can identify expensive functions. Common causes include inefficient algorithms, large synchronous computations, excessive serialization, tight loops, and unexpectedly high traffic.

Key Takeaways
  • Profile before guessing.
  • Use CPU profiles and flame graphs.
  • Investigate event-loop latency and garbage collection as well.
  • Optimize the actual bottleneck.
Knowledge Check

Which tool or technique is useful for identifying CPU-intensive JavaScript functions?