Skip to content
Permalink
Browse files
HBASE-26872 Load rate calculator for cost functions should be more pr…
…ecise (#4253)

Signed-off-by: Bryan Beaudreault <bbeaudreault@hubspot.com>
Signed-off-by: Viraj Jasani<virajjasani@apache.org>
  • Loading branch information
sunhelly committed Mar 27, 2022
1 parent 698937d commit ad70ac2cd18c1411d96cd10e2b0ddb2dfe8c9635
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
@@ -42,9 +42,9 @@ protected double getRegionLoadCost(Collection<BalancerRegionLoad> regionLoadList
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));
}
}
}
@@ -23,7 +23,6 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -51,7 +50,6 @@
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils;

@Category({ MasterTests.class, MediumTests.class })
@@ -519,6 +517,32 @@ public void testRegionLoadCost() {
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.getCpRequestsCount()).thenReturn((long)load);
regionLoads.add(regionLoad);
}

Configuration conf = HBaseConfiguration.create();
ReadRequestCostFunction readCostFunction =
new ReadRequestCostFunction(conf);
double rateResult = readCostFunction.getRegionLoadCost(regionLoads);
// read requests are treated as a rate so the average rate here is simply 1
assertEquals(1.67, rateResult, 0.01);

CPRequestCostFunction cpCostFunction =
new CPRequestCostFunction(conf);
rateResult = cpCostFunction.getRegionLoadCost(regionLoads);
// coprocessor requests are treated as a rate so the average rate here is simply 1
assertEquals(1.67, rateResult, 0.01);
}

@Test
public void testLosingRs() throws Exception {
int numNodes = 3;

0 comments on commit ad70ac2

Please sign in to comment.