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

Only 1 token returned after duration #17

Closed
VadimBelov opened this issue Jul 28, 2016 · 1 comment
Closed

Only 1 token returned after duration #17

VadimBelov opened this issue Jul 28, 2016 · 1 comment

Comments

@VadimBelov
Copy link
Contributor

In scenario of 30 permitted requests per second I'm using "tollbooth.NewLimiter(30, time.Second)".

Reproduction steps:

  1. Send 50 requests during 1 second
  2. 30 requests are processed, 20 are thrown away because of (configured) throttling - correct
  3. After 1 second send another 30 requests
  4. Only 1 request is processed, 29 are thrown away, instead of being processed
    You may repeat steps 3 and 4 and see the same unwanted result

My solution is to replace:
l.tokenBuckets[key] = ratelimit.NewBucket(l.TTL, l.Max)
with:
l.tokenBuckets[key] = ratelimit.NewBucketWithQuantum(l.TTL, l.Max, l.Max)

NewBucket "fills at the rate of one token every fillInterval", and it's expected that every fillInterval we would get the full bucket again. NewBucketWithQuantum solves this exactly with quantum parameter.

After testing - after the same 1 configured second we get all the quota available again and further requests are not thrown away (in step 4).

VadimBelov added a commit to VadimBelov/tollbooth that referenced this issue Jul 28, 2016
in juju/ratelimit: 
NewBucket "fills at the rate of one token every fillInterval", where in NewBucketWithQuantum "quantum tokens are added every fillInterval."

Since throttling limit is configured per fillInterval, it is expected that upon a new fillInterval the bucket would be full again. Therefore adding Quantum tokens each fillInterval instead of only 1 token each fillInterval is the expected behavior.

Please see Issue#17 for details and steps to reproduce.
didip added a commit that referenced this issue Jul 29, 2016
Issue #17 Fix - Only 1 token returned after duration
@didip
Copy link
Owner

didip commented Jul 29, 2016

Merged, thank you for taking the time to explain it!

@didip didip closed this as completed Jul 29, 2016
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