-
Notifications
You must be signed in to change notification settings - Fork 5.5k
upstream: locality weighted load balancing. #2892
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
73adca2
upstream: locality weighted load balancing.
htuch faf4981
Merge remote-tracking branch 'upstream/master' into locality-weighted-lb
htuch 5e2acf4
Fix unique_ptr snafu that only showed up on OS X build.
htuch 58328f8
Eager vs. lazy locality weight adjustment.
htuch b96b20f
Cleanup overprovisioning and add tests.
htuch 0d8a161
Remove some handling for cases that can't happen due to invariants.
htuch 6128d37
TODO for subset LB locality weighting.
htuch 118336d
Merge remote-tracking branch 'upstream/master' into locality-weighted-lb
htuch 2a2123d
Fix upstream_impl_test TSAN fail.
htuch d370fbf
Merge remote-tracking branch 'upstream/master' into locality-weighted-lb
htuch 7213832
Fix typo.
htuch 17e6dbc
Merge remote-tracking branch 'upstream/master' into locality-weighted-lb
htuch 317693b
Use data-plane-api at HEAD.
htuch be7c53c
Bump data plane SHA further.
htuch d8426ec
Share kOverProvisioningFactor definition.
htuch 6fed65a
Merge remote-tracking branch 'upstream/master' into locality-weighted-lb
htuch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,16 @@ | |
| namespace Envoy { | ||
| namespace Upstream { | ||
|
|
||
| namespace { | ||
| // Priority levels are considered overprovisioned with this factor. This means that we don't | ||
| // consider a priority level unhealthy until the percentage of healthy hosts multiplied by | ||
| // kOverProvisioningFactor drops below 100. | ||
| static constexpr uint32_t kOverProvisioningFactor = 140; | ||
|
|
||
| static const std::string RuntimeZoneEnabled = "upstream.zone_routing.enabled"; | ||
| static const std::string RuntimeMinClusterSize = "upstream.zone_routing.min_cluster_size"; | ||
| static const std::string RuntimePanicThreshold = "upstream.healthy_panic_threshold"; | ||
| } // namespace | ||
|
|
||
| uint32_t LoadBalancerBase::choosePriority(uint64_t hash, | ||
| const std::vector<uint32_t>& per_priority_load) { | ||
|
|
@@ -57,13 +64,13 @@ void LoadBalancerBase::recalculatePerPriorityState(uint32_t priority) { | |
|
|
||
| // Determine the health of the newly modified priority level. | ||
| // Health ranges from 0-100, and is the ratio of healthy hosts to total hosts, modified by the | ||
| // somewhat arbitrary overprovision factor of 1.4. | ||
| // somewhat arbitrary overprovision factor of kOverProvisioningFactor. | ||
| // Eventually the overprovision factor will likely be made configurable. | ||
| HostSet& host_set = *priority_set_.hostSetsPerPriority()[priority]; | ||
| per_priority_health_[priority] = 0; | ||
| if (host_set.hosts().size() > 0) { | ||
| per_priority_health_[priority] = | ||
| std::min<uint32_t>(100, 140 * host_set.healthyHosts().size() / host_set.hosts().size()); | ||
| per_priority_health_[priority] = std::min<uint32_t>( | ||
| 100, kOverProvisioningFactor * host_set.healthyHosts().size() / host_set.hosts().size()); | ||
| } | ||
|
|
||
| // Now that we've updated health for the changed priority level, we need to caculate percentage | ||
|
|
@@ -95,7 +102,7 @@ void LoadBalancerBase::recalculatePerPriorityState(uint32_t priority) { | |
| } | ||
| } | ||
|
|
||
| const HostSet& LoadBalancerBase::chooseHostSet() { | ||
| HostSet& LoadBalancerBase::chooseHostSet() { | ||
| const uint32_t priority = choosePriority(random_.random(), per_priority_load_); | ||
| return *priority_set_.hostSetsPerPriority()[priority]; | ||
| } | ||
|
|
@@ -341,7 +348,7 @@ uint32_t ZoneAwareLoadBalancerBase::tryChooseLocalLocalityHosts(const HostSet& h | |
| } | ||
|
|
||
| ZoneAwareLoadBalancerBase::HostsSource ZoneAwareLoadBalancerBase::hostSourceToUse() { | ||
| const HostSet& host_set = chooseHostSet(); | ||
| HostSet& host_set = chooseHostSet(); | ||
| HostsSource hosts_source; | ||
| hosts_source.priority_ = host_set.priority(); | ||
|
|
||
|
|
@@ -352,6 +359,14 @@ ZoneAwareLoadBalancerBase::HostsSource ZoneAwareLoadBalancerBase::hostSourceToUs | |
| return hosts_source; | ||
| } | ||
|
|
||
| // If we're doing locality weighted balancing, pick locality. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is such a nice clean change given the prior refactor - thanks! |
||
| const absl::optional<uint32_t> locality = host_set.chooseLocality(); | ||
| if (locality.has_value()) { | ||
| hosts_source.source_type_ = HostsSource::SourceType::LocalityHealthyHosts; | ||
| hosts_source.locality_index_ = locality.value(); | ||
| return hosts_source; | ||
| } | ||
|
|
||
| // If we've latched that we can't do priority-based routing, return healthy hosts for the selected | ||
| // host set. | ||
| if (per_priority_state_[host_set.priority()]->locality_routing_state_ == | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
I seem to remember you offering to make more of this structured data rather than vectors of pairs and such? It's optional (you're not making things much worse than they were) but it'd be nice!
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 one I'll leave as is, since it's local to this function, so it would be probably less readable to start defining new types. I've been generally trying to avoid the contagion of vectors at the interface level.