Last active
February 23, 2022 18:17
-
-
Save intech/e218c5424a7c3bdf37a99b30cc514a61 to your computer and use it in GitHub Desktop.
Moleculer middleware for detect event loop delay
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
const { monitorEventLoopDelay } = require("perf_hooks"); | |
const { humanize } = require("moleculer/src/utils"); | |
module.exports = { | |
name: "perfhook", | |
created() { | |
this.perfhook = monitorEventLoopDelay({ resolution: 20 }); | |
this.perfhook.enable(); | |
}, | |
stopped() { | |
this.perfhook.disable(); | |
console.table({ | |
min: humanize(this.perfhook.min / 1e6), | |
max: humanize(this.perfhook.max / 1e6), | |
mean: humanize(this.perfhook.mean / 1e6), | |
stddev: humanize(this.perfhook.stddev / 1e6), | |
p10: humanize(this.perfhook.percentile(10) / 1e6), | |
p50: humanize(this.perfhook.percentile(50) / 1e6), | |
p99: humanize(this.perfhook.percentile(99) / 1e6) | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment