Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[RateLimiter] Add SlidingWindowLimiter::reserve()#51676

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.4fromJeroeny:ratelimit
Oct 1, 2023

Conversation

@Jeroeny
Copy link
Contributor

@JeroenyJeroeny commentedSep 18, 2023
edited by fabpot
Loading

QA
Branch?6.4
Bug fix?yes
New feature?yes
Deprecations?yes
TicketsFix#40289,Fixes#46875
LicenseMIT

This implementsLimiterInterface->reserve() forSlidingWindowLimiter. I'm not sure if the lack of implementation was due to time/scope or if it's actually not possible and my approach is incorrect. But I like to give it a try anyway. Perhaps@wouterj you could elaborate on that?

The calculation does the following:

  1. Calculate tokens to be released within this window. E.g. if 4 were used in the last window, at 50% into the current, 2 are still to be released.
  2. Calculate the time-per-token within the remainder of the window. If the requested tokens will be available before the end of the current window, return the time-per-token * needed-tokens.
  3. Otherwise return time-per-token of the regular interval * needed-tokens(-after the current window).

This wasn't abugfix, so back to feature PR. I couldn't reopen#47557, So had to create this new PR.

@fabpot
Copy link
Member

Thank you@Jeroeny.

@fabpotfabpot merged commitf315b4e intosymfony:6.4Oct 1, 2023
This was referencedOct 21, 2023
nicolas-grekas added a commit that referenced this pull requestDec 29, 2023
…licies (wouterj)This PR was merged into the 6.3 branch.Discussion----------[RateLimit] Test and fix peeking behavior on rate limit policies| Q             | A| ------------- | ---| Branch?       | 6.3| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Issues        | Ref#52835| License       | MITAlthough heavily discouraged for user-land code, we've implemented peeking behavior for rate limiting in 6.2 with#46110. However, I found that our rate limit policies show very inconsistent behavior on this.As we didn't have great test covering peeking return values, we broke BC with#51676 in 6.4. I propose this PR to verify the behavior of the policies and also make it inconsistent. I target 6.3 because we rely on this in the login throttling since 6.2 and this shows buggy error messages ("try again in 0 minute") when not using the default policy for login throttling.> [!NOTE]> When merging this PR, there will be heavy merge conflicts in the SlidingWindowLimiter. You can ignore the changes in this PR for this policy in 6.4. I'll rebase and update#52835 to fix the sliding window limiter in 6.4+Commits-------e4a8c33 [RateLimit] Test and fix peeking behavior on rate limit policies
nicolas-grekas added a commit that referenced this pull requestDec 30, 2023
…when consuming 0 or last tokens (wouterj, ERuban)This PR was merged into the 6.4 branch.Discussion----------[RateLimiter] Fix RateLimit->getRetryAfter() return value when consuming 0 or last tokens| Q             | A| ------------- | ---| Branch?       | 6.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Issues        | -| License       | MITReplaces#52835 Original description:> Have got some BC after updating the project to Symfony 6.4 (after that PR#51676).>> Sometimes I need to get `RateLimit` object without consuming just before consuming a try, in example:> ```php> $rateLimit = $limiter->consume(0);> if ($rateLimit->getRemainingTokens() === 0) {>    throw new SomeException($rateLimit->getRetryAfter());> }> ...> $limiter->consume(1)> ...> ```> and found that in that case `$rateLimit->getRetryAfter()` always returns `now`.>> So this PR fixes it.Commits-------677b8b7 [RateLimit] Allow to get RateLimit without consuming again169e383 Reintroduce peek consume test for sliding window policy
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasAwaiting requested review from nicolas-grekas

Assignees

No one assigned

Projects

None yet

Milestone

6.4

Development

Successfully merging this pull request may close these issues.

[Bug][RateLimiter]retryAfter returns bad value [RateLimiter] retry-after of SlidingWindowLimiter is incorrect

4 participants

@Jeroeny@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp