Skip to content

Instantly share code, notes, and snippets.

@ecasilla
Created August 25, 2015 16:45
Show Gist options
  • Save ecasilla/d46dc1227cd2feb754eb to your computer and use it in GitHub Desktop.
Save ecasilla/d46dc1227cd2feb754eb to your computer and use it in GitHub Desktop.
Node js prod tools
var heapdump = require('heapdump');
//Grab a heapdump if the memory increase goes over 250mb
var nextMBThreshold = 0;
setInterval(function () {
var memoryMB = process.memoryUsage().rss / 1048576;
if (memoryMB > nextMBThreshold) {
heapdump.writeSnapshot();
nextMBThreshold += 250;
}
}, 6000 * 2);
//log the event loop blocked time
module.exports = function(fn) {
var start = process.hrtime();
var interval = 100;
setInterval(function(){
var delta = process.hrtime(start);
var nanosec = delta[0] * 1e9 + delta[1];
var ms = nanosec / 1e6;
var n = ms - interval;
if (n > 10) fn(Math.round(n));
start = process.hrtime();
}, interval).unref();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment