Skip to content

Commit

Permalink
perf: do not allocate runtime key string inside lb (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattklein123 authored Nov 12, 2016
1 parent 5a288a0 commit 01e8004
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions source/common/upstream/load_balancer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

namespace Upstream {

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";

bool LoadBalancerBase::earlyExitNonZoneRouting() {
uint32_t number_of_zones = host_set_.healthyHostsPerZone().size();
if (number_of_zones < 2 ||
!runtime_.snapshot().featureEnabled("upstream.zone_routing.enabled", 100)) {
if (number_of_zones < 2 || !runtime_.snapshot().featureEnabled(RuntimeZoneEnabled, 100)) {
return true;
}

Expand All @@ -21,8 +24,7 @@ bool LoadBalancerBase::earlyExitNonZoneRouting() {
}

// Do not perform zone routing for small clusters.
uint64_t min_cluster_size =
runtime_.snapshot().getInteger("upstream.zone_routing.min_cluster_size", 6U);
uint64_t min_cluster_size = runtime_.snapshot().getInteger(RuntimeMinClusterSize, 6U);

if (host_set_.healthyHosts().size() < min_cluster_size) {
stats_.lb_zone_cluster_too_small_.inc();
Expand All @@ -47,7 +49,7 @@ bool LoadBalancerBase::earlyExitNonZoneRouting() {

bool LoadBalancerBase::isGlobalPanic(const HostSet& host_set) {
uint64_t global_panic_threshold =
std::min(100UL, runtime_.snapshot().getInteger("upstream.healthy_panic_threshold", 50));
std::min(100UL, runtime_.snapshot().getInteger(RuntimePanicThreshold, 50));
double healthy_percent = 100.0 * host_set.healthyHosts().size() / host_set.hosts().size();

// If the % of healthy hosts in the cluster is less than our panic threshold, we use all hosts.
Expand Down

0 comments on commit 01e8004

Please sign in to comment.