Giter Club home page Giter Club logo

ratelimiter's Introduction

Description Build Status

ratelimiter is a simple golang implementation of a thread safe, basic rate limiter.

Usage

Creating a Rate Limiter

To create a rate limiter, simply:

limiter := NewRateLimiter()
limiter.SetRate(5000.0) // 5000 Permit per second

Using The Rate Limiter

There are two ways to aquire permits:

  • Blocking
  • Blocking with Timeout

For the basic blocking:

limiter.Aquire(1) // aquires 1 permit. Will block the thread until it is allowed to proceed

For the timeout blocking:

limiter.TryAquire(2, 0)    // aquires 2 permit with noblocking
limiter.TryAquire(2, 3000) // aquires 2 permit, and max timeout is 3000us

If TryAquire can aquire it's permits within the specified time (from now), it will block as long as necessary by the rate limiter, and then return true when it has aquired the permits. If it cannot aquire those permits within the specified time, then it will return IMMEDIATELY, with a value of false.

ratelimiter's People

Contributors

nncm avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

awakl

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.