dylantack / redis-token-bucket Goto Github PK
View Code? Open in Web Editor NEWA distributed token bucket using Redis as the coordinator
A distributed token bucket using Redis as the coordinator
I am trying to use this for distributed rate-limiting queries to an external API. Like, for example, I have a fleet of AWS EC2 Machines behind a load balancer, and a workload is distributed across these machines, and collectively, they can only make X queries per minute to the external API.
So If my rate limit is a maximum 30 queries per minute, would the following configuration be correct ?
const res = (
await redisTokenBucketConsumer(
'myscope',
{
refill_interval_ms : 60 * 1000, // ms per minute
max_bucket_size : 30
}
)
)
If so, the expected rate is not happening (its being throttled much slower), I am wondering in your code, whether the below line is correct:
const expire = Math.ceil(config.refill_interval_ms * config.max_bucket_size / 1000);
Why would the expire figure be the refill_interval_ms
MULTIPLIED by the bucket size ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.