HBASE-26872 Load rate calculator for cost functions should be more precise (#4280)

Signed-off-by: Bryan Beaudreault <bbeaudreault@hubspot.com>
Signed-off-by: Viraj Jasani<virajjasani@apache.org>
This commit is contained in:
Xiaolin Ha 2022-03-27 15:20:51 +08:00 committed by GitHub
parent 34cb2ee967
commit 9a7ee77bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -1328,7 +1328,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
double cost = 0;
do {
double current = getCostFromRl(iter.next());
cost += current - previous;
cost += current >= previous ? current - previous : current;
previous = current;
} while (iter.hasNext());
return Math.max(0, cost / (regionLoadList.size() - 1));

View File

@ -358,6 +358,32 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
assertEquals(2.5, result, 0.01);
}
@Test
public void testRegionLoadCostWhenDecrease() {
List<BalancerRegionLoad> regionLoads = new ArrayList<>();
// test region loads of [1,2,1,4]
for (int i = 1; i < 5; i++) {
int load = i == 3 ? 1 : i;
BalancerRegionLoad regionLoad = mock(BalancerRegionLoad.class);
when(regionLoad.getReadRequestsCount()).thenReturn((long)load);
when(regionLoad.getStorefileSizeMB()).thenReturn(load);
regionLoads.add(regionLoad);
}
Configuration conf = HBaseConfiguration.create();
StochasticLoadBalancer.ReadRequestCostFunction readCostFunction =
new StochasticLoadBalancer.ReadRequestCostFunction(conf);
double rateResult = readCostFunction.getRegionLoadCost(regionLoads);
// read requests are treated as a rate, so here is the average rate
assertEquals(1.67, rateResult, 0.01);
StochasticLoadBalancer.StoreFileCostFunction storeFileCostFunction =
new StochasticLoadBalancer.StoreFileCostFunction(conf);
rateResult = storeFileCostFunction.getRegionLoadCost(regionLoads);
// storefile size cost is simply an average of it's value over time
assertEquals(2.0, rateResult, 0.01);
}
@Test
public void testLosingRs() throws Exception {
int numNodes = 3;