question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Burst requests using leaky bucket size

See original GitHub issue

Is there any way to implement a leaky bucket algorithm with bucket size in order to allow burst requests?

For example a bucket of size 10 with 2 req/s leak rate allows up to 10 burst requests which fill the bucket and then only 2 req/s while the bucket remains full. If there are no requests, then the bucket empties at the 2 req/s leak rate, allowing another 10 burst requests after 5 seconds.

This is the implementation of the bottleneck library: https://github.com/SGrondin/bottleneck#increase-interval

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
animircommented, Mar 18, 2020

@matomesc Hi. This package doesn’t provide that logic exactly, but there is an option. You can create BurstyRateLimiter and use it with RateLimiterQueue.

const burstyLimiter = new BurstyRateLimiter(
  new RateLimiterMemory({
    points: 2,
    duration: 1,
  }),
  new RateLimiterMemory({
    keyPrefix: 'burst',
    points: 8,
    duration: 5,
  })
);

const limiter = new RateLimiterQueue(limiterFlexible, {
  maxQueueSize: 10,
});

This rate limited FIFO queue allows to queue up not more than 10 requests. It executes 2 requests per second and allows traffic burst up to 10 every 5 seconds.

0reactions
radulescuandrewcommented, Oct 13, 2021

@animir Thanks!

I’m in a hurry to deliver and will not investigate the changes right away but I will come back later to find a solution for the burst also. Best regards!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leaky bucket - Wikipedia
The leaky bucket is an algorithm based on an analogy of how a bucket with a constant leak will overflow if either the...
Read more >
API Rate Limits - Getting started with Recharge
“leak rate” refers to the number of requests that will be processed by the server at the same time, while “bucket size” refers...
Read more >
What is the leaky bucket algorithm? – TechTarget Definition
Learn about the leaky bucket algorithm to reduce network data congestion by temporarily storing requests and organizing them into set-rate output of packets....
Read more >
24 Token Bucket Rate Limiting
It is also possible to use token buckets to describe the router itself; in this setting, the leaky-bucket formulation may be clearer. The...
Read more >
Token Bucket - an overview | ScienceDirect Topics
A token bucket provides a mechanism that allows a desired level of burstiness within a flow by limiting its average rate as well...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found