Created
August 25, 2015 16:45
-
-
Save ecasilla/d46dc1227cd2feb754eb to your computer and use it in GitHub Desktop.
Node js prod tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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