@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:
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.
BaseLoadBalancer.Cluster
Modifier and Type | Field and Description |
---|---|
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 |
clusterStatus, config, maintenanceMode, masterServerName, metricsBalancer, MIN_SERVER_BALANCE, onlySystemTablesOnMaster, overallSlop, rackManager, regionFinder, services, slop, useRegionFinder
BOGUS_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> |
balanceCluster(Map<ServerName,List<RegionInfo>> clusterState)
Given the cluster state this will try and approach an optimal balance.
|
List<RegionPlan> |
balanceCluster(TableName tableName,
Map<ServerName,List<RegionInfo>> clusterState)
Perform the major balance operation
|
static String |
composeAttributeName(String tableName,
String costFunctionName)
A helper function to compose the attribute name from tablename and costfunction name
|
protected double |
computeCost(BaseLoadBalancer.Cluster cluster,
double previousCost)
This is the main cost function.
|
String[] |
getCostFunctionNames()
Get the names of the cost functions
|
protected void |
initCosts(BaseLoadBalancer.Cluster cluster) |
protected boolean |
needsBalance(BaseLoadBalancer.Cluster cluster) |
void |
onConfigurationChange(org.apache.hadoop.conf.Configuration conf)
This method would be called by the
ConfigurationManager
object when the Configuration object is reloaded from disk. |
protected void |
setCandidateGenerators(List<org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer.CandidateGenerator> customCandidateGenerators) |
void |
setClusterMetrics(ClusterMetrics st)
Set the current cluster status.
|
void |
setConf(org.apache.hadoop.conf.Configuration conf) |
void |
setMasterServices(MasterServices masterServices)
Set the master service.
|
protected void |
setSlop(org.apache.hadoop.conf.Configuration conf) |
protected void |
updateCostsWithAction(BaseLoadBalancer.Cluster cluster,
BaseLoadBalancer.Cluster.Action action) |
void |
updateMetricsSize(int size)
Update the number of metrics that are reported to JMX
|
assignMasterSystemRegions, balanceMasterRegions, createCluster, getConf, getRegionAssignmentsByServer, initialize, isStopped, postMasterStartupInitialize, randomAssignment, regionOffline, regionOnline, retainAssignment, roundRobinAssignment, setClusterLoad, setRackManager, shouldBeOnMaster, stop, updateBalancerStatus
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isMasterCanHostUserRegions, isSystemTablesOnlyOnMaster, isTablesOnMaster
protected 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 Random RANDOM
public StochasticLoadBalancer()
public void onConfigurationChange(org.apache.hadoop.conf.Configuration conf)
ConfigurationObserver
ConfigurationManager
object when the Configuration
object is reloaded from disk.onConfigurationChange
in interface ConfigurationObserver
onConfigurationChange
in interface LoadBalancer
onConfigurationChange
in class BaseLoadBalancer
public void setConf(org.apache.hadoop.conf.Configuration conf)
setConf
in interface org.apache.hadoop.conf.Configurable
setConf
in class BaseLoadBalancer
protected void setCandidateGenerators(List<org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer.CandidateGenerator> customCandidateGenerators)
protected void setSlop(org.apache.hadoop.conf.Configuration conf)
setSlop
in class BaseLoadBalancer
public void setClusterMetrics(ClusterMetrics st)
LoadBalancer
setClusterMetrics
in interface LoadBalancer
setClusterMetrics
in class BaseLoadBalancer
public void updateMetricsSize(int size)
public void setMasterServices(MasterServices masterServices)
LoadBalancer
setMasterServices
in interface LoadBalancer
setMasterServices
in class BaseLoadBalancer
protected boolean areSomeRegionReplicasColocated(BaseLoadBalancer.Cluster c)
BaseLoadBalancer
areSomeRegionReplicasColocated
in class BaseLoadBalancer
c
- Cluster informationprotected boolean needsBalance(BaseLoadBalancer.Cluster cluster)
needsBalance
in class BaseLoadBalancer
public List<RegionPlan> balanceCluster(TableName tableName, Map<ServerName,List<RegionInfo>> clusterState)
LoadBalancer
public List<RegionPlan> balanceCluster(Map<ServerName,List<RegionInfo>> clusterState)
protected void initCosts(BaseLoadBalancer.Cluster cluster)
protected void updateCostsWithAction(BaseLoadBalancer.Cluster cluster, BaseLoadBalancer.Cluster.Action action)
public String[] getCostFunctionNames()
protected double computeCost(BaseLoadBalancer.Cluster cluster, double previousCost)
cluster
- The state of the clusterpreviousCost
- the previous cost. This is used as an early out.Copyright © 2007–2019 Cloudera. All rights reserved.