Features

Runtime

Memory, CPU, the event loop, garbage collection, open handles and requests of each process, with leaks traced to the function holding the memory, blocks to the function that ran, processes at their limit called out, and an alert when the app goes down.

Node.js runs your code on one thread. When synchronous work holds it (a large JSON.parse, a slow regular expression, a sync file or crypto call, a long loop), nothing else runs: every request in flight waits. PeekInside measures that, and the process around it.

Event-loop blocks#

When the event loop is blocked for 100 ms or more, every request in flight records it: an Event loop blocked span on its timeline, a finding at the top of its overview ("The event loop was blocked for 820 ms during this request in renderInvoice (src/invoice.ts:88)"), and a counter the Requests page filters on with has:block.

The span names the code that ran while the loop was held, from a CPU profile: the functions that took the time, the most first, each with its location (opening in your editor locally) and, when the time went into a package's or Node.js's function, which one ("in Node.js's pbkdf2Sync"). The work may belong to another request running at the same time; the function says whose it is. See What blocked the event loop.

Change the threshold with loopBlockMs (at least 50), or turn it off with loopBlockMs: false.

The Runtime page#

Each process of the project samples itself: every 10 seconds for the local dashboard, every minute for PeekInside Cloud. The page has six parts.

  • The numbers. Processes running and stopped, memory, CPU, the event loop's delay, requests a minute, and the share of time spent collecting garbage, across the processes on screen.
  • Findings. What looks wrong, in plain words, with the process it's about: memory that keeps growing (a likely leak, with the function whose memory grows), memory outside the heap that keeps growing (Buffers), a heap close to its limit, a process that stopped near its heap limit (with what held the memory), a blocked event loop (with the function that blocked it), a CPU at its limit for minutes on end, garbage collection taking too much time, open handles that only go up, and processes restarting.
  • Processes. A row per process: whether it runs, its environment, Node.js version and release, its memory over the window, heap (and how much of its limit), CPU, loop delay and requests a minute. Sort by any of them; a click shows that process's charts, and All processes shows them added up.
  • Charts.
Chart Shows
Memory The JavaScript heap, resident memory (RSS) and memory outside the heap (buffers); the heap's limit when it gets close
CPU The share of one core the process used, and how much of the time its event loop was busy
Event-loop delay How late timers ran: the median, the 99th percentile and the worst
Requests Requests finished a minute, and the most open at once
Garbage collection Time spent collecting a minute, and the longest pause
Open handles Sockets, timers and files the process holds open
  • What blocked the event loop and where memory is held. The functions behind each block, from CPU profiles, and the functions holding the heap, from heap profiles: see What blocked the event loop and Memory leaks.

Drag across any chart to zoom into that stretch of time; the chip above goes back. The window (15 minutes to 30 days in PeekInside Cloud, up to six hours in the local dashboard), the filters (status, environment, release) and the process shown are part of the page's address, so a link opens the same view.

Once there are 20 minutes of samples, the page reads the heap after garbage collection (the lowest heap of each period): when it keeps rising, steadily, it says so, with how fast (for example "grew 180 MB in 6 hours, 30 MB an hour"). That is what a memory leak looks like; a sawtooth, or a cache that fills once, is not.

What blocked the event loop#

PeekInside 1.4 and later keep V8's CPU profiler running in each process, recording what the thread runs every 10 ms (about 0.1% of CPU). When the loop is blocked, the samples from that stretch are added up by function: your own function that ran, with the package's or Node.js's function it was mostly in, else the package's own. Built-ins such as JSON.parse or a regular expression count as the function that called them.

What blocked the event loop, on the Runtime page, lists those functions for the process shown (with several on screen, the one blocked the longest): how many blocks each was in, the time it took in all and its share, and the most in one block. The blocked loop's finding names the function that took the most ("Most of the blocked time went to renderInvoice (src/invoice.ts:88): 4.5 s in 10 blocks"), and every request that waited names the functions on its timeline.

A row Means
renderInvoice src/invoice.ts:88 Your function: its own code, or a built-in it called (JSON.stringify, a regular expression)
hashPassword src/auth.ts:14 in Node.js's pbkdf2Sync Your function, its time mostly in a Node.js function it called
parseRow node_modules/mysql2/... mysql2 A package's own function, with no code of yours on the stack
Garbage collection V8 collecting garbage while the loop waited

The profiler starts with the app, which costs a pause of tens of milliseconds once, in a large app; reading it afterwards costs a fraction of a millisecond. V8 can only place code it compiled while profiling: a loop that was optimized before the profiler started is counted as the function that called it, until the process restarts. Locally, a block is summed into a window a minute; on servers, every five minutes. Only code locations and times leave the process. To read the profiler without stopping it, PeekInside takes turns between two profiles, one of them a console profile named peekinside: with Chrome DevTools attached and its profiler open, those turns show there. Turn it off with cpuProfiling: false.

On servers it comes with PeekInside Cloud's Pro plan and up. It starts with the app there too (it can't place code compiled before it started), and stops at PeekInside Cloud's first answer when the plan doesn't include it.

Memory leaks#

Knowing that memory grows is half the answer; the other half is which code holds it. PeekInside 1.4 and later keep V8's sampling heap profiler running in each process (it records about one allocation in every 512 KB, a cost of a few percent of CPU at most), and now and then read what it found: the objects still alive, added up by the function that allocated them. When a package or a built-in allocated, the memory is put on the function of your own code that called it, with the package named beside it.

Where memory is held, on the Runtime page, lists those functions for the process shown (with several on screen, the one whose heap grows fastest): what each holds in the latest profile, its share of the heap, its growth an hour fitted across the profiles, and a line of it over the window. Functions that hold more in every profile come first, marked: that is where a leak is. In the local dashboard, a function's location opens in your editor.

A row Means
remember src/cache.ts:12 Your function: it allocated the memory, or called the built-in that did
listUsers src/api/users.ts:30 through lru-cache Your function, through a package it called
parseFeed node_modules/xml2js/lib/parser.js:40 xml2js A package's own function, with no code of yours on the stack

The findings use them too: a leak's finding names the functions growing fastest ("Growing fastest: remember (src/cache.ts:12), 31 MB an hour"), and when a process stops with its heap close to its limit, a finding says it likely ran out of memory and what held the memory in its last profile. Near the limit (90% of the heap's limit, or of a container's memory limit), the SDK reads a profile early and sends it at once, at most once a minute, so the last one is there even when the process dies right after.

Each profile is per process, read every minute for the local dashboard and every five minutes for PeekInside Cloud. A line is where the function starts: V8 records allocations by function, not by line. The amounts are estimates from samples, of objects still alive; the contents of Buffers and ArrayBuffers live outside the heap and aren't counted (the Memory chart shows them).

Only code locations and byte counts leave the process: function names, file paths, packages and amounts, never the values in memory. PeekInside Cloud stores the locations sealed with the project key, like requests, and your browser opens them; when and how much stay readable. Heap profiles come with PeekInside Cloud's Pro plan and up, and are always on in the local dashboard. Turn them off with heapProfiling: false. When another tool already samples the heap (a profiler of your APM, an open DevTools session), PeekInside leaves the heap to it.

To hear about a leak before a process runs out, set an alert on the Runtime page's Heap growth an hour (see Alerts): it is fitted to the last hour of samples, after garbage collection.

Event-loop busy time, garbage collection, open handles and request counts come from PeekInside 1.2.5 and later; processes running older versions show the rest.

The local dashboard keeps the last six hours of each process in memory. PeekInside Cloud keeps samples like requests.

Samples are numbers only (memory, CPU, delays, counts, the process id and Node.js version); PeekInside Cloud stores them readable. Turn them off with runtime: false, which turns off heap profiles too.

App down#

On a server, every process the SDK runs sends PeekInside Cloud a sample once a minute, whatever its traffic. When none of an environment's processes has reported for 5 minutes, PeekInside says the app is down, and when one reports again, that it's back up and for how long it was down. It tells the members who read the runtime: in the app on every plan, by email and in the organization's Slack with Pro and up, each as their notification settings say.

The email says when the last report came, how many processes were running then, and their release. A crash, a stopped server and a network that can't reach PeekInside all look the same from here, as silence; a crash's error, when it had time to report it, is on the Exceptions page.

Change it on the project's Alerts page, under Built in: down after 2 minutes to an hour, or off; every environment but development and test, or only those you choose. The same place shows how each environment stands, and forgets one the project no longer runs.

What doesn't count as down:

  • A restart: a deploy's restart takes less than the wait.
  • A short run: an environment that reported for less than 10 minutes before going quiet, such as a script or a test run that ended.
  • A long-gone environment: one silent for over a day.
  • A paused organization: when its PeekInside Cloud is paused, its apps stop sending.
  • PeekInside not hearing: after PeekInside itself restarts, it waits for the SDKs to send what they kept meanwhile; and when many apps go quiet at once, it tells nobody, as the silence is more likely its own.

An app with sampling off (runtime: false) sends no samples, so it can't be told down.