Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/envoy/upstream/upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,14 @@ class Host : virtual public HostDescription {
virtual void setOutlierDetector(Outlier::DetectorHostMonitorPtr&& outlier_detector) PURE;

/**
* @return the current load balancing weight of the host, in the range 1-100.
* @return the current load balancing weight of the host, in the range 1-128 (see
* envoy.api.v2.endpoint.Endpoint.load_balancing_weight).
*/
virtual uint32_t weight() const PURE;

/**
* Set the current load balancing weight of the host, in the range 1-100.
* Set the current load balancing weight of the host, in the range 1-128 (see
* envoy.api.v2.endpoint.Endpoint.load_balancing_weight).
*/
virtual void weight(uint32_t new_weight) PURE;

Expand Down
24 changes: 10 additions & 14 deletions source/common/upstream/maglev_lb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MaglevTable::MaglevTable(const HostsPerLocality& hosts_per_locality,
}
};

// Compute maximum host weight. If this is zero, we are doing unweighted Maglev.
// Compute maximum host weight.
uint32_t max_host_weight = 0;
uint32_t total_hosts = 0;
for (uint32_t i = 0; i < hosts_per_locality.get().size(); ++i) {
Expand All @@ -46,8 +46,7 @@ MaglevTable::MaglevTable(const HostsPerLocality& hosts_per_locality,
const std::string& address = host->address()->asString();
table_build_entries.emplace_back(host, HashUtil::xxHash64(address) % table_size_,
(HashUtil::xxHash64(address, 1) % (table_size_ - 1)) + 1,
max_host_weight > 0 ? effective_weight(host->weight(), i)
: 0);
effective_weight(host->weight(), i));
Comment thread
mergeconflict marked this conversation as resolved.
}
}

Expand All @@ -57,18 +56,15 @@ MaglevTable::MaglevTable(const HostsPerLocality& hosts_per_locality,
while (true) {
for (uint64_t i = 0; i < table_build_entries.size(); i++) {
TableBuildEntry& entry = table_build_entries[i];
// Only consider weight if we are doing weighted Maglev.
if (max_host_weight > 0) {
// Counts are in units of max_host_weight. To understand how counts_ and
// weight_ are used below, consider a host with weight equal to
// max_host_weight. This would be picked on every single iteration. If
// it had weight equal to backend_weight_scale / 3, then this would only
// happen every 3 iterations, etc.
if (iteration * entry.weight_ < entry.counts_) {
continue;
}
entry.counts_ += max_host_weight;
// Counts are in units of max_host_weight. To understand how counts_ and
// weight_ are used below, consider a host with weight equal to
// max_host_weight. This would be picked on every single iteration. If
// it had weight equal to backend_weight_scale / 3, then this would only
// happen every 3 iterations, etc.
if (iteration * entry.weight_ < entry.counts_) {
continue;
Comment thread
mergeconflict marked this conversation as resolved.
}
entry.counts_ += max_host_weight;
uint64_t c = permutation(entry);
while (table_[c] != nullptr) {
entry.next_++;
Expand Down