Socket
Socket
Sign inDemoInstall

node-oom-heapdump

Package Overview
Dependencies
20
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-oom-heapdump

Node module which will create a V8 memory snapshot right before an "Out of Memory" error occurs.


Version published
Weekly downloads
2K
increased by12.54%
Maintainers
1
Install size
3.56 MB
Created
Weekly downloads
 

Readme

Source

node-oom-heapdump

Node module which will create a V8 memory snapshot right before an "Out of Memory" error occurs.

Node 8+ required.

Why?

When running nodejs processes in a low memory environment, every out of memory that occurs is interesting. To figure out why a process went out of memory, a memory snapshot (e.g. heapdump) can help a lot. This module creates a memory snapshot right before an suspected out of memory error occurs. It shows what the heap was filled with right before the out of memory error occured.

There are several modules around which can create heapdumps (v8-profiler, node-heapdump), but these run in the same process as the one going out of memory. Often, creating heapdump won't work when the node process is already struggling. This module creates the memory snapshot from a separate process, which solves this issue.

What?

It uses 'gc-stats' to determine when an out of memory error is about to occur and then fires up a new process which uses 'chrome-remote-interface' to connect with the DevTools protocol (https://chromedevtools.github.io/devtools-protocol/v8/) of the calling process. That process uses HeapProfiler to actually create the heapdump and then exits.

Example

Just run "npm test" to see it in action. It creates a heapdump named "my_snapshot.heapsnapshot" in the root.

Usage

npm install node-oom-heapdump

Just add the following snippet to your node process.

require("node-oom-heapdump")({
    threshold: 75,
    name: "my_heapdump"
});

Your node process should at least be started with the "--inspect" (or --inspect=port) flag. When running in a low memory environment, the following flags are advised:

  • --max_old_space_size=60 - this will limit your heapsize on 60MB
  • --optimize_for_size - keep memory as low as possible (GC more often than usual)
  • --always_compact - keep memory as low as possible (do compactions each GC)

These might impact performance though.

Options

  • threshold - integer which determines when to make the snapshot. When the used heapSize exceeds the threshold, a heapdump is made.
  • name - the name of the heapdump file
  • port - optionally the alternative DevTools protocol port. Defauls to 9229.

Keywords

FAQs

Last updated on 29 Sep 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc