HBASE-14604 Improve MoveCostFunction in StochasticLoadBalancer (Guanghao Zhang)
This commit is contained in:
parent
74ad3947e9
commit
b076d7dbd1
|
@ -52,6 +52,7 @@ import org.apache.hadoop.hbase.master.RegionPlan;
|
||||||
import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.Action.Type;
|
import org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster.Action.Type;
|
||||||
import org.apache.hadoop.util.StringUtils;
|
import org.apache.hadoop.util.StringUtils;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
@ -896,6 +897,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",
|
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SBSC_USE_STRINGBUFFER_CONCATENATION",
|
||||||
justification="Not important but should be fixed")
|
justification="Not important but should be fixed")
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1026,7 +1026,7 @@ public class StochasticLoadBalancer extends BaseLoadBalancer {
|
||||||
return 1000000; // return a number much greater than any of the other cost
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,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
|
@Test
|
||||||
public void testSkewCost() {
|
public void testSkewCost() {
|
||||||
Configuration conf = HBaseConfiguration.create();
|
Configuration conf = HBaseConfiguration.create();
|
||||||
|
|
Loading…
Reference in New Issue