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

Add initial impl of PartitionedRateLimiter.Create #67677

Merged
merged 12 commits into from
Apr 29, 2022

Conversation

BrennanConroy
Copy link
Member

Adds the PartitionedRateLimiter.Create method and the other types necessary to implement it.
#65400

Some more work will need to be done once #67020 is merged so we can properly handle replenishing rate limiters.

Additionally, fixed a bug (in concurrency and token bucket) with cancellation when disposing the limiter and when adding new requests to the queue. Found while writing a cancellation test for the PartitionedRateLimiter.

CreateChained and TranslateKey are not included in this change.

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Apr 6, 2022

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

Issue Details

Adds the PartitionedRateLimiter.Create method and the other types necessary to implement it.
#65400

Some more work will need to be done once #67020 is merged so we can properly handle replenishing rate limiters.

Additionally, fixed a bug (in concurrency and token bucket) with cancellation when disposing the limiter and when adding new requests to the queue. Found while writing a cancellation test for the PartitionedRateLimiter.

CreateChained and TranslateKey are not included in this change.

Author: BrennanConroy
Assignees: -
Labels:

area-System.Threading

Milestone: 7.0.0

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since #67020 is merged, can we do something? Or are we going to leave that as follow up for preview5? I guess we can announce it with the caveat that it only works for a statically bounded number of partitions. Partitioning by username for example would not be advisable.

_partitioner = partitioner;

// TODO: Only create timer once there is an active replenishing limiter
// TODO: Figure out what interval we should use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we file issues for the any TODOs we think are worth following up in the .NET 7 timeframe? I think these probably qualify. I think we might want to add public API to make this interval configurable.

_timer.Start();
while (await _timer)
{
Replenish(this);
Copy link
Member

@halter73 halter73 Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're going to have to catch any exceptions now that we rely on the loop continuing. It's unfortunate that we cannot log it, and this stops any exception from showing up as an UnhandledException. It's tempting to use ExceptionDispatchInfo.Capture and dispatch the throwing of the exception to a threadpool thread.

@BrennanConroy BrennanConroy merged commit 9b1da97 into dotnet:main Apr 29, 2022
@BrennanConroy BrennanConroy deleted the brecon/partition branch April 29, 2022 03:22
BrennanConroy added a commit to BrennanConroy/runtime that referenced this pull request Apr 29, 2022
mmitche pushed a commit that referenced this pull request Apr 29, 2022
…eate (#68695)

* Add RL non-generic fixed window, sliding window implementations (#68087)

* Add initial impl of PartitionedRateLimiter.Create (#67677)

Co-authored-by: Shreya Verma <shve9863@colorado.edu>
@ghost ghost locked as resolved and limited conversation to collaborators May 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants