Node.js memory analysis

3,249 views

Published on

Memory Leak Analysis in Node.js

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,249
On SlideShare
0
From Embeds
0
Number of Embeds
92
Actions
Shares
0
Downloads
19
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Node.js memory analysis

  1. 1. Shubhra Kar @shubhrakar April, 2014 Memory Leak Analysis
  2. 2. heapdump for V8 snapshots by @bnoordhuis npm install heapdump Add 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’)
  3. 3. 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>
  4. 4. Heapdump analysis in Chrome Dev Tools 4
  5. 5. Heapdump analysis in Chrome Dev Tools 5
  6. 6. StrongOps - Memory Profiling and Leak Detection
  7. 7. A nasty one ! (memory leak)
  8. 8. Good references Memory Analysis 101 :https://developers.google.com/chrome- developer-tools/docs/memory-analysis-101 Taming the Unicorn: Easing JavaScript Memory profiling in Chrome DevTools :http://addyosmani.com/blog/taming-the-unicorn-easing- javascript-memory-profiling-in-devtools/ StrongLoop Blog : http://strongloop.com/strongblog/how-to-heap- snapshots/ StrongOps : http://strongloop.com/node-js-performance/strongops/ 8

×