perf_hooks.monitorEventLoopDelay
History
lowest, highest, and figures options.samplePerIteration option.perf_hooks.monitorEventLoopDelay(options?): ELDHistogram
Objectbooleantrue, samples are taken once per
event loop iteration. Default: false.numbersamplePerIteration is true. Default: 10.0. Default: 1 when
samplePerIteration is true, otherwise 1000.lowest. Default: 2n ** 63n - 1n.number1 and 5. Default: 3.ELDHistogramThis property is an extension by Node.js. It is not available in Web browsers.
Creates a histogram object that samples and reports the event loop delay over time. The delays will be reported in nanoseconds.
By default, the histogram is updated by a timer using the configured
resolution. When samplePerIteration is true, samples are taken once per
event loop iteration using uv_prepare_t and uv_check_t hooks. In that mode,
the histogram does not keep the loop alive or force additional iterations when
the application is idle.
The two sampling modes produce significantly different results and should not
be compared directly.
The lowest, highest, and figures options configure the histogram as they
do for perf_hooks.createHistogram(). lowest must be greater than 0
because an event loop delay of zero is not possible: the event loop has a
minimal overhead, and the measurement itself depends on the event loop turning.
Delays greater than highest are not recorded, and are counted by
histogram.exceeds instead. With interval-based sampling, every sample
includes the resolution, so highest should be well above
resolution * 1e6. The histogram's memory use depends on these options, not
on the number of samples.
import { monitorEventLoopDelay } from 'node:perf_hooks'; const h = monitorEventLoopDelay({ resolution: 20 }); h.enable(); // Do something. h.disable(); console.log(h.min); console.log(h.max); console.log(h.mean); console.log(h.stddev); console.log(h.percentiles); console.log(h.percentile(50)); console.log(h.percentile(99));
const { monitorEventLoopDelay } = require('node:perf_hooks'); const h = monitorEventLoopDelay({ resolution: 20 }); h.enable(); // Do something. h.disable(); console.log(h.min); console.log(h.max); console.log(h.mean); console.log(h.stddev); console.log(h.percentiles); console.log(h.percentile(50)); console.log(h.percentile(99));