Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate and Burst configurations are not clear #92

Open
Nomango opened this issue Nov 29, 2023 · 1 comment
Open

Rate and Burst configurations are not clear #92

Nomango opened this issue Nov 29, 2023 · 1 comment

Comments

@Nomango
Copy link

Nomango commented Nov 29, 2023

Hi, there. Thank you for providing such a simple and useful library.

There are some configuration options confuse me. What do 'Rate' and 'Burst' mean? How can I modify them to achieve the effect of 'maximum 2 times per 10 minutes'?

Hope to add some explanatory comments.

@Nomango Nomango changed the title Rate and Brust configuration items are not clear Rate and Brust configurations are not clear Nov 29, 2023
@Nomango Nomango changed the title Rate and Brust configurations are not clear Rate and Burst configurations are not clear Nov 29, 2023
@tikhomirovv
Copy link

tikhomirovv commented Jun 19, 2024

@Nomango

It seems the "Leaky Bucket" algorithm is being used. Burst is the bucket size, Rate is the bucket's throughput (leak rate = Rate/Period).

The "Leaky Bucket" algorithm represents a model where incoming requests are added to a bucket from which they leak out at a constant rate, ensuring a steady and predictable flow of request processing. The bucket size determines the maximum number of requests that can be temporarily accumulated, allowing the system to handle short-term load spikes. This algorithm is used to prevent system overload and ensure even load distribution by discarding requests if the bucket is full.

To answer your question: if you don't need to account for load spikes, you can do it like this:

limit := redis_rate.Limit{
    Rate:   2,
    Burst:  1,
    Period: time.Minute * 10,
}

Thus, no accumulation of requests will occur, the first request will be allowed immediately, and the next one approximately 5 minutes later (10 minutes / 2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants