Skip to content

Instantly share code, notes, and snippets.

@intech
Last active February 23, 2022 18:17
Show Gist options
  • Save intech/e218c5424a7c3bdf37a99b30cc514a61 to your computer and use it in GitHub Desktop.
Save intech/e218c5424a7c3bdf37a99b30cc514a61 to your computer and use it in GitHub Desktop.
Moleculer middleware for detect event loop delay
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