HBASE-14604 Improve MoveCostFunction in StochasticLoadBalancer (Guanghao Zhang)
This commit is contained in:
parent
c9523a569d
commit
6046596403
|
@ -54,6 +54,7 @@ import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.Action.T
|
|||
import org.apache.hadoop.hbase.security.access.AccessControlLists;
|
||||
import org.apache.hadoop.util.StringUtils;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
|
@ -898,6 +899,16 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
|
|||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected void setNumRegions(int numRegions) {
|
||||
this.numRegions = numRegions;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected void setNumMovedRegions(int numMovedRegions) {
|
||||
this.numMovedRegions = numMovedRegions;
|
||||
}
|
||||
|
||||
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SBSC_USE_STRINGBUFFER_CONCATENATION",
|
||||
justification="Not important but should be fixed")
|
||||
@Override
|
||||
|
|
|
@ -1026,7 +1026,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
|||
return 1000000; // return a number much greater than any of the other cost
|
||||
}
|
||||
|
||||
return scale(0, cluster.numRegions, moveCost);
|
||||
return scale(0, Math.min(cluster.numRegions, maxMoves), moveCost);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -121,6 +121,44 @@ public class TestStochasticLoadBalancer extends BalancerTestBase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveCost() throws Exception {
|
||||
Configuration conf = HBaseConfiguration.create();
|
||||
StochasticLoadBalancer.CostFunction
|
||||
costFunction = new StochasticLoadBalancer.MoveCostFunction(conf);
|
||||
for (int[] mockCluster : clusterStateMocks) {
|
||||
BaseLoadBalancer.Cluster cluster = mockCluster(mockCluster);
|
||||
costFunction.init(cluster);
|
||||
double cost = costFunction.cost();
|
||||
assertEquals(0.0f, cost, 0.001);
|
||||
|
||||
// cluster region number is smaller than maxMoves=600
|
||||
cluster.setNumRegions(200);
|
||||
cluster.setNumMovedRegions(10);
|
||||
cost = costFunction.cost();
|
||||
assertEquals(0.05f, cost, 0.001);
|
||||
cluster.setNumMovedRegions(100);
|
||||
cost = costFunction.cost();
|
||||
assertEquals(0.5f, cost, 0.001);
|
||||
cluster.setNumMovedRegions(200);
|
||||
cost = costFunction.cost();
|
||||
assertEquals(1.0f, cost, 0.001);
|
||||
|
||||
|
||||
// cluster region number is bigger than maxMoves=2500
|
||||
cluster.setNumRegions(10000);
|
||||
cluster.setNumMovedRegions(250);
|
||||
cost = costFunction.cost();
|
||||
assertEquals(0.1f, cost, 0.001);
|
||||
cluster.setNumMovedRegions(1250);
|
||||
cost = costFunction.cost();
|
||||
assertEquals(0.5f, cost, 0.001);
|
||||
cluster.setNumMovedRegions(2500);
|
||||
cost = costFunction.cost();
|
||||
assertEquals(1.0f, cost, 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkewCost() {
|
||||
Configuration conf = HBaseConfiguration.create();
|
||||
|
|
Loading…
Reference in New Issue