Coder Social home page Coder Social logo

rolling-window's Introduction

rolling-window

Actions Status Codecov npm version

Implements "Reset reservoir periodically by chunks" strategy to use hdr-histogram-js for monitoring. Inspired by vladimir-bukhtoyarov/rolling-metrics. No additional dependencies.

See rolling-metrics' documentation for the background.

Install

With hdr-histogram-js@2:

npm install -S hdr-histogram-js @shuhei/rolling-window

With hdr-histogram-js@1:

npm install -S hdr-histogram-js@1 @shuhei/rolling-window@^0.2.1

Usage

const { RollingWindowHistogram } = require("@shuhei/rolling-window");

// This configuration creates 7 internal histograms (6 + 1) and rotates them
// one by one in each 10 seconds. `getSnapshot()` returns a histogram of the
// last 60 to 70 seconds. These additional 0 to 10 seconds make sure that the
// rolling window can provide a fresh histogram without losing any records at
// any given time.
const rollingWindowHistogram = new RollingWindowHistogram({
  timeWindow: 1000 * 60,
  numChunks: 6,
});

// Record a value
rollingWindowHistogram.recordValue(value);

// Get a snapshot
const snapshot = rollingWindowHistogram.getSnapshot();
const p99 = snapshot.getValueAtPercentile(99);

API

new RollingWindowHistogram([options])

  • options
    • timeWindow: number The length of a time window in milliseconds. Default: 60000
    • numChunks: number The number of chunks in the time window. Default: 6
    • buildHistogram: () => Histogram A factory function to create a histogram. This will be called multiple times to prepare necessary histograms in the rolling window. Use this to provide custom options to histograms. Default: build from hdr-histogram-js

Creates a rolling window histogram with numChunks + 1 histograms in it and starts rotating chunks with an interval of timeWindow / numChunks.

rollingWindowHistogram.stop()

Stop the rotation timer. When you stop using a rolling window histogram, make sure to call this method to avoid memory leak.

rollingWindowHistogram.recordValue(value)

  • value: number A numerical value to record. It must not be negative.

rollingWindowHistogram.getSnapshot([snapshot])

  • snapshot: Histogram A histogram to accumulate histograms. It is reset before accumulating histograms. If this is not provided, a Histogram is created and kept for reuse.
  • Returns: Histogram

rolling-window's People

Contributors

shuhei avatar dependabot[bot] avatar addityasingh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.