@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.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.LocalityCostFunction
Compute a cost of a potential cluster configuration based upon where
StoreFile 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.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.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, masterServerName, metricsBalancer, rackManager, regionFinder, services, slop, TABLES_ON_MASTER, tablesOnMaster
Constructor and Description |
---|
StochasticLoadBalancer() |
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<HRegionInfo>> clusterState)
Given the cluster state this will try and approach an optimal balance.
|
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.
|
protected void |
initCosts(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. |
void |
setClusterStatus(ClusterStatus 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) |
private void |
updateRegionLoad()
Store the current region loads.
|
assignMasterRegions, balanceMasterRegions, createCluster, getConf, getRegionAssignmentsByServer, getTablesOnMaster, immediateAssignment, initialize, isStopped, needsBalance, randomAssignment, regionOffline, regionOnline, retainAssignment, roundRobinAssignment, setRackManager, shouldBeOnMaster, stop, tablesOnMaster
protected static final String STEPS_PER_REGION_KEY
protected static final String MAX_STEPS_KEY
protected static final String MAX_RUNNING_TIME_KEY
protected static final String KEEP_REGION_LOADS
private static final Random RANDOM
private static final org.apache.commons.logging.Log LOG
Map<String,Deque<RegionLoad>> loads
private int maxSteps
private int stepsPerRegion
private long maxRunningTime
private int numRegionLoadsToRemember
private StochasticLoadBalancer.CandidateGenerator[] candidateGenerators
private StochasticLoadBalancer.CostFromRegionLoadFunction[] regionLoadFunctions
private StochasticLoadBalancer.CostFunction[] costFunctions
private StochasticLoadBalancer.LocalityBasedCandidateGenerator localityCandidateGenerator
private StochasticLoadBalancer.LocalityCostFunction localityCost
private StochasticLoadBalancer.RegionReplicaHostCostFunction regionReplicaHostCostFunction
private StochasticLoadBalancer.RegionReplicaRackCostFunction regionReplicaRackCostFunction
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 setSlop(org.apache.hadoop.conf.Configuration conf)
setSlop
in class BaseLoadBalancer
public void setClusterStatus(ClusterStatus st)
LoadBalancer
setClusterStatus
in interface LoadBalancer
setClusterStatus
in class BaseLoadBalancer
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 informationBaseLoadBalancer.Cluster.Action nextAction(BaseLoadBalancer.Cluster cluster)
public List<RegionPlan> balanceCluster(Map<ServerName,List<HRegionInfo>> clusterState)
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)
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 The Apache Software Foundation. All rights reserved.