-
Notifications
You must be signed in to change notification settings - Fork 337
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
Cache TTL is less than :period #480
Comments
I believe the reason for this is that the key used for caching specifies a timeframe that doesn't necessarily starts when you make your first request. Let's consider your example, where you specify a period of 60 seconds. If you make a request at the timestamp Indeed, the downside of this approach is that the limit you specify will be applied only to these "blocks" of time. It's guaranteed that you can make I think the only solution to strictly apply the limit to all possible timeframes would be to record the timestamp of every request made by a user, but that would require much more storage and also some extra processing. I hope this helps! |
Indeed. Thanks @peter-roland-toth for responding! |
For what is worth... There's been an attempt in the past to make the throttle algorithm more sophisticated in #206, in case anyone wants to take another shot at trying. |
Looking at how the cache keys are set when using throttling, I've figured out that, depending on the time in which RackAttack is called, the TTL for the cache keys is set to a value lower than the
:period
.Testing the code
is showing the following behaviour:
What I see is that:
Given the original period of 60 seconds, I was able to successfully requests the resource twice as expected.
While the behaviour can be acceptable when using a single rule, it gets a bit more concerning when using exponential backoff, because it becomes harder to keep control on the amount of requests that should be blocked.
For example, for a limit of 20 requests in 7200 seconds, I get a TTL of 1710 seconds
What's the reason behind calculating the TTL subtracting the current time?
The text was updated successfully, but these errors were encountered: