Git Product home page Git Product logo

Comments (8)

hellboy81 avatar hellboy81 commented on July 29, 2024 1

+ìnfinity

from node-memwatch.

joeytwiddle avatar joeytwiddle commented on July 29, 2024 1

When our leak is detected, the app is using about 1GB of RAM. Each heap snapshot takes about 8 seconds. The diff (which we trigger on the next GC) takes 52 seconds!

Diffing is a synchronous process right? That means our server is blocking all requests while the diff is being processed. That's unacceptable for production. So currently we only report "leak detected" in production, and try to reproduce on a dev machine for heap snapshots and diffing.

What would be really great:

  1. Instead of starting and ending a HeapDiff, save two HeapSnapshots to a file. (Accept the 8 second hit for each.)
  2. Diff the two heaps in a separate process (e.g. a shell command the developer can execute).

Is that possible now? Or is it planned? Thanks!

from node-memwatch.

joeytwiddle avatar joeytwiddle commented on July 29, 2024 1

@jackycute The diffing can still be useful on a development machine, but in staging (and sometimes production) I am now using this approach:

After memwatch reports a possible leak, I use 'heapdump' to take 5 snapshots after each of the next 5 GCs.

const memwatch = require('memwatch-next');
const heapdump = require('heapdump');

const maxHeapDumpsToSave = 5;

let leakDetected = false;
let numHeapDumpsSaved = 0;

memwatch.on('leak', function (info) {
  console.warn(new Date(), "Possible memory leak detected:", info);
  leakDetected = true;
  // We leave it to the 'stats' event to snapshot and diff heaps
  // We don't do it here because it can be a very long time between two 'leak' events,
  // resulting in large and different heaps.
});

memwatch.on('stats', function (d) {
  if (leakDetected && numHeapDumpsSaved < maxHeapDumpsToSave) {
    console.warn(new Date(), "Dumping the heap...");

    const filename = `./heapdump-${process.pid}-${numHeapDumpsSaved}.heapsnapshot`;

    heapdump.writeSnapshot(filename, () => {
      console.warn(new Date(), "Heap dump completed.");
    });

    numHeapDumpsSaved++;
  }
});

When these files appear on disk, I use Chrome devtools to compare them. (The UI for this changed recently, but you can drag files into the devtools pane, or hit Cmd-O / Ctrl-O.)

from node-memwatch.

hellboy81 avatar hellboy81 commented on July 29, 2024
  • Can node-memwatch be used in production environment?
  • Which best practices should be used to detect memory leaks (may be also with v8-profiler)

from node-memwatch.

jacoscaz avatar jacoscaz commented on July 29, 2024

@hellboy81 I've used memwatch(-next) to trigger heapdump with very good results so far. Saved me a ton of debugging.

from node-memwatch.

marcominetti avatar marcominetti commented on July 29, 2024

I'll include heapdump as enhancement to allow automatic dumps on memwatch events (configurable)

from node-memwatch.

jhiver avatar jhiver commented on July 29, 2024

+1

from node-memwatch.

jackycute avatar jackycute commented on July 29, 2024

Agreed with @joeytwiddle
The diffing is blocking and takes long time.

from node-memwatch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.