Skip to content

Conversation

@Dav1dde
Copy link
Member

@Dav1dde Dav1dde commented Nov 26, 2025

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 quantity to the RedisQuota instead 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.

@Dav1dde Dav1dde force-pushed the dav1d/opportunistic-quotas branch from b68730f to d15c707 Compare November 28, 2025 10:58
@Dav1dde Dav1dde self-assigned this Nov 28, 2025
@Dav1dde Dav1dde force-pushed the dav1d/opportunistic-quotas branch from d15c707 to a7d1618 Compare November 28, 2025 11:07
@linear
Copy link

linear bot commented Nov 28, 2025

@Dav1dde Dav1dde marked this pull request as ready for review November 28, 2025 11:08
@Dav1dde Dav1dde requested a review from a team as a code owner November 28, 2025 11:08
@Dav1dde Dav1dde force-pushed the dav1d/opportunistic-quotas branch from a7d1618 to 2ccedf5 Compare November 28, 2025 11:09
@Dav1dde Dav1dde force-pushed the dav1d/opportunistic-quotas branch from 2ccedf5 to 9657268 Compare November 28, 2025 11:14
Comment on lines +119 to +121
let max_allowed_spend = usize::try_from(remaining).unwrap_or(usize::MAX)
* PERCENT_PRECISION
/ self.max_over_spend_divisor.get();
Copy link
Contributor

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.

Copy link
Member Author

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.

@Dav1dde Dav1dde force-pushed the dav1d/opportunistic-quotas branch from 12dd624 to 4e16d5f Compare December 1, 2025 10:42
@Dav1dde Dav1dde enabled auto-merge December 1, 2025 10:50
@Dav1dde Dav1dde added this pull request to the merge queue Dec 1, 2025
Merged via the queue into master with commit d171673 Dec 1, 2025
29 checks passed
@Dav1dde Dav1dde deleted the dav1d/opportunistic-quotas branch December 1, 2025 11:10
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

Successfully merging this pull request may close these issues.

3 participants