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

Allow greater access to the SmoothBursty rate limiter #1974

Closed
wjam opened this issue Feb 13, 2015 · 8 comments
Closed

Allow greater access to the SmoothBursty rate limiter #1974

wjam opened this issue Feb 13, 2015 · 8 comments

Comments

@wjam
Copy link

wjam commented Feb 13, 2015

Create a method, such as create(permitsPerSecond, maxBurst, timeUnit) so that the full functionality of the SmoothBursty class can be utilised.

Use case
Use a RateLimiter when the rate is applied on a wider timescale than just a single second. An example of this would be the GitHub API which has a rate limit of 5,000 per hour.

@PhilippWendler
Copy link

I guess this is a duplicate of #1707.

That being sad, I would also appreciate this being made available. We would like to limit sending out notification emails with something like a low hourly limit, but a burst size of 10-15 minutes.

@AlexAtLeanPath
Copy link

We need bursting as well. Sad to have to reinvent the wheel

lucamilanesio pushed a commit to GerritCodeReview/plugins_quota that referenced this issue Jun 23, 2017
From time to time we observe excessive load caused by misconfigured
build jobs polling for new changes too frequently or by buggy scripts or
other misbehaving clients. Analyzing and following up such problems
manually is time consuming. Rate limiting can be used to automatically
limit the load an individual user can impose on Gerrit to prevent a
negative impact on other users.

As a first step this change implements rate limits for fetch requests
which we found to be the most frequent cause of excessive load caused by
misbehaving clients.

Fetch request rate limits can be configured in configuration file
quota.config stored in the refs/meta/config branch of All-Projects.

For logged in users rate limits are associated to their accountId. For
anonymous users rate limits are associated to their remote host address.
If multiple anonymous users are accessing Gerrit via the same host (e.g.
a proxy) they share a common rate limit.

Guava's RateLimiter implementation class SmoothRateLimiter.SmoothBursty
allows to collect permits during idle times which can be used to send
bursts of requests exceeding the average rate until the stored permits
are consumed. If the rate per second is 0.2 and you wait 20 seconds you
can acquire 4 permits which in average matches the configured rate limit
of 0.2 requests/second.

Unfortunately the standard implementation doesn't allow any bursts if
the configured permit rate is smaller than 1 per second since the
maximum time which can be used to collect stored permits is hard-coded
to 1 second.

Build jobs fetching updates from Gerrit are typically triggered by
events which can arrive in bursts. Hence the standard RateLimiter seems
not to be the right choice for fetch requests we might want to limit to
a rate of less than 1 request per second per user.

The used constructor can't be accessed through a public method yet hence
use reflection to instantiate it. There is a bug [1] open requesting to
expose this parameter in the public guava API.

For standalone Buck build reference Gerrit API 2.13-SNAPSHOT until
2.13.9 has been released since this change depends on the enhanced
UploadValidationListener interface in
Iaafc0f844c07d823b8a7ef6377f2ede1c5805a08

TODOs:
* add tests for parsing of rate limit configuration entries

[1] google/guava#1974

Depends-On: Iaafc0f844c07d823b8a7ef6377f2ede1c5805a08
Change-Id: Ie1ca2e19e9d8a9a525af534b7ee7d6d4164e27e9
@uptimestar
Copy link

Ping on this.

@gopi-gith
Copy link

We recently switched from Guava to https://github.com/bbeck/token-bucket due to this issue. It helped us a lot to implement rate limiting with bursts.

@MrGraversen
Copy link

MrGraversen commented Nov 15, 2018

Also interested in this.

@gmethvin
Copy link

We released a small library for this: https://mvnrepository.com/artifact/com.iterable/guava-bursty-rate-limiter/0.1.0

@nick-someone
Copy link
Member

Agreed with @PhilippWendler that this is a dup.

Duplicate of #1707

@nick-someone
Copy link
Member

Duplicate of #1707

@nick-someone nick-someone marked this as a duplicate of #1707 Jul 24, 2019
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

8 participants