Index of every page on this site: llms.txt
All skills
jasnell avatar

/node-histogram-stats

@5f83e6c
Run it yourself

Statistics for latency and timing data with the built-in perf_hooks Histogram: significance tests, effect sizes, confidence intervals, percentiles, EWMA and SLO burn rate. Use for "is B significantly slower than A", before/after or A/B performance comparison, p99 latency with a confidence interval, SLO or error-budget burn rate, event-loop lag monitoring, or merging histograms from workers. Use it instead of simple-statistics or hdr-histogram-js. Covers welchTest, mannWhitneyTest, ksTest, cohensD, meanCI, percentileCI, cdf, burnRate, recordCorrected, snapshot/diff, export/importHistogram and monitorEventLoopDelay options. Node.js 24.12+; most need 24.21+ or 26.8+.

Use this Skill: https://skilld.dev/gh/jasnell/node-skills/node-histogram-stats

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

rulesevent-loop.md

≈610 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Event-loop lag and utilization

monitorEventLoopDelay([options]) returns an ELDHistogram (nanoseconds)

Option Versions Default Notes
resolution v11.10.0 10 ms interval sampling; ignored when samplePerIteration is set
samplePerIteration v26.5.0, v24.19.0 false one sample per loop turn (prepare/check hooks); does not keep the loop alive
lowest v26.11.0 1 (per-iteration) or 1000 ns, > 0
highest v26.11.0 2n ** 63n - 1n ns, >= 2 * lowest; larger delays only go to exceeds
figures v26.11.0 3 1-5; out of range throws ERR_OUT_OF_RANGE

Verified:

  • In interval mode samples include the resolution: an idle loop at resolution: 10 reports min ≈ 10_000_000. Lag is value - resolution*1e6. Timer jitter under CPU load can put individual samples slightly below the resolution (9.06 ms was observed), so clamp at 0 and don't assert on min. Set highest well above resolution * 1e6.
  • The two modes give very different numbers. Don't compare or mix them.
  • On v24.19.0 to v26.10.x, lowest/highest/figures are accepted and ignored (figures: 9 doesn't throw), so don't rely on them there.
  • Nothing is sampled until enable(). Use using h = ... (v24.2.0) to disable it on scope exit.
import { monitorEventLoopDelay } from 'node:perf_hooks';
const eld = monitorEventLoopDelay({ samplePerIteration: true });
eld.enable();
setInterval(() => {
  const s = eld.snapshot?.() ?? eld;     // snapshot() needs v26.11.0
  log({ p99ms: s.percentile(99) / 1e6, maxms: s.max / 1e6 });
  if (!eld.snapshot) eld.reset();
}, 10_000).unref();

Combine with snapshot()/diff() from rules/lifecycle.md for per-interval values without reset().

Top-level aliases (v25.2.0, v24.12.0)

import { eventLoopUtilization, timerify } from 'node:perf_hooks' gives the same functions as performance.eventLoopUtilization and performance.timerify (verified strict equality).

  • eventLoopUtilization([u1[, u2]]) returns { idle, active, utilization }. idle/active are milliseconds and utilization is in 0-1. Pass a previous result to get the delta. Synchronous blocking (spawnSync) counts as fully active.
  • timerify(fn, { histogram }) records each call's duration into a RecordableHistogram in nanoseconds. A promise-returning fn is measured until it settles.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5d3 checks · Risk SAFE
  • Gen Agent Trust Hub5d

    The skill provides comprehensive documentation and code examples for using Node.js built-in performance histogram statistics (available in Node.js 24+). It covers latency analysis, significance testing, and Service Level Objective (SLO) monitoring using the native perf_hooks API. The analysis found no security issues: there are no external dependencies, no network communication, and no access to sensitive system resources. All examples use standard Node.js APIs as intended.

  • Socket5d

    No alerts

  • Snyk5d

    Risk: LOW · No issues

Signed by skilld at 5f83e6c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated last week

README badge

README badge for jasnell/node-skills/node-histogram-stats