GithubHelp home page GithubHelp logo

traffic-shaper's Introduction

Licence

Traffic Shaper

Overview

The Traffic Shaper allows for customizable time-windowed (both sliding and tumbling windows) traffic shaping (eg. rate throttling of any invocations in a selectable time-unit). An example use would be say we want to generate an event if our subscription service receives 20000 new user subscription messages in 3 seconds.

Since throttling is in-memory but at the same time, we care for data reliability, there's full state-snapshotting available on-demand or pre-shutdown; similarly state-reconstruction happens at boot-time but is also available on-demand.

Two modes of traffic shaping are supported via Leaky and Token buckets.

Quick Start - Rate Throttler

Assuming you dropped the ratethrottler jar in your classpath:

  1. Create an instance ServiceRateThrottler throttler = new ServiceRateThrottler();
  2. Create an invocation Invocation invocation = new Invocation("dispatchPayment", 50000L, 5L, WindowType.SECONDS);
  3. Register invocation's interest with the throttler throttler.setupInvocationThrottler(invocation);
  4. Tick the event at every invocation and watch outcome boolean limitReached = throttler.throttle(invocation);

API

1. Setup invocation throttler

void setupInvocationThrottler(final Invocation invocation)

2. Tick invocation and signal throttling outcome

boolean throttle(final Invocation invocation)

3. Purge previous recordings for invocation

void purgeInvocationThrottler(final Invocation invocation)

4. Drop throttler

void dropInvocationThrottler(final Invocation invocation)

5. Count active throttlers

int reportActiveThrottlerCount()

6. Check existence of throttler for invocation

boolean existsInvocationThrottler(final Invocation invocation)

7. Purge all runtime throttling state

void purgeAllState()

8. Snaphsot all runtime throttling state to bson

String takeSnapshot()

9. Reconstruct throttling state from a previous snapshot

void reconstructFromSnapshot(String bsonSnapshot)

License

MIT License - Copyright (c) 2012 Gaurav Sharma

traffic-shaper's People

Contributors

gsharma avatar

Stargazers

 avatar

Watchers

 avatar  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.