Components of cache-aware load balancer

The cache-aware load balancer uses two cost elements for deciding the region allocation, cache cost and skewness cost.

Cache cost

The cache cost is calculated as the percentage of data for a region cached on the region server where it is either currently hosted or was previously hosted. A region may have multiple HFiles, each of different sizes. An HFile is considered to be fully prefetched when all the data blocks in this file are in the cache. The region server hosting this region calculates the ratio of the number of HFiles cached in the bucket cache to the total number of HFiles in the region. This ratio varies from 0 (region hosted on this server and all the HFiles for this region are cached into the bucket cache) to 1 (region hosted on this server, but none of its HFiles are cached into the bucket cache).

Every region server maintains this information for all the regions currently hosted there. In addition to that, this cache ratio is also maintained for the regions that were previously hosted on this region server giving historical information about the regions.

Skewness cost

The skewness cost is calculated as the number of regions hosted on each region server in the cluster. The skewness cost varies from 0 (regions are equally distributed across the region servers) to 1 (regions are not equally distributed across the region servers).

The balancer considers these two costs and calculates the resulting cost of maintaining the balance in the cluster. The balancer attempts to rebalance the cluster under the following conditions:

  • An idle server exists in the cluster. This can happen when an existing server is restarted or a new server is added to the cluster.
  • When the cost of maintaining the balance in the cluster is greater than the minimum threshold defined by the configuration parameter, hbase.master.balancer.stochastic.minCostNeedBalance.