perf_hooks.createSlidingWindowHistogram
History
perf_hooks.createSlidingWindowHistogram(options): SlidingWindowHistogram
Objectnumber1 and 1024.number1 and 18_446_744_073_709. Exactly one of
chunkDuration and recordsPerChunk must be specified.numberrecord() assigned to
each chunk. Must be an integer between 1 and Number.MAX_SAFE_INTEGER.
Exactly one of chunkDuration and recordsPerChunk must be specified.0. Default: 1.lowest.
Default: Number.MAX_SAFE_INTEGER.number1 and 5. Default: 3.SlidingWindowHistogramCreates a SlidingWindowHistogram that retains the latest chunks histogram
chunks. Rotation is lazy and does not create a timer. Time-based rotation is
evaluated when record() or snapshot() is called. Count-based rotation is
evaluated when record() is called.
One histogram chunk is allocated during construction. Additional chunks are
allocated lazily. The maximum native memory used by the window scales with
chunks and with the lowest, highest, and figures histogram options.
The window boundary has chunk-level precision. With N chunks of duration
D, a recorded value is retained for between (N - 1) * D and N * D
milliseconds. Once a count-based window is populated, it retains between
(N - 1) * C + 1 and N * C recording attempts, where C is
recordsPerChunk. Recording attempts which exceed highest are included when
determining count-based rotation.
const { createSlidingWindowHistogram } = require('node:perf_hooks'); const window = createSlidingWindowHistogram({ chunks: 6, chunkDuration: 10_000, }); window.record(20_000_000); // Materialize the current window as an independent Histogram. const snapshot = window.snapshot(); console.log(snapshot.percentile(99));