diff --git a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultHost.java b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultHost.java index b05228e5cb..7da7c76d46 100644 --- a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultHost.java +++ b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultHost.java @@ -117,7 +117,7 @@ public Addr address() { } @Override - public double loadBalancingWeight() { + public double weight() { return 1; } diff --git a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultHostPriorityStrategy.java b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultHostPriorityStrategy.java index 5a6271b615..ab8a08934e 100644 --- a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultHostPriorityStrategy.java +++ b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultHostPriorityStrategy.java @@ -133,14 +133,14 @@ private void addToResults(int groupProbability, List results) { // instead to all receive an equal portion of the groups weight. double weight = ((double) groupProbability) / hosts.size(); for (H host : hosts) { - host.loadBalancingWeight(weight); + host.weight(weight); results.add(host); } } else { double scalingFactor = groupProbability / groupTotalWeight; for (H host : hosts) { - double hostWeight = host.loadBalancingWeight() * scalingFactor; - host.loadBalancingWeight(hostWeight); + double hostWeight = host.weight() * scalingFactor; + host.weight(hostWeight); if (hostWeight > 0) { results.add(host); } @@ -152,7 +152,7 @@ private void addToResults(int groupProbability, List results) { private static double totalWeight(Iterable hosts) { double sum = 0; for (PrioritizedHost host : hosts) { - sum += host.loadBalancingWeight(); + sum += host.weight(); } return sum; } diff --git a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultLoadBalancer.java b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultLoadBalancer.java index eae092a136..33b1b586a4 100644 --- a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultLoadBalancer.java +++ b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/DefaultLoadBalancer.java @@ -508,7 +508,7 @@ private void sequentialUpdateUsedHosts(List host : nextHosts) { - host.loadBalancingWeight(host.serviceDiscoveryWeight()); + host.weight(host.serviceDiscoveryWeight()); } nextHosts = priorityStrategy.prioritize(nextHosts); nextHosts = subsetter.subset(nextHosts); @@ -706,12 +706,12 @@ void serviceDiscoveryWeight(final double weight) { // Set the weight to use in load balancing. This includes derived weight information such as prioritization // and is what the host selectors will use when picking hosts. @Override - public void loadBalancingWeight(final double weight) { + public void weight(final double weight) { this.loadBalancingWeight = weight; } @Override - public double loadBalancingWeight() { + public double weight() { return loadBalancingWeight; } diff --git a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/Host.java b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/Host.java index 9497ba0d23..66a6fbbc5e 100644 --- a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/Host.java +++ b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/Host.java @@ -73,12 +73,4 @@ interface Host extends Listen * @return true if the host is now in the closed state, false otherwise. */ boolean markExpired(); - - /** - * The weight of the host, relative to the weights of associated hosts. - * @return the relative weight of the host. - */ - default double weight() { - return 1.0; - } } diff --git a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/LoadBalancerObserver.java b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/LoadBalancerObserver.java index c223ce4db5..2f61076c6f 100644 --- a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/LoadBalancerObserver.java +++ b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/LoadBalancerObserver.java @@ -125,6 +125,6 @@ interface Host { * The weight of the host, relative to the weights of associated hosts as used for load balancing. * @return the relative weight of the host. */ - double loadBalancingWeight(); + double weight(); } } diff --git a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/PrioritizedHost.java b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/PrioritizedHost.java index 31cf4def30..47250add33 100644 --- a/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/PrioritizedHost.java +++ b/servicetalk-loadbalancer-experimental/src/main/java/io/servicetalk/loadbalancer/PrioritizedHost.java @@ -42,11 +42,11 @@ interface PrioritizedHost { * The weight of the host to use for load balancing. * @return the weight of the host to use for load balancing. */ - double loadBalancingWeight(); + double weight(); /** * Set the weight of the host to use during load balancing. * @param weight the weight of the host to use during load balancing. */ - void loadBalancingWeight(double weight); + void weight(double weight); } diff --git a/servicetalk-loadbalancer-experimental/src/test/java/io/servicetalk/loadbalancer/DefaultHostPriorityStrategyTest.java b/servicetalk-loadbalancer-experimental/src/test/java/io/servicetalk/loadbalancer/DefaultHostPriorityStrategyTest.java index 534589d8b5..96d69a58a5 100644 --- a/servicetalk-loadbalancer-experimental/src/test/java/io/servicetalk/loadbalancer/DefaultHostPriorityStrategyTest.java +++ b/servicetalk-loadbalancer-experimental/src/test/java/io/servicetalk/loadbalancer/DefaultHostPriorityStrategyTest.java @@ -47,7 +47,7 @@ void noPriorities() { void noPrioritiesWithWeights() { List hosts = makeHosts(4); for (int i = 0; i < hosts.size(); i++) { - hosts.get(i).loadBalancingWeight(i + 1d); + hosts.get(i).weight(i + 1d); } List result = hostPriorityStrategy.prioritize(hosts); assertThat(result.size(), equalTo(hosts.size())); @@ -79,7 +79,7 @@ void twoPrioritiesNoWeights() { void twoPrioritiesWithWeights() { List hosts = makeHosts(6); for (int i = 0; i < hosts.size(); i++) { - hosts.get(i).loadBalancingWeight(i + 1d); + hosts.get(i).weight(i + 1d); if (i >= 3) { hosts.get(i).priority(1); } @@ -99,7 +99,7 @@ void twoPrioritiesWithWeights() { void twoPrioritiesWithWeightsButSkipNumbers() { List hosts = makeHosts(6); for (int i = 0; i < hosts.size(); i++) { - hosts.get(i).loadBalancingWeight(i + 1d); + hosts.get(i).weight(i + 1d); if (i >= 3) { hosts.get(i).priority(2); } @@ -119,7 +119,7 @@ void twoPrioritiesWithWeightsButSkipNumbers() { void noHealthyNodesDoesntFilterOutElements() { List hosts = makeHosts(6); for (int i = 0; i < hosts.size(); i++) { - hosts.get(i).loadBalancingWeight(i + 1d); + hosts.get(i).weight(i + 1d); hosts.get(i).isHealthy = false; if (i >= 3) { hosts.get(i).priority(1); @@ -206,10 +206,10 @@ void priorityGroupsWithWeightedUnhealthyNodes() { hosts.get(0).isHealthy(false); for (int i = 0; i < hosts.size(); i++) { if (i >= 3) { - hosts.get(i).loadBalancingWeight(i - 3 + 1d); + hosts.get(i).weight(i - 3 + 1d); hosts.get(i).priority(1); } else { - hosts.get(i).loadBalancingWeight(i + 1d); + hosts.get(i).weight(i + 1d); } } List result = hostPriorityStrategy.prioritize(hosts); @@ -241,10 +241,10 @@ void onlyHealthyNodesAreZeroWeight() { List hosts = makeHosts(6); for (int i = 0; i < hosts.size(); i++) { if (i >= 3) { - hosts.get(i).loadBalancingWeight(0); + hosts.get(i).weight(0); hosts.get(i).priority(1); } else { - hosts.get(i).loadBalancingWeight(1); + hosts.get(i).weight(1); hosts.get(i).isHealthy = false; } } @@ -312,7 +312,7 @@ void priority(final int priority) { // Set the weight to use in load balancing. This includes derived weight information such as prioritization // and is what the host selectors will use when picking endpoints. @Override - public void loadBalancingWeight(final double weight) { + public void weight(final double weight) { this.loadBalancedWeight = weight; } @@ -330,7 +330,7 @@ public void isHealthy(final boolean isHealthy) { } @Override - public double loadBalancingWeight() { + public double weight() { return loadBalancedWeight; } } diff --git a/servicetalk-loadbalancer-experimental/src/test/java/io/servicetalk/loadbalancer/DefaultLoadBalancerTest.java b/servicetalk-loadbalancer-experimental/src/test/java/io/servicetalk/loadbalancer/DefaultLoadBalancerTest.java index 37ad089230..04680b552c 100644 --- a/servicetalk-loadbalancer-experimental/src/test/java/io/servicetalk/loadbalancer/DefaultLoadBalancerTest.java +++ b/servicetalk-loadbalancer-experimental/src/test/java/io/servicetalk/loadbalancer/DefaultLoadBalancerTest.java @@ -185,10 +185,10 @@ void changesToPriorityOrWeightTriggerRebuilds() throws Exception { public List prioritize(List hosts) { assert hosts.size() == 1; T host = hosts.get(0); - value.set(host.loadBalancingWeight()); + value.set(host.weight()); // We want to adjust the weight here so that if the `loadBalancingWeight()` fails to be // reset then the test will fail. - host.loadBalancingWeight(0.5 * host.loadBalancingWeight()); + host.weight(0.5 * host.weight()); return hosts; } }; @@ -201,7 +201,7 @@ public List prioritize(List hosts) { List> curentHosts = refinedLb.hosts(); assertThat(curentHosts, hasSize(1)); assertThat(curentHosts.get(0).priority(), equalTo(0)); - assertThat(curentHosts.get(0).loadBalancingWeight(), equalTo(0.5)); + assertThat(curentHosts.get(0).weight(), equalTo(0.5)); assertThat(value.getAndSet(null), equalTo(1.0)); // send a new event with a different priority group. This should trigger another build. @@ -209,7 +209,7 @@ public List prioritize(List hosts) { curentHosts = refinedLb.hosts(); assertThat(curentHosts, hasSize(1)); assertThat(curentHosts.get(0).priority(), equalTo(1)); - assertThat(curentHosts.get(0).loadBalancingWeight(), equalTo(0.5)); + assertThat(curentHosts.get(0).weight(), equalTo(0.5)); assertThat(value.getAndSet(null), equalTo(1.0)); // send a new event with a different weight. This should trigger yet another build. @@ -217,7 +217,7 @@ public List prioritize(List hosts) { curentHosts = refinedLb.hosts(); assertThat(curentHosts, hasSize(1)); assertThat(curentHosts.get(0).priority(), equalTo(1)); - assertThat(curentHosts.get(0).loadBalancingWeight(), equalTo(1.0)); + assertThat(curentHosts.get(0).weight(), equalTo(1.0)); assertThat(value.getAndSet(null), equalTo(2.0)); }