@InterfaceAudience.LimitedPrivate(value="Configuration") public class StochasticLoadBalancer extends BaseLoadBalancer
This is a best effort load balancer. Given a Cost function F(C) => x It will randomly try and mutate the cluster to Cprime. If F(Cprime) < F(C) then the new cluster state becomes the plan. It includes costs functions to compute the cost of:
Every cost function returns a number between 0 and 1 inclusive; where 0 is the lowest cost best solution, and 1 is the highest possible cost and the worst solution. The computed costs are scaled by their respective multipliers:
You can also add custom Cost function by setting the the following configuration value:
All custom Cost Functions needs to extends StochasticLoadBalancer.CostFunction
In addition to the above configurations, the balancer can be tuned by the following configuration values:
This balancer is best used with hbase.master.loadbalance.bytable set to false so that the balancer gets the full picture of all loads on the cluster.
| Modifier and Type | Class and Description |
|---|---|
static class |
StochasticLoadBalancer.CostFunction
Base class of StochasticLoadBalancer's Cost Functions.
|
static class |
StochasticLoadBalancer.GeneratorType |
BaseLoadBalancer.Cluster| Modifier and Type | Field and Description |
|---|---|
protected List<org.apache.hadoop.hbase.master.balancer.CandidateGenerator> |
candidateGenerators |
static double |
COST_EPSILON |
protected static String |
COST_FUNCTIONS_COST_FUNCTIONS_KEY |
protected static String |
KEEP_REGION_LOADS |
protected static String |
MAX_RUNNING_TIME_KEY |
protected static String |
MAX_STEPS_KEY |
protected static String |
MIN_COST_NEED_BALANCE_KEY |
protected static Random |
RANDOM |
protected static String |
RUN_MAX_STEPS_KEY |
protected static String |
STEPS_PER_REGION_KEY |
BALANCER_DECISION_BUFFER_ENABLED, BALANCER_REJECTION_BUFFER_ENABLED, clusterStatus, config, DEFAULT_BALANCER_DECISION_BUFFER_ENABLED, DEFAULT_BALANCER_REJECTION_BUFFER_ENABLED, isByTable, masterServerName, metricsBalancer, MIN_SERVER_BALANCE, onlySystemTablesOnMaster, overallSlop, rackManager, regionFinder, services, slop, useRegionFinderBOGUS_SERVER_NAME, SYSTEM_TABLES_ON_MASTER, TABLES_ON_MASTER| Constructor and Description |
|---|
StochasticLoadBalancer()
The constructor that pass a MetricsStochasticBalancer to BaseLoadBalancer to replace its
default MetricsBalancer
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
areSomeRegionReplicasColocated(BaseLoadBalancer.Cluster c)
Subclasses should implement this to return true if the cluster has nodes that hosts multiple
replicas for the same region, or, if there are multiple racks and the same rack hosts replicas
of the same region
|
List<RegionPlan> |
balanceTable(TableName tableName,
Map<ServerName,List<RegionInfo>> loadOfOneTable)
Given the cluster state this will try and approach an optimal balance.
|
static String |
composeAttributeName(String tableName,
String costFunctionName)
A helper function to compose the attribute name from tablename and costfunction name
|
List<org.apache.hadoop.hbase.master.balancer.CandidateGenerator> |
getCandidateGenerators()
Exposed for Testing!
|
protected org.apache.hadoop.hbase.master.balancer.CandidateGenerator |
getRandomGenerator()
Select the candidate generator to use based on the cost of cost functions.
|
protected boolean |
needsBalance(TableName tableName,
BaseLoadBalancer.Cluster cluster) |
void |
onConfigurationChange(org.apache.hadoop.conf.Configuration conf) |
protected void |
setCandidateGenerators(List<org.apache.hadoop.hbase.master.balancer.CandidateGenerator> customCandidateGenerators) |
void |
setClusterMetrics(ClusterMetrics st)
Set the current cluster status.
|
void |
setConf(org.apache.hadoop.conf.Configuration conf) |
protected void |
setSlop(org.apache.hadoop.conf.Configuration conf) |
void |
updateMetricsSize(int size)
Update the number of metrics that are reported to JMX
|
assignMasterSystemRegions, balanceCluster, balanceMasterRegions, createCluster, getConf, getRegionAssignmentsByServer, idleRegionServerExist, initialize, isStopped, postMasterStartupInitialize, randomAssignment, regionOffline, regionOnline, retainAssignment, roundRobinAssignment, setMasterServices, setRackManager, shouldBeOnMaster, stop, updateBalancerStatusclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisMasterCanHostUserRegions, isSystemTablesOnlyOnMaster, isTablesOnMasterprotected static final String STEPS_PER_REGION_KEY
protected static final String MAX_STEPS_KEY
protected static final String RUN_MAX_STEPS_KEY
protected static final String MAX_RUNNING_TIME_KEY
protected static final String KEEP_REGION_LOADS
protected static final String MIN_COST_NEED_BALANCE_KEY
protected static final String COST_FUNCTIONS_COST_FUNCTIONS_KEY
protected static final Random RANDOM
public static final double COST_EPSILON
protected List<org.apache.hadoop.hbase.master.balancer.CandidateGenerator> candidateGenerators
public StochasticLoadBalancer()
public void onConfigurationChange(org.apache.hadoop.conf.Configuration conf)
onConfigurationChange in interface ConfigurationObserveronConfigurationChange in interface LoadBalanceronConfigurationChange in class BaseLoadBalancerpublic void setConf(org.apache.hadoop.conf.Configuration conf)
setConf in interface org.apache.hadoop.conf.ConfigurablesetConf in class BaseLoadBalancerprotected void setCandidateGenerators(List<org.apache.hadoop.hbase.master.balancer.CandidateGenerator> customCandidateGenerators)
public List<org.apache.hadoop.hbase.master.balancer.CandidateGenerator> getCandidateGenerators()
protected void setSlop(org.apache.hadoop.conf.Configuration conf)
setSlop in class BaseLoadBalancerpublic void setClusterMetrics(ClusterMetrics st)
LoadBalancersetClusterMetrics in interface LoadBalancersetClusterMetrics in class BaseLoadBalancerpublic void updateMetricsSize(int size)
protected boolean areSomeRegionReplicasColocated(BaseLoadBalancer.Cluster c)
BaseLoadBalancerareSomeRegionReplicasColocated in class BaseLoadBalancerc - Cluster informationprotected boolean needsBalance(TableName tableName, BaseLoadBalancer.Cluster cluster)
needsBalance in class BaseLoadBalancerprotected org.apache.hadoop.hbase.master.balancer.CandidateGenerator getRandomGenerator()
public List<RegionPlan> balanceTable(TableName tableName, Map<ServerName,List<RegionInfo>> loadOfOneTable)
balanceTable in interface LoadBalancerbalanceTable in class BaseLoadBalancertableName - the table to be balancedloadOfOneTable - region load of servers for the specific one tableCopyright © 2007–2020 The Apache Software Foundation. All rights reserved.