npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hystrix-too-busy

v0.2.0

Published

Provides a backpressure management hystrix command partially based on too-busy module logic and utilizing hystrix metrics accumulation and circuit breaking

Downloads

387

Readme

hystrix-too-busy

Provides a back-pressure management based on hystrix command and too-busy module logic, utilizing hystrix metrics accumulation and circuit breaking capabilities to avoid false positives generated by plain toobusy-js module.

codecov Build Status NPM Downloads Known Vulnerabilities

What is it?

The importance of maintaining the stability of the system is hard to argue. There are many different techniques on how to achieve this. One of them is based on determining how busy the system based on a latency related to event loop by measuring between expected and actual time when measured timer event happens.

One of the popular modules is toobusy-js, but it does not work as expected and can generate false positives (busy signal) under relatively small load (20% CPU) due to GC memory profile or an application logic. What was missing is a floating window of measurements over specific period of time; which would provide better data to decide if the system is really busy.

Hystrix component provides a fail fast pattern on top of the statistics it collects and that makes it a perfect candidate to add to toobusy-js module to close this gap.

The module defines a hystrix command that executes toobusy check and emits back an error which is used by hystrix to calculate number of errors towards circuit opening.

Once the circuit is open it will stay open till the next sleep window, which will lead to generating a constant signal to the client that the system is busy.

Since it is based on hystrix, it makes all the statistic available to hystrix dashboard and can be integrated into the same node app or plugged into standalone hystrix dashboard.

Install

$ npm install hystrix-too-busy -S

Usage

require('hystrix-too-busy').getState(busy => {
    console.log('I am', busy ? 'busy' : 'free');
})

// or for specific command
require('hystrix-too-busy').getState('fooCommand', busy => {
    console.log(`fooCommand is ${busy ? 'busy' : 'free'}`);
})

Configuration

Since this module is based on both too-busy and hystrixjs you need to understand how different parameters affect the outcome, which in our case is a signal that the system is in stress mode and need to shed some load.

  • toobusy settings:

    • latencyThreshold (default 70) is a number if milliseconds that defines a threshold beyond which toobusy module would generate positive signal that the system is busy.
    • interval (default 500) is a number in milliseconds that defines intervals at which to calculate the system state.
    • smoothingFactor (default 0.33) is smoothing factor used by toobusy module to calculate how system is busy.
  • hystrix settings:

    • circuitBreakerErrorThresholdPercentage (default 50) defines an a threshold for toobusy signal
    • circuitBreakerForceClosed (default false) forces to always keep the circuit closed, which is equal to disabling the module functionality.
    • circuitBreakerForceOpened (default false) forces to always keep the circuit open, which is equal to always busy.
    • circuitBreakerRequestVolumeThreshold (default 20) is a number of requests to the module after which it should start checking if the system is busy
    • circuitBreakerSleepWindowInMilliseconds (default 5000) is an interval after which it should attempt to close the circuit or in other words, check again if the system is busy after being marked as busy.
    • requestVolumeRejectionThreshold (default 0 (off)) defines a number of request to the module after which the requests will be immediately rejected, i.e. marked busy disregarding the actual business of the system. Note by default it is off.
    • statisticalWindowNumberOfBuckets (default 10) is number of buckets used to calculate the stats.
    • statisticalWindowLength (default 10000) defines statistical window in milliseconds.
    • percentileWindowNumberOfBuckets (default 6) defines a number of buckets to calculate percentile stats.
    • percentileWindowLength (default 60000) defines percentile window length in milliseconds.

The default configuration used by the module:

require('hystrix-too-busy').init({
    latencyThreshold: 70,
    interval: 500,
    smoothingFactor: 0.33,
    default: {
        circuitBreakerErrorThresholdPercentage: 50,
        circuitBreakerForceClosed: false,
        circuitBreakerForceOpened: false,
        circuitBreakerRequestVolumeThreshold: 20,
        circuitBreakerSleepWindowInMilliseconds: 5000,
        requestVolumeRejectionThreshold: 0,
        statisticalWindowNumberOfBuckets: 10,
        statisticalWindowLength: 10000,
        percentileWindowNumberOfBuckets: 6,
        percentileWindowLength: 60000
    }
});

Customizing behavior for toobusy module.

Since the module is based on hystrix, we can re-use the command concept to provide different behavior of the circuit breaker. This can allow us to give priorities for some commands over the other, i.e. unimportant commands will get short circuited sooner than the more important ones.

By default all calls to the module will be treated as a single command using default config.

You can configure specific command and only what is different from default config. If some command config is not found, it will use default configuration.

require('hystrix-too-busy').init({
    latencyThreshold: 70,
    interval: 500,
    smoothingFactor: 0.33,
    commands: {
        fooCommand: {
            circuitBreakerErrorThresholdPercentage: 80,
            circuitBreakerRequestVolumeThreshold: 1
        },
        barCommand: {
            circuitBreakerErrorThresholdPercentage: 30
        }
    }
});