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

Expose a public ConcurrentRequestCount property on ClusterState, like DestinationState #2223

Closed

Conversation

j3parker
Copy link

We use different clusters for rolling out updates to our software. To support rollout we want each YARP server to monitor the outgoing clusters for remaining connections. When this drops to zero for a cluster, the YARP server communicates this to a central location and drops the reference to the ClusterState. Once all YARP servers have reported the cluster as drained (or a timeout occurs) we mark the deployment as complete.

DestinationState has a public ConcurrentRequestCount property that works the same way, by exposing ConcurrencyCounter.Value. I didn't add the setter in this PR (DestinationState says it is only for testing) in the interests of a making the change smaller.

… DestinationState has


We use different clusters for rolling out updates to our software. To support rollout we want each YARP server to monitor the outgoing clusters for remaining connections. When this drops to zero for a cluster, the YARP server communicates this to a central location and drops the reference to the ClusterState. Once all YARP servers have reported the cluster as drained (or a timeout occurs) we mark the deployment as complete.

DestinationState has a public ConcurrentRequestCount property that works the same way, by exposing `ConcurrencyCounter.Value`. I didn't add the setter in this PR (DestinationState says it is only for testing) in the interests of a making the change smaller.
public int ConcurrentRequestCount
{
get => ConcurrencyCounter.Value;
}
Copy link
Author

Choose a reason for hiding this comment

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

DestinationState.ConcurrentRequestCount for comparison:

/// <summary>
/// Keeps track of the total number of concurrent requests on this endpoint.
/// The setter should only be used for testing purposes.
/// </summary>
public int ConcurrentRequestCount
{
get => ConcurrencyCounter.Value;
set => ConcurrencyCounter.Value = value;
}
internal AtomicCounter ConcurrencyCounter { get; } = new AtomicCounter();

Copy link
Member

Choose a reason for hiding this comment

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

There's a race here where the count could be zero but a request is about to increment it. Any monitoring logic would need to wait a minimum amount of time in order to make sure all current requests are able to properly enter the pipeline.

There's also no way to monitor this value except polling which doesn't seem ideal. It seems like you don't need to know the actual value, just if it's still in use. Would a WeakHandle work just as well for that?

Copy link
Author

Choose a reason for hiding this comment

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

Good point RE: the race condition.

Yep, polling isn't amazing. It will work fine for us in our context (the rate of poling we're thinking, the number of clusters we'll be watching at any time etc.) but I could see that being an issue generally.

You're right -- a weak reference would satisfy our use-case better.

@Tratcher
Copy link
Member

Please don't submit PRs without first filing an issue to discuss the requirements and design.

@j3parker
Copy link
Author

Please don't submit PRs without first filing an issue to discuss the requirements and design.

Sorry about that.

I'm going to look into the weak reference thing for our use-case. That would still mean polling the outgoing resources. Do you want me to open an issue for destination/cluster draining monitoring in general? YARP could possibly help here e.g. by allowing you to listen for "draining complete" events, etc.

@j3parker j3parker closed this Aug 22, 2023
@j3parker j3parker deleted the ClusterState.ConcurrentRequestCount branch August 22, 2023 18:56
@Tratcher
Copy link
Member

Yes, please open an issue for the general scenario and we can look into possible solutions.

@j3parker
Copy link
Author

Ok -- #2225

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants