@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.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
StochasticLoadBalancer.CandidateGenerator
Generates a candidate action to be applied to the cluster for cost function search
|
(package private) static class |
StochasticLoadBalancer.CostFromRegionLoadAsRateFunction
Class to be used for the subset of RegionLoad costs that should be treated as rates.
|
(package private) static class |
StochasticLoadBalancer.CostFromRegionLoadFunction
Base class the allows writing costs functions from rolling average of some
number from RegionLoad.
|
(package private) static class |
StochasticLoadBalancer.CostFunction
Base class of StochasticLoadBalancer's Cost Functions.
|
(package private) static class |
StochasticLoadBalancer.LoadCandidateGenerator |
(package private) static class |
StochasticLoadBalancer.LocalityBasedCandidateGenerator |
(package private) static class |
StochasticLoadBalancer.LocalityBasedCostFunction
Compute a cost of a potential cluster configuration based upon where
HStoreFile s are located. |
(package private) static class |
StochasticLoadBalancer.MemStoreSizeCostFunction
Compute the cost of total memstore size.
|
(package private) static class |
StochasticLoadBalancer.MoveCostFunction
Given the starting state of the regions and a potential ending state
compute cost based upon the number of regions that have moved.
|
(package private) static class |
StochasticLoadBalancer.PrimaryRegionCountSkewCostFunction
Compute the cost of a potential cluster state from skew in number of
primary regions on a cluster.
|
(package private) static class |
StochasticLoadBalancer.RackLocalityCostFunction |
(package private) static class |
StochasticLoadBalancer.RandomCandidateGenerator |
(package private) static class |
StochasticLoadBalancer.ReadRequestCostFunction
Compute the cost of total number of read requests The more unbalanced the higher the
computed cost will be.
|
(package private) static class |
StochasticLoadBalancer.RegionCountSkewCostFunction
Compute the cost of a potential cluster state from skew in number of
regions on a cluster.
|
(package private) static class |
StochasticLoadBalancer.RegionReplicaCandidateGenerator
Generates candidates which moves the replicas out of the region server for
co-hosted region replicas
|
(package private) static class |
StochasticLoadBalancer.RegionReplicaHostCostFunction
A cost function for region replicas.
|
(package private) static class |
StochasticLoadBalancer.RegionReplicaRackCandidateGenerator
Generates candidates which moves the replicas out of the rack for
co-hosted region replicas in the same rack
|
(package private) static class |
StochasticLoadBalancer.RegionReplicaRackCostFunction
A cost function for region replicas for the rack distribution.
|
(package private) static class |
StochasticLoadBalancer.ServerLocalityCostFunction |
(package private) static class |
StochasticLoadBalancer.StoreFileCostFunction
Compute the cost of total open storefiles size.
|
(package private) static class |
StochasticLoadBalancer.TableSkewCostFunction
Compute the cost of a potential cluster configuration based upon how evenly
distributed tables are.
|
(package private) static class |
StochasticLoadBalancer.WriteRequestCostFunction
Compute the cost of total number of write requests.
|
BaseLoadBalancer.Cluster
clusterStatus, config, IDLE_SERVER_PREDICATOR, 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.
|
private List<RegionPlan> |
createRegionPlans(BaseLoadBalancer.Cluster cluster)
Create all of the RegionPlan's needed to move from the initial cluster state to the desired
state.
|
private String |
functionCost() |
String[] |
getCostFunctionNames()
Get the names of the cost functions
|
protected void |
initCosts(BaseLoadBalancer.Cluster cluster) |
protected boolean |
needsBalance(BaseLoadBalancer.Cluster cluster) |
(package private) BaseLoadBalancer.Cluster.Action |
nextAction(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<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
|
private void |
updateRegionLoad()
Store the current region loads.
|
private void |
updateStochasticCosts(TableName tableName,
Double overall,
Double[] subCosts)
update costs to JMX
|
assignMasterSystemRegions, balanceMasterRegions, createCluster, getConf, getRegionAssignmentsByServer, initialize, isStopped, postMasterStartupInitialize, randomAssignment, regionOffline, regionOnline, retainAssignment, roundRobinAssignment, setClusterLoad, setRackManager, shouldBeOnMaster, stop
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
private static final String TABLE_FUNCTION_SEP
protected static final String MIN_COST_NEED_BALANCE_KEY
private static final org.slf4j.Logger LOG
Map<String,Deque<BalancerRegionLoad>> loads
private int maxSteps
private boolean runMaxSteps
private int stepsPerRegion
private long maxRunningTime
private int numRegionLoadsToRemember
private float minCostNeedBalance
private List<StochasticLoadBalancer.CandidateGenerator> candidateGenerators
private StochasticLoadBalancer.CostFromRegionLoadFunction[] regionLoadFunctions
private StochasticLoadBalancer.CostFunction[] costFunctions
private Double curOverallCost
private Double[] tempFunctionCosts
private Double[] curFunctionCosts
private StochasticLoadBalancer.LocalityBasedCandidateGenerator localityCandidateGenerator
private StochasticLoadBalancer.ServerLocalityCostFunction localityCost
private StochasticLoadBalancer.RackLocalityCostFunction rackLocalityCost
private StochasticLoadBalancer.RegionReplicaHostCostFunction regionReplicaHostCostFunction
private StochasticLoadBalancer.RegionReplicaRackCostFunction regionReplicaRackCostFunction
private boolean isByTable
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<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
BaseLoadBalancer.Cluster.Action nextAction(BaseLoadBalancer.Cluster cluster)
public List<RegionPlan> balanceCluster(Map<ServerName,List<RegionInfo>> clusterState)
private void updateStochasticCosts(TableName tableName, Double overall, Double[] subCosts)
private String functionCost()
private List<RegionPlan> createRegionPlans(BaseLoadBalancer.Cluster cluster)
cluster
- The state of the clusterprivate void updateRegionLoad()
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.public static String composeAttributeName(String tableName, String costFunctionName)
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.