Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Drain Over Limit behavior #209

Merged
merged 15 commits into from
Feb 9, 2024
Merged

Conversation

Baliedge
Copy link
Contributor

@Baliedge Baliedge commented Jan 4, 2024

  • Add new behavior DRAIN_OVER_LIMIT.
  • Tech debt

Users may add behavior Behavior_DRAIN_OVER_LIMIT to the rate check request. A
GetRateLimits call drains the remaining counter on first over limit event. Then,
successive GetRateLimits calls will return zero remaining counter and not any
residual value. This behavior works best with token bucket algorithm
because the Remaining counter will stay zero after an over limit until reset
time, whereas leaky bucket algorithm will immediately update Remaining to a
non-zero value.

This facilitates scenarios that require an over limit event to stay over limit
until the rate limit resets. This approach is necessary if a process must make
two rate checks, before and after a process, and the Hit amount is not known
until after the process.

  • Before process: Call GetRateLimits with Hits=0 to check the value of
    Remaining counter. If Remaining is zero, it's known
    that the rate limit is depleted and the process can be aborted.
  • After process: Call GetRateLimits with a user specified Hits value. If
    the call returns over limit, the process cannot be aborted because it had
    already completed. Using DRAIN_OVER_LIMIT behavior, the Remaining count
    will be drained to zero.

Once an over limit occurs in the "After" step, successive processes will detect
the over limit state in the "Before" step.

@Baliedge Baliedge force-pushed the Baliedge/PIP-2786-drain-remaining branch from ead0fd8 to 8db85a4 Compare January 4, 2024 19:29
@Baliedge Baliedge changed the title Drain Overlimit behavior Drain Over Limit behavior Jan 4, 2024
@Baliedge Baliedge requested a review from a team January 4, 2024 22:10
@Baliedge Baliedge merged commit 7ffdfef into master Feb 9, 2024
4 checks passed
@Baliedge Baliedge deleted the Baliedge/PIP-2786-drain-remaining branch February 9, 2024 18:44
@Baliedge Baliedge mentioned this pull request Feb 9, 2024
@Baliedge Baliedge mentioned this pull request Feb 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants