Comments (2)
For anyone wondering what we ended up doing, we went with the latter suggestion and created a custom resolver that implements the ArtisanSdk\RateLimiter\Contracts\Resolver interface. It made a lot of sense to go that route since we also realized that we needed to customize the names of cache keys, and set unlimited rates for internal applications that call the same API.
from ratelimiter.
Per the documentation the throttle:<bursts>,<rate>,<timeout>
defaults to throttle:60,1,1
which means 60 requests in a burst (e.g.: in 1 second) and a leak rate of 1 r/s which means that if you bursted all 60 requested in 1 second you'd only be able to make 1 r/s from then on. If you sat idle for 60 seconds then your quota would reset to 60 more. If you trip the burst quota you'll go into a 1 minute timeout which is to forcibly wait for the bucket to drain.
A value of throttle:60,60,10
would be 60 burst requests in a second with a leak of 60 r/s which means every second you can make another 60 but if you ever exceed 60 r/s then you'll go into a 10 minute timeout.
A value of throttle:10,0.0167,5
would correspond roughly to 10 burst requests within a minute as the 1 / 60
= 0.0167
leaks per second rate will leak 0.0167
request per second and takes 60s to leak 1 whole request. If you exceed therefore 10 requests in a minute then you'll go into a 5 minute timeout. Similarly throttle:60,0.1,5
would leak 1 request every 10 seconds as 1 request / 0.1 requests/second
= 10 seconds
.
Timeout is configured in minutes. Requests are configured as instantaneous burst. The leak rate is configured in seconds but a decimal value will allow some granularity over the request leaking per minute instead of per second. Note that accuracy is limited this way due to rounding errors with floating point math.
I welcome a PR for an improved syntax to configure by the minute. Alternatively consider making a custom resolver which will let you control everything about the leaky bucket configuration including being able to change the leaking unit of measurement to minutes, hours, days, etc if you wanted.
from ratelimiter.
Related Issues (8)
- Logo Design HOT 1
- Cache record expiration time is erroneously passed as a float HOT 1
- User-Resolver: sha1() expects parameter 1 to be string, int given HOT 1
- All routes and users are spammed with response error 429 HOT 1
- Possible to tag a release? HOT 5
- Timeout TTL set incorrectly HOT 2
- Hit TTL potentially set incorrectly... HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ratelimiter.