All Projects → jessicaxiejw → adaptive_throttler

jessicaxiejw / adaptive_throttler

Licence: MIT license
manages multiple throttlers with ability to ramp up and down

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to adaptive throttler

rush
rush.readthedocs.io/en/latest/
Stars: ✭ 42 (+35.48%)
Mutual labels:  rate-limiting, throttle, rate-limiter, throttler, ratelimit, throttle-requests
gentle-force
Brute-force, error and request rate limiting
Stars: ✭ 45 (+45.16%)
Mutual labels:  rate-limiting, rate-limit, rate-limiter
phalcon-throttler
Phalcon Throttler is a Rate Limiter for the PHP Phalcon Framework.
Stars: ✭ 19 (-38.71%)
Mutual labels:  rate-limiting, rate-limiter, throttler
zlimiter
A toolkit for rate limite,support memory and redis
Stars: ✭ 17 (-45.16%)
Mutual labels:  rate-limiting, rate-limiter, ratelimit
Node Rate Limiter Flexible
Node.js rate limit requests by key with atomic increments in single process or distributed environment.
Stars: ✭ 1,950 (+6190.32%)
Mutual labels:  rate-limiting, throttle, rate
nestjs-ratelimiter
Distributed consistent flexible NestJS rate limiter based on Redis
Stars: ✭ 49 (+58.06%)
Mutual labels:  rate-limiter, ratelimiter
go-ratelimit
Ratelimit your methods using Redis
Stars: ✭ 37 (+19.35%)
Mutual labels:  rate-limits, rate-limiting
RateLimiting.NET
Rate Limiting (debounce, throttle) for C# Portable Class Library
Stars: ✭ 20 (-35.48%)
Mutual labels:  rate-limiting, throttle
flood-protection
Flood protection for realtime applications
Stars: ✭ 19 (-38.71%)
Mutual labels:  rate-limiting, rate
gatekeeper
Rate limiting middleware for Vapor 👮
Stars: ✭ 54 (+74.19%)
Mutual labels:  rate-limits, rate-limiting
asyncio-throttle
Simple, easy-to-use throttler for asyncio.
Stars: ✭ 95 (+206.45%)
Mutual labels:  throttle, throttler
Guzzle Advanced Throttle
A Guzzle middleware that can throttle requests according to (multiple) defined rules. It is also possible to define a caching strategy, e.g. get the response from cache when the rate limit is exceeded or always get a cached value to spare your rate limits. Using wildcards in host names is also supported.
Stars: ✭ 120 (+287.1%)
Mutual labels:  rate-limiting, rate-limiter
portara-website
Portara dashboard controller to change rate limit settings without redeploying your app
Stars: ✭ 42 (+35.48%)
Mutual labels:  rate-limiter, throttler
nestjs-throttler-storage-redis
Redis storage provider for the nestjs-throttler package.
Stars: ✭ 56 (+80.65%)
Mutual labels:  rate-limit, throttler
ratelimit
用户访问频率控制ratelimit,不同于网关级限流(包括go.uber.org/ratelimit漏桶限流以及github.com/juju/ratelimit令牌桶限流),本限流方案为业务级限流,适用于平台运营中,精细化的按单个用户,按IP等限流,为业内rdeis滑动窗口限流方案的纯GO替代方案,并且支持持久化(可选),可定期把历史数据备份到本地磁盘,程序重启也可保留之前的访问记录
Stars: ✭ 57 (+83.87%)
Mutual labels:  ratelimiter, ratelimit
Redisratelimiter
Redis Based API Access Rate Limiter
Stars: ✭ 80 (+158.06%)
Mutual labels:  rate-limiting, rate
Bottleneck
Job scheduler and rate limiter, supports Clustering
Stars: ✭ 1,113 (+3490.32%)
Mutual labels:  rate-limiting, rate-limiter
Redis Ratelimit
A fixed window rate limiter based on Redis
Stars: ✭ 15 (-51.61%)
Mutual labels:  rate-limiting, rate-limiter
Bucket4j
Java rate limiting library based on token/leaky-bucket algorithm.
Stars: ✭ 1,025 (+3206.45%)
Mutual labels:  rate-limiting, rate-limiter
rate-limiter
The Rate Limiter Component provides a Token Bucket implementation to rate limit input and output in your application.
Stars: ✭ 156 (+403.23%)
Mutual labels:  rate, rate-limiter

Adaptive Throttler

A thread-safe throttler library that

  • generic for different use cases(eg/ controls the rate limit per host, limit database reads/writes, and etc)
  • easy to keep track of throttlers for multiple use cases
  • allows you to ramp up and ramp down request rate per throttler

The adaptive throttler is a wrapper around the golang.org/x/time/rate library.

Installation

go get github.com/jessicaxiejw/adaptive_throttler

See godoc for in-depth explanation on the functions and parameters.

Example Usage

manager := throttlers.New(throttlers.Params{
	StartingRate: 10,	// request per second
	Burst: 5,
	LowerBound: 1,
	UpperBound: 20,
	Increment: 2,
	Decrement: 1,
})

keys := []string{"http://example.com/", "http://another-example.com/"}
for _, key := range keys {
	go func() {
		manager.Wait(key)	// waiting until request can be sent

		resp, err := http.Get(key)
		if err != nil {
			manager.Decrement(key)
		} else {
			manager.Increment(key)
		}	
	}
}
<-done

How does the package work?

When the throttlers are first created, it will use StartingRate for every key. The request rate per key is adjusted based on the Increment and Decrement call. For example, say we set

StartingRate: 10
Burst: 1
LowerBound: 1
UpperBound: 20
Increment: 2
Decrement: 1

We would at first allow 10 requests/s for a given key. Two requests were successfully and we called the Increment function twice. The request rate limit was raised to StartingRate + 2 * Increment = 10 + 2 * 2 = 14 request/s.

Right after, one request wasn't successful and you called Decrement. The rate limit was now set to (current request rate) - Decrement = 14 - 1 = 13 requests/s.

We then successfully sent 4 requests, the new request rate should be (current request rate) + Increment * 4 = 13 + 2 * 4 = 21 requests/s. However, because the UpperBound was set to 20 requests/s, the new request rate actually became 20 requests/s.

Say there were 20 unsuccessful requests in series, the new request rate would hit the LowerBound, which was 1 requests/s.

Can the package only be used for handling HTTP requests?

No.

Even though the package was originally created for keeping track of throttle limits for different hosts, it is designed to be generic for any types of throttling. For example, you can use it for rate limiting a database's read and write per user. The key will be the user name.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].