Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[RateLimiter] Fix wait duration for fixed window policy#42168
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedJul 18, 2021
Hey! I think@kbond has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
Nyholm commentedJul 18, 2021
Thank you. Isn't the correct behaviour to not accept that you are trying to overconsume? |
jlekowski commentedJul 19, 2021
@Nyholm, thanks for looking at this PR. I think you can always call Here's a code I used to compare different policies: foreach (['fixed_window','sliding_window','token_bucket']as$policy) {echo"\nPOLICY:$policy\n";$factory =newRateLimiterFactory(['id' =>'db_write','policy' =>$policy,'limit' =>10,'interval' =>'2 seconds','rate' => ['amount' =>10,'interval' =>'2 seconds'], ],newInMemoryStorage());$limiter =$factory->create();$limit =$limiter->consume(8);$limit =$limiter->consume(4);echo"REMAINING TOKENS:" .$limit->getRemainingTokens() .PHP_EOL;echo"IS ACCEPTED:" . (int)$limit->isAccepted() .PHP_EOL;$start =microtime(true);$limit->wait();echo'WAITED:' .1000 * (microtime(true) -$start) .PHP_EOL;$limit =$limiter->consume(4);echo"REMAINING TOKENS:" .$limit->getRemainingTokens() .PHP_EOL;echo"IS ACCEPTED:" . (int)$limit->isAccepted() .PHP_EOL;} BTW, there might be another issue with |
jlekowski commentedAug 2, 2021
Nyholm left a comment
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.
I finally got my head around this PR.
What do you think of changing the solution slightly? Will it still work?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
jlekowski commentedOct 20, 2021
@Nyholm, thanks for having a closer look into this. Fixing the number of tokens to calculate time for works too. I made the changes according to your suggestions. If that looks fine, I will:
The reason behind removing |
Nyholm left a comment
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.
Im happy with this.
Please squash the commits and rebase on 5.3. Make sure that none of the test failures are related to this PR. Then I would be happy if@wouterj saw this PR too.
About removing the method.
I didn't see the class was internal, if so, you are correct. Removing a method from an internal class is not a BC break.
jlekowski commentedOct 23, 2021
Thank you@Nyholm. I squashed and rebased my changes.
@wouterj, please have a look how you feel about this change. My original commit was herejlekowski@44807a6 with |
fabpot commentedOct 30, 2021
Thank you@jlekowski. |
This PR was merged into the 5.3 branch.Discussion----------[RateLimiter] Increase delta in limiter tests| Q | A| ------------- | ---| Branch? | 5.3 <!-- see below -->| Bug fix? | yes| New feature? | no <!-- please update src/**/CHANGELOG.md files -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| License | MITTests from [PR](#42168) might randomly fail [1](https://ci.appveyor.com/project/fabpot/symfony/builds/41346868#L597) [2](https://ci.appveyor.com/project/fabpot/symfony/builds/41346183#L650)I increased delta like in [this test](https://github.com/symfony/symfony/blob/5.3/src/Symfony/Component/RateLimiter/Tests/Policy/TokenBucketLimiterTest.php#L90).`@fabpot` `@Nyholm` please reviewCommits-------3e2ca33 [RateLimiter] Increase delta in limiter tests
Uh oh!
There was an error while loading.Please reload this page.
When using
fixed_windowpolicy and calling->wait()after overconsuming, there might be nosleep()called. Reproducer below: