Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reugn/equalizer
A set of performant rate limiters for Go
https://github.com/reugn/equalizer
api quota quotas rate rate-limit rate-limiter rate-limiting ratelimit ratelimiter sliding-window throttle throttler throttling tokenbucket
Last synced: 24 days ago
JSON representation
A set of performant rate limiters for Go
- Host: GitHub
- URL: https://github.com/reugn/equalizer
- Owner: reugn
- License: mit
- Created: 2019-06-14T09:25:13.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-14T08:46:32.000Z (2 months ago)
- Last Synced: 2024-04-18T11:23:21.307Z (about 1 month ago)
- Topics: api, quota, quotas, rate, rate-limit, rate-limiter, rate-limiting, ratelimit, ratelimiter, sliding-window, throttle, throttler, throttling, tokenbucket
- Language: Go
- Homepage: https://pkg.go.dev/github.com/reugn/equalizer
- Size: 37.1 KB
- Stars: 77
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
- awesome-go-extra - equalizer - 06-14T09:25:13Z|2021-02-16T13:50:24Z| (Utilities / Fail injection)
- awesome-go-cn - equalizer
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
- awesome-go-projects - equalizer - Quota manager and rate limiter collection for Go. (Utilities / HTTP Clients)
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / HTTP Clients)
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
- go-awesome-cn-star - equalizer
- awesome-go-stars - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
- awesome-go-cn - equalizer
- awesome-go-with-stars - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / HTTP Clients)
- repo-1316-awesome-go-cn - equalizer
- repo-1211-awesome-go-cn - equalizer
- awesome-go-zh - equalizer
- awesome-Char - equalizer - Quota manager and rate limiter collection for Go. (Utilities / HTTP Clients)
- Go-awesome - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
- awesome-go-cn - equalizer
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / HTTP Clients)
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
- awesome-go - equalizer - Quota manager and rate limiter collection for Go. (Utilities / Utility/Miscellaneous)
README
equalizer
A rate limiters package for Go.
Pick one of the rate limiters to throttle requests and control quota.
* [Equalizer](#equalizer)
* [Slider](#slider)
* [TokenBucket](#tokenbucket)## Equalizer
`Equalizer` is a rate limiter that manages quota based on previous requests' statuses and slows down or accelerates accordingly.### Usage
```go
offset := equalizer.NewRandomOffset(96)// an Equalizer with the bitmap size of 96 with 16 reserved
// positive bits and the random offset manager
eq := equalizer.NewEqualizer(96, 16, offset)// non-blocking quota request
haveQuota := eq.Ask()// update with ten previous successful requests
eq.Notify(true, 10)
```### Benchmarks
```sh
BenchmarkEqualizerShortAskStep-16 30607452 37.5 ns/op 0 B/op 0 allocs/op
BenchmarkEqualizerShortAskRandom-16 31896340 34.5 ns/op 0 B/op 0 allocs/op
BenchmarkEqualizerShortNotify-16 12715494 81.9 ns/op 0 B/op 0 allocs/op
BenchmarkEqualizerLongAskStep-16 34627239 35.4 ns/op 0 B/op 0 allocs/op
BenchmarkEqualizerLongAskRandom-16 32399748 34.0 ns/op 0 B/op 0 allocs/op
BenchmarkEqualizerLongNotify-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
```go
// a Slider with one second window size, 100 millis sliding interval
// and the capacity of 32
slider := equalizer.NewSlider(time.Second, time.Millisecond*100, 32)// non-blocking quota request
haveQuota := slider.Ask()// blocking call
slider.Take()
```### Benchmarks
```sh
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
```go
// a TokenBucket with the capacity of 32 and 100 millis refill interval
tokenBucket := equalizer.NewTokenBucket(32, time.Millisecond*100)// non-blocking quota request
haveQuota := tokenBucket.Ask()// blocking call
tokenBucket.Take()
```### Benchmarks
```sh
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.