Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: RateLimiterService #13997

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

anatawa12
Copy link
Member

What

#13994 (comment)

とりあえずの対応としてはこれでいいと思ってますが、new Promiseのコールバックが長いことが原因の一端になってると思うので、Limiter.prototype.getをpromise化してそれをasyncで呼ぶ形に近い将来したいと思ったのでちょっと準備してます

を実装しました

Why

What参照

Additional info (optional)

diffとしては大きいですが、小さな作業単位にcommitを分けたので、レビューするときはコミット単位にみてもらうとおそらく見やすいと思います。

#13994を先にマージする必要があるため、マージされるまでDraftにしますが Ready for Review です

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

@github-actions github-actions bot added the packages/backend Server side specific issue/PR label Jun 14, 2024
@anatawa12 anatawa12 mentioned this pull request Jun 14, 2024
5 tasks
Copy link
Contributor

github-actions bot commented Jun 14, 2024

このPRによるapi.jsonの差分

差分はこちら

Get diff files from Workflow Page

Copy link

codecov bot commented Jun 14, 2024

Codecov Report

Attention: Patch coverage is 13.33333% with 52 lines in your changes missing coverage. Please review.

Project coverage is 40.07%. Comparing base (8b4933c) to head (bb92129).

Files Patch % Lines
...kages/backend/src/server/api/RateLimiterService.ts 16.32% 41 Missing ⚠️
packages/backend/src/server/api/ApiCallService.ts 0.00% 9 Missing ⚠️
...ackages/backend/src/server/api/SigninApiService.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #13997      +/-   ##
===========================================
- Coverage    40.16%   40.07%   -0.10%     
===========================================
  Files         1521     1521              
  Lines       188552   188535      -17     
  Branches      3509     3512       +3     
===========================================
- Hits         75735    75553     -182     
- Misses      112246   112439     +193     
+ Partials       571      543      -28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@u1-liquid
Copy link
Contributor

ちょっとoutofscopeかもしれないけどrefactorついでにpolicyでrateLimitFactorを調整すると
回数だけではなく時間も影響されて実際の影響が倍になる問題を直したほうがいいかもしれません
(durationとmax両方でfactorをかけ算/割り算するのではなくmaxにだけ割り算した方が良さそう)

@KisaragiEffective
Copy link
Collaborator

実際の影響が倍になる

正確には2乗に比例するはずです。

@KisaragiEffective KisaragiEffective marked this pull request as ready for review June 14, 2024 23:45
@KisaragiEffective
Copy link
Collaborator

mark this pull request as "ready for review": #13994 is merged

@anatawa12 anatawa12 changed the title refactor: RateLimiterService refactor&fix: RateLimiterService Jun 22, 2024
@anatawa12
Copy link
Member Author

ちょっとoutofscopeかもしれないけどrefactorついでにpolicyでrateLimitFactorを調整すると 回数だけではなく時間も影響されて実際の影響が倍になる問題を直したほうがいいかもしれません (durationとmax両方でfactorをかけ算/割り算するのではなくmaxにだけ割り算した方が良さそう)

実装しました

@syuilo

This comment was marked as resolved.

@anatawa12
Copy link
Member Author

IDEのeslintがコンフィグのロードに失敗してましたすみません

@KisaragiEffective
Copy link
Collaborator

KisaragiEffective commented Jun 22, 2024

あ、セマンティックコミットじゃない 🙇🏻

@KisaragiEffective KisaragiEffective requested a review from syuilo June 22, 2024 05:42
@syuilo
Copy link
Member

syuilo commented Jul 30, 2024

レートリミットのfactorが二回適用されて二乗の効果がある問題を修正

これは意図した挙動だった

@anatawa12
Copy link
Member Author

これは意図した挙動だった

二乗の効果にした意図は何なのでしょうか

@acid-chicken acid-chicken changed the title refactor&fix: RateLimiterService fix: RateLimiterService Jul 30, 2024
@syuilo
Copy link
Member

syuilo commented Jul 30, 2024

強さを変更したらdurationも変わる方が自然に思った(別に「factor」は回数のみに影響するとは決まっていない)

@anatawa12
Copy link
Member Author

強さが線形(2倍にしたら2倍アクセスできる)のほうが私は直感的だと私は思いました。(少なくとも過去の自分は線形の影響度を持つと解釈してました。)
今回の変更では回数を変更しましたが、durtionをfactor倍するのでも私はいいと思っています。

また、両方に影響するべきという話であれば、今の実装以外の線形の方法としてはsqrt(factor)をdurationも回数も影響させるというのが実装可能だと思います。

@kakkokari-gtyih kakkokari-gtyih modified the milestone: v2024.9.0 Sep 6, 2024
@anatawa12
Copy link
Member Author

anatawa12 commented Jan 19, 2025

rate limitのfactorの影響が線形であるほうがわかりやすいという話と、 duration / max の両方影響受けるべきという話について、影響割合をFactorの二乗に影響するように戻すべきでしょうか。(戻した場合にはUIの説明テキストの方を更新します)

@kakkokari-gtyih kakkokari-gtyih modified the milestone: v2025.2.1 Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages/backend Server side specific issue/PR
Projects
Development

Successfully merging this pull request may close these issues.

7 participants