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:
parent
34cb2ee967
commit
9a7ee77bd4
|
@ -1328,7 +1328,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
double cost = 0;
|
double cost = 0;
|
||||||
do {
|
do {
|
||||||
double current = getCostFromRl(iter.next());
|
double current = getCostFromRl(iter.next());
|
||||||
cost += current - previous;
|
cost += current >= previous ? current - previous : current;
|
||||||
previous = current;
|
previous = current;
|
||||||
} while (iter.hasNext());
|
} while (iter.hasNext());
|
||||||
return Math.max(0, cost / (regionLoadList.size() - 1));
|
return Math.max(0, cost / (regionLoadList.size() - 1));
|
||||||
|
|
|
@ -358,6 +358,32 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
|
||||||
assertEquals(2.5, result, 0.01);
|
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
|
@Test
|
||||||
public void testLosingRs() throws Exception {
|
public void testLosingRs() throws Exception {
|
||||||
int numNodes = 3;
|
int numNodes = 3;
|
||||||
|
|
Loading…
Reference in New Issue