Back to results for “Profiling”
Node.js › Debugging & Diagnostics

How would you use the 'clinic.js' toolset (clinic doctor, clinic flame) to diagnose a Node.js performance problem?

Advanced

Answer

clinic doctor runs an application under load and produces a diagnostic report highlighting likely categories of problems (event loop blocking, I/O bottlenecks, memory issues) based on observed metrics, pointing you toward which specific tool to use next. clinic flame generates a flame graph -- a visualization of where CPU time is actually being spent across the call stack -- making it straightforward to visually identify which specific function is consuming a disproportionate share of CPU time during a profiling run.
npm install -g clinic

clinic doctor -- node server.js
# generates a report suggesting likely problem categories

clinic flame -- node server.js
# generates an interactive flame graph after the app is exercised under load
Real-world example A team investigating unexplained latency spikes runs clinic doctor against their API under simulated load, which flags 'Event Loop' as the likely culprit; following up with clinic flame reveals a specific synchronous JSON.parse() call on very large payloads as the actual function consuming the disproportionate CPU time blocking the event loop.

Common follow-ups: How do you interpret a flame graph's width versus its depth in terms of what each represents?;What's the difference between clinic's diagnostic categories and what a raw CPU profile alone would tell you?