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

Make load-balancing extensible #600

Merged
merged 13 commits into from
Dec 15, 2020
Merged

Conversation

MihaZupan
Copy link
Member

Fixes #106
Fixes #229

Replace the internal LoadBalancingMode, ILoadBalancer, LoadBalancer with a public ILoadBalancingPolicy interface.

Following the pattern used with session affinity, LoadBalancingMiddleware resolves available policies from DI and select the current one per-invoke based on cluser config.

LoadBalancingOptions (a struct wrapping the LoadBalancingMode enum) is replaced by a string LoadBalancingPolicy.

The 5 existing load balancing strategies are implemented as separate ILoadBalancingPolicy types. Power of two choices remains the default.

ToDo: docs on load balancing

@MihaZupan MihaZupan added this to the YARP 1.0.0-preview8 milestone Dec 7, 2020
Copy link
Contributor

@alnikola alnikola left a comment

Choose a reason for hiding this comment

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

Looks good overall, besides a few comments.

docs/docfx/articles/service-fabric-int.md Show resolved Hide resolved
/// A unique identifier for this load balancing policy. This will be referenced from config.
/// </summary>
public string Name { get; }

/// <summary>
/// Picks a destination to send traffic to.
/// </summary>
// TODO: How to ensure retries pick a different destination when available?
DestinationInfo PickDestination(
Copy link
Member

Choose a reason for hiding this comment

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

Thinking out loud: I think we'll want to pass more state here like the route and cluster data, though I'm not sure which type to pass in. Algorithms with options will likely pull those from the cluster metadata. That would mean passing ClusterConfig or IReverseProxyFeature. IReverseProxyFeature might be best since I think that's where we want to expose the route data in the future. Yes they could pull the IReverseProxyFeature from the HttpContext, but that's not discoverable.

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

We should definitely keep the availableDestinations parameter.
If we're planning on adding more info onto IReverseProxyFeature, then that should be what we include for discoverability.

Do you think pointing out the GetRequiredProxyFeature extension in load balancing docs would help with discoverability enough to stick with HttpContext's "everything"?

It doesn't seem like we can reason on if/what info custom policies will rely on.
None of the built-in do (except RoundRobin, but that's our choice for state storage), and none of the ones in #107 do.
As you mention, policies with options would likely need that info.

Copy link
Member

Choose a reason for hiding this comment

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

That's a good point that none of the proposed protocols have this requirement. We can wait to see if it comes up.

Copy link
Contributor

@alnikola alnikola left a comment

Choose a reason for hiding this comment

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

LGTM

@Tratcher
Copy link
Member

Tratcher commented Dec 8, 2020

ToDo: docs on load balancing

Can you complete the docs as part of this PR?

@MihaZupan
Copy link
Member Author

Can you complete the docs as part of this PR?

There shouldn't be any big conflicting code changes coming in to block a merge, so I will push the docs to this PR.

@Tratcher
Copy link
Member

Tratcher commented Dec 8, 2020

Also check the samples and docs:

"LoadBalancing": {
"Mode": "Random"
},

@MihaZupan
Copy link
Member Author

@Tratcher can you PTAL at the added docs?

Thanks!

Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

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

The doc looks nice and simple.

I did just realize we missed updating the ConfigValidator. Should be a simple fix.

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

Successfully merging this pull request may close these issues.

Component-specific data storage Add more extensible/custom load balancers
3 participants