Last active
August 8, 2017 10:04
-
-
Save zz85/a0b365d72d664a95d0bcd20729f88192 to your computer and use it in GitHub Desktop.
Node Event Loop Lag
This file contains 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
// Also see https://github.com/tj/node-blocked/blob/master/index.js and https://stackoverflow.com/questions/28563354/how-to-detect-and-measure-event-loop-blocking-in-node-js | |
const blocked = require('blocked'); | |
blocked(function(ms) { | |
console.log("Blocked", ms); | |
}, { threshold: 10 }); | |
var blockDelta = 1; | |
var interval = 500; | |
var interval = setInterval(function() { | |
const last = process.hrtime(); | |
const last2 = Date.now(); | |
let x= 0; | |
for (let i =0; i < 100000000; i++) { x++; } | |
const calc_diff = (x) => { | |
var diff = process.hrtime(last); // with process.hrtime() | |
var delta = (diff[0] * 1e9 + diff[1]) * 1e-6; | |
console.log("node.eventloop_blocked", Math.round(delta), Date.now() - last2, x); | |
if (delta > blockDelta) { | |
} | |
} | |
setImmediate(calc_diff, 'immediate'); | |
process.nextTick(calc_diff, 'nexttick'); | |
}, interval); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment