8
Shubhra Kar @shubhrakar April, 2014 Memory Leak Analysis

Node.js memory analysis

Embed Size (px)

DESCRIPTION

Memory Leak Analysis in Node.js

Citation preview

Page 1: Node.js memory analysis

Shubhra Kar@shubhrakar

April, 2014

Memory Leak Analysis

Page 2: Node.js memory analysis

heapdump for V8 snapshots by @bnoordhuis

npm install heapdumpAdd to app : var heapdump = require(‘heapdump’)

Method 1 : writeSnapshot

Method 2 : SIGUSR2 (Unix only)

Make sure your directory is writable

var heapdump = require('heapdump')...heapdump.writeSnapshot()

kill –USR2 <pid>

process.chdir('/path/to/writeable/dir’)

Page 3: Node.js memory analysis

heapdump for V8 snapshots by @bnoordhuis

Programmatic heap snapshots (timer based)

Programmatic heap snapshots (threshold based)

var heapdump = require('heapdump') ... setInterval(function () {   heapdump.writeSnapshot() }, 6000 * 30) <strong>(1)</strong>

var heapdump = require('heapdump')var nextMBThreshold = 0 <strong>(1)</strong>

setInterval(function () {  var memMB = process.memoryUsage().rss / 1048576 <strong>(2)</strong>  if (memMB &gt; nextMBThreshold) { <strong>(3)</strong>    heapdump.writeSnapshot()    nextMBThreshold += 100  }}, 6000 * 2) <strong>(4)</strong>

Page 4: Node.js memory analysis

4

Heapdump analysis in Chrome Dev Tools

Page 5: Node.js memory analysis

5

Heapdump analysis in Chrome Dev Tools

Page 6: Node.js memory analysis

StrongOps - Memory Profiling and Leak Detection

Page 7: Node.js memory analysis

A nasty one ! (memory leak)