Skip to content

Performance monitoring

Node.js performance monitoring

Node.js runs your JavaScript on one thread. Anything that blocks it slows every request at once, so event loop delay is the first number to watch.

2 min read8 sectionsUpdated

On this page

Node.js metrics that matter

MetricMeaningWorry when
Event loop delay (p99)How long callbacks wait to runAbove ~100 ms; everything is slower
Event loop utilizationShare of time the loop is busyNear 1.0 under normal traffic
Heap used / heap limitV8 memory for JS objectsClimbs and stays high after GC
RSSTotal process memory, including buffersNear the container limit
Active handles / requestsOpen sockets, timersGrows without bound (leaked sockets)
Request p95 per routeUser-facing latencyAbove target

Measuring event loop delay

javascript
import { monitorEventLoopDelay, performance } from 'node:perf_hooks';

const h = monitorEventLoopDelay({ resolution: 20 });
h.enable();
setInterval(() => {
  const elu = performance.eventLoopUtilization();
  console.log(JSON.stringify({ msg: 'loop', p99_ms: h.percentile(99) / 1e6, utilization: elu.utilization }));
  h.reset();
}, 60_000).unref();

Typical Node.js bottlenecks

  • Synchronous work on the main thread: JSON.parse of large bodies, crypto without async variants, regexes with catastrophic backtracking, fs.*Sync.
  • Unbounded concurrency: Promise.all over thousands of items opens thousands of sockets.
  • Connection pools too small for pg or mysql2, so queries queue.
  • Memory leaks from caches and listeners; see Node.js memory leaks.
  • Unhandled promise rejections crashing the process; see unhandled promise rejection.

Instrumenting

Load the OpenTelemetry SDK before your app with node --import ./instrumentation.mjs server.js and export JSON straight to VitalRix with an API key. Step by step: Node.js tracing guide, NestJS, Next.js. For CPU profiles, node --cpu-prof writes a profile you can open in Chrome devtools as a flame graph.

Frequently asked questions

Should I use worker threads?

For CPU-heavy tasks, yes, or move them to a separate service or queue. Keep the main thread for I/O.

How many Node processes per machine?

Usually one per CPU core (cluster mode, PM2 or several containers), since each process uses one main thread.

Check it now, free

  • Node.js event loop lag: how to measure and fix it: Measure and fix Node.js event loop lag: monitorEventLoopDelay, CPU profiles, synchronous code, big JSON and worker threads, with thresholds that matter.
  • OpenTelemetry for Flask: Instrument a Flask app with OpenTelemetry, in code or with zero code: trace routes, SQLAlchemy and outgoing calls, and export to VitalRix.
  • Go performance monitoring: Monitor Go services: goroutine counts, GC and heap, request latency per handler, pprof profiling in production and OpenTelemetry tracing with otelhttp.
  • PHP performance monitoring: Monitor PHP and Laravel apps: request latency, PHP-FPM worker saturation, OPcache hit rate, slow queries, external calls and errors.
  • Python performance monitoring: Monitor Python web apps: request latency per route, worker saturation, the GIL and CPU-bound code, database time, Celery queues and memory.
  • Ruby and Rails performance monitoring: Monitor Ruby on Rails apps: request latency per action, Puma thread and worker saturation, ActiveRecord queries, Sidekiq queues, memory bloat and GC.

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.