dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.99k stars 4.67k forks source link

System.Threading.RateLimiting Sliding vs Fix windows implementation #76510

Open AliKhalili opened 1 year ago

AliKhalili commented 1 year ago

Sliding window is quite similar to the fixed window approach but different in that it also has a segment per window option. Technically, we can consider fix window algorithm as a special case of sliding window algorithm for resource rate limiting. So, regarding DRY and have a more clear code base, I would suggest remove fix window internal implementation and inherit it from the sliding window class. The only needed change is on the fix window constructor initialize base class(sliding window instance) with SegmentsPerWindow = 1.

We can also expect not remarkable performance to degrade with using an array with a segment for fix window. I am keen to know your thoughts. Thanks cc: @BrennanConroy

dotnet-issue-labeler[bot] commented 1 year ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost commented 1 year ago

Tagging subscribers to this area: @mangod9 See info in area-owners.md if you want to be subscribed.

Issue Details
Sliding window is quite similar to the fixed window approach but different in that it also has a segment per window option. Technically, we can consider fix window algorithm as a special case of sliding window algorithm for resource rate limiting. So, regarding DRY and have a more clear code base, I would suggest remove fix window internal implementation and inherit it from the sliding window class. The only needed change is on the fix window constructor initialize base class(sliding window instance) with `SegmentsPerWindow = 1`. We can also expect not remarkable performance to degrade with using an array with a segment for fix window. I am keen to know your thoughts. Thanks cc: @BrennanConroy
Author: AliKhalili
Assignees: -
Labels: `area-System.Threading`, `untriaged`
Milestone: -