Go package for rate limiter collection

Related tags

rlc
Overview

rlc

A rate limiter collection for Go.

Pick up one of the rate limiters to throttle requests and control quota.

RLC

RLC is a rate limiter that manages quota based on previous requests' statuses and slows down or accelerates accordingly.

Usage

offset := rlc.NewRandomOffset(96)

// an RLC with the bitmap size of 96 with 16 reserved
// positive bits and the random offset manager
eq := rlc.NewRLC(96, 16, offset)

// non-blocking quota request
haveQuota := eq.Ask()

// update with ten previous successful requests
eq.Notify(true, 10)

Benchmarks

BenchmarkRLCShortAskStep-16       30607452                37.5 ns/op             0 B/op          0 allocs/op
BenchmarkRLCShortAskRandom-16     31896340                34.5 ns/op             0 B/op          0 allocs/op
BenchmarkRLCShortNotify-16        12715494                81.9 ns/op             0 B/op          0 allocs/op
BenchmarkRLCLongAskStep-16        34627239                35.4 ns/op             0 B/op          0 allocs/op
BenchmarkRLCLongAskRandom-16      32399748                34.0 ns/op             0 B/op          0 allocs/op
BenchmarkRLCLongNotify-16            59935               20343 ns/op             0 B/op          0 allocs/op

Slider

Slider rate limiter is based on a sliding window with a specified quota capacity. Implements the Limiter interface.

Usage

// a Slider with one second window size, 100 millis sliding interval
// and the capacity of 32
slider := rlc.NewSlider(time.Second, time.Millisecond*100, 32)

// non-blocking quota request
haveQuota := slider.Ask()

// blocking call
slider.Take()

Benchmarks

BenchmarkSliderShortWindow-16           123488035                9.67 ns/op            0 B/op          0 allocs/op
BenchmarkSliderLongerWindow-16          128023276                9.76 ns/op            0 B/op          0 allocs/op

TokenBucket

TokenBucket rate limiter is based on the token bucket algorithm with a refill interval. Implements the Limiter interface.

Usage

// a TokenBucket with the capacity of 32 and 100 millis refill interval
tokenBucket := rlc.NewTokenBucket(32, time.Millisecond*100)

// non-blocking quota request
haveQuota := tokenBucket.Ask()

// blocking call
tokenBucket.Take()

Benchmarks

BenchmarkTokenBucketDenseRefill-16      212631714                5.64 ns/op            0 B/op          0 allocs/op
BenchmarkTokenBucketSparseRefill-16     211491368                5.63 ns/op            0 B/op          0 allocs/op

License

Licensed under the MIT License.

Owner
Alex Xu
Alex Xu
Simple middleware to rate-limit HTTP requests.

Tollbooth This is a generic middleware to rate-limit HTTP requests. NOTE 1: This library is considered finished. NOTE 2: Major version changes are bac

Didip Kerabat 2k Jun 9, 2021
Go package for rate limiter collection

rlc A rate limiter collection for Go. Pick up one of the rate limiters to throttle requests and control quota. RLC Slider TokenBucket RLC RLC is a rat

Alex Xu 15 May 7, 2021
Efficient token-bucket-based rate limiter package.

ratelimit -- import "github.com/juju/ratelimit" The ratelimit package provides an efficient token bucket implementation. See http://en.wikipedia.org/w

Juju 2k Jun 8, 2021
A Golang blocking leaky-bucket rate limit implementation

Go rate limiter This package provides a Golang implementation of the leaky-bucket rate limit algorithm. This implementation refills the bucket based o

Uber Go 2.4k Jun 11, 2021
Simple, thread-safe Go rate-limiter

RateLimit Simple, thread-safe Go rate-limiter. Inspired by Antti Huima's algorithm on http://stackoverflow.com/a/668327 Example package main import (

Black Square Media 66 May 3, 2021
An efficient and feature complete Hystrix like Go implementation of the circuit breaker pattern.

Circuit Circuit is an efficient and feature complete Hystrix like Go implementation of the circuit breaker pattern. Learn more about the problems Hyst

Jack Lindamood 565 Jun 10, 2021
Sentinel Go version (Reliability & Resilience)

Sentinel: The Sentinel of Your Microservices Introduction As distributed systems become increasingly popular, the reliability between services is beco

Alibaba 1.6k Jun 11, 2021
A collection of useful middleware for Go HTTP services & web applications 🛃

gorilla/handlers Package handlers is a collection of handlers (aka "HTTP middleware") for use with Go's net/http package (or any framework supporting

Gorilla Web Toolkit 1.2k Jun 13, 2021
A tiny http middleware for Golang with added handlers for common needs.

rye A simple library to support http services. Currently, rye provides a middleware handler which can be used to chain http handlers together while pr

InVision 759 Jun 2, 2021
Go package for easily rendering JSON, XML, binary data, and HTML templates responses.

Render Render is a package that provides functionality for easily rendering JSON, XML, text, binary data, and HTML templates. This package is based on

Cory Jacobsen 1.5k Jun 13, 2021
Simple, lightweight and faster response (JSON, JSONP, XML, YAML, HTML, File) rendering package for Go

Package renderer Simple, lightweight and faster response (JSON, JSONP, XML, YAML, HTML, File) rendering package for Go Installation Install the packag

Saddam H 221 Jun 3, 2021
Idiomatic HTTP Middleware for Golang

Negroni Notice: This is the library formerly known as github.com/codegangsta/negroni -- Github will automatically redirect requests to this repository

null 7k Jun 11, 2021
Minimalist net/http middleware for golang

interpose Interpose is a minimalist net/http middleware framework for golang. It uses http.Handler as its core unit of functionality, minimizing compl

James Pirruccello 291 Jun 10, 2021
gorilla/csrf provides Cross Site Request Forgery (CSRF) prevention middleware for Go web applications & services 🔒

gorilla/csrf gorilla/csrf is a HTTP middleware library that provides cross-site request forgery (CSRF) protection. It includes: The csrf.Protect middl

Gorilla Web Toolkit 667 Jun 12, 2021