-
Notifications
You must be signed in to change notification settings - Fork 919
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
Implement locality/priority based load balancing #5610
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good! 👍👍
return null; | ||
} | ||
if (!prioritySet.hostSets().containsKey(hostsSource.priority)) { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question) With the current implementation, does hostsSource.priority
always exist so we can't reach here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, let me just throw an exception here to make this clearer 👍
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/EndpointGroupUtil.java
Outdated
Show resolved
Hide resolved
|
||
static int hash(ClientRequestContext ctx) { | ||
if (ctx.hasAttr(XdsAttributesKeys.SELECTION_HASH)) { | ||
return ctx.attr(XdsAttributesKeys.SELECTION_HASH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question)
- Could we ensure that the value set with
XdsAttributesKeys.SELECTION_HASH
is a non-negative number? - Where does the value of
SELECTION_HASH
come from? I checked that it is used for testing in this PR. Will it be fetched from a control plane later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the value of SELECTION_HASH come from? I checked that it is used for testing in this PR. Will it be fetched from a control plane later?
I believe this is only used from tests in upstream as well. I think it's fine to remove this attribute if it is too confusing. Let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks excellent. Thanks a lot!
I left a few suggestions, mostly nits and style issues.
I also noticed that there are no logs at all. If everything goes well, it shouldn't be a problem. However, if something goes wrong, troubleshooting will be very difficult. Could you add trace or debug logs where you think they are necessary?
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/ClusterEntry.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/ClusterEntry.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/UpdateHostsParam.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/UpdateHostsParam.java
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/EndpointUtil.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/EndpointUtil.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/HostSet.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/HostSet.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/DefaultLbStateFactory.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks excellent. Thanks a lot!
I left a few suggestions, mostly nits and style issues.
I also noticed that there are no logs at all. If everything goes well, it shouldn't be a problem. However, if something goes wrong, troubleshooting will be very difficult. Could you add trace or debug logs where you think they are necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks excellent. Thanks a lot!
I left a few suggestions, mostly nits and style issues.
I also noticed that there are no logs at all. If everything goes well, it shouldn't be a problem. However, if something goes wrong, troubleshooting will be very difficult. Could you add trace or debug logs where you think they are necessary?
Good point. Added logs in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor comments. Looks good!
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/DefaultLbStateFactory.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/DefaultLbStateFactory.java
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/DefaultLoadBalancer.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/DefaultLoadBalancer.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/DefaultLoadBalancer.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/HostSet.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/PriorityStateManager.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/PriorityStateManager.java
Outdated
Show resolved
Hide resolved
xds/src/main/java/com/linecorp/armeria/xds/client/endpoint/XdsAttributesKeys.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor comments. Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Way to go, @jrhee17! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, @jrhee17! Thanks a lot. 👍 👍 👍
👍 👍 👍 👍 👍 |
Motivation:
This pull request attempts to implement the default EdfLoadBalancerBase which is the default load balancer used in envoy. Most load balancer implementations in envoy derive from this base class.
The basic load balancer supports locality weighted load balancing and priority levels.
Note that not all functionality (namely zone aware load balancing, etc..) have been implemented for simplicity.
Additionally, SubsetLoadBalancer has not been implemented in this PR for easier reviewing. The previous
SubsetLoadBalancer
will be replaced in the next (and final) pull request.This pull request mostly focuses on updating the
LoadBalancer
state when aClusterSnapshot
is updated.The flow is as follows:
ClusterEntry#accept
is called, which indicates aClusterSnapshot
has been updatedPrioritySet
contains a map ofInteger -> HostSet
where a HostSet contains host information for each health/locality.DefaultLbStateFactory
is created which creates aLbState
for theDefaultLoadBalancer
. ALbState
is a convenience object used to avoid potential race conditions. TheLbState
is replaced atomically from the perspective ofDefaultLoadBalancer
.envoy
source, each load balancer registers a callback which listens forHostSet
updates. Once aHostSet
is updated, the load balancer state is updated.HostSource
, and subsequently a host from the selectedHostSet
ref: #5450
Modifications:
ClusterEntry
now creates aPrioritySet
for eachClusterSnapshot
updatePrioritySet
, utility classesPriorityStateManager
,PriorityState
,HostSet
,UpdateHostsParam
have been created.EndpointUtil
,EndpointGroupUtil
have been createdDefaultLoadBalancer
has been introduced. The functionality of thisLoadBalancer
is equivalent toEdfLoadBalancer
.DefaultLbStateFactory
has been introduced to facilitate creating a state forDefaultLoadBalancer
. TheLbState
created byDefaultLbStateFactory
is intended to be updated atomically from the perspective ofDefaultLoadBalancer
.Result:
XdsEndpointGroup