You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In scenario of 30 permitted requests per second I'm using "tollbooth.NewLimiter(30, time.Second)".
Reproduction steps:
Send 50 requests during 1 second
30 requests are processed, 20 are thrown away because of (configured) throttling - correct
After 1 second send another 30 requests
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).
The text was updated successfully, but these errors were encountered:
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.
In scenario of 30 permitted requests per second I'm using "tollbooth.NewLimiter(30, time.Second)".
Reproduction steps:
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).
The text was updated successfully, but these errors were encountered: