fix: [PSERV-2110] skip_n_calls take amount accounts for current call #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue where
skip_n_calls
would inaccurately limit received requests.Local Test Results
Tests generated locally using testing tools added here: https://github.com/auth0/platform-core-services-tools/pull/24/files
The graphs below show the number of conformant requests under the following conditions:
Before Fix
Notice that it is limiting to 1.4k RPS instead of 1k RPS
After Fix
The graph below shows the number of conformant requests under the following conditions:
Notice that it is now correctly limiting to 1k RPS
Other Local Test Case Results
skip_n_calls
Root Cause:
When taking tokens after skipping calls to
redis
, we were taking tokens to account for the skipped calls, but not for the current call.This off-by-one error explains why the results were more prominent when `n` is small.
Examples
When
skip_n_calls
is 1 we would do the following:redis
- (bucket = 2)redis
(bucket = 2)n
tokens fromredis
. n = 1. (bucket = 1)n
+ 1 tokens fromredis
; one for the previously skipped call, and one for this call. (bucket = 0)When
skip_n_calls
is 3 we would do the following:redis
- (bucket = 4)redis
(bucket = 4)n
tokens fromredis
. n = 3. (bucket = 1)n
+ 1 tokens fromredis
; one for the previously skipped call, and one for this call. (bucket = 0)References
Slack Discussion
Jira
Testing
Checklist