-
Notifications
You must be signed in to change notification settings - Fork 103
feat(quotas): Add an opportunistic cache for Quotas #5416
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
Conversation
b68730f to
d15c707
Compare
d15c707 to
a7d1618
Compare
a7d1618 to
2ccedf5
Compare
2ccedf5 to
9657268
Compare
| let max_allowed_spend = usize::try_from(remaining).unwrap_or(usize::MAX) | ||
| * PERCENT_PRECISION | ||
| / self.max_over_spend_divisor.get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this is essentially remaining * max_over_spend_percentage (the PERCENT_PRECISIONs cancel out). It might be worth factoring this differently because currently it's quite difficult to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some docs on PERCENT_PRECISION to problem is the accuracy loss going from 0..1 percentage to an integer division.
1 / 0.7 = 1.42, which would truncate to 1 when converting to usize. To keep some precision it's multiplied by 10 first.
12dd624 to
4e16d5f
Compare
Implements an opportunistic quota cache. Closes: INGEST-638.
The cache is aware of the currently used quota and opportunistically accepts N% of the remaining quota before synchronizing with the central cache (Redis).
By default the cache is not enabled. I plan to test the cache and collect some telemetry in a test environment.
In a follow up I want to re-evaluate how the percentage is calculated and potentially do it normalized as a percentage of 1 second or 10 seconds, to not run into issues with very large quota windows.
I had to change how the quantity is handled, I added the
quantityto theRedisQuotainstead of carrying int separately, this makes it possible for the cache easily to work per quota. All the underlying machinery already worked per quota, making this a very simple refactor.