HBase性能优化系列(一)

作者: Alex90 | 来源:发表于2018-07-23 19:01 被阅读27次

    针对IO进行性能优化(一)

    如果服务器IO能力弱,进行限流控制

    Compaction吞吐量限制

    有效版本 1.1.0+ 2.0.0+
    hbase-2.0.0版本开始默认有限制,hbase-1.x版本默认不限制

    HBASE-8329
    相关参数:
    hbase.regionserver.throughput.controller
    hbase.hstore.compaction.throughput.offpeak
    hbase.hstore.compaction.throughput.lower.bound
    hbase.hstore.compaction.throughput.higher.bound
    hbase.hstore.blockingStoreFiles

    解释如下:
    增加Compaction吞吐量限制机制。
    默认值是org.apache.hadoop.hbase.regionserver.compactions.PressureAwareCompactionThroughputController
    将限制吞吐量如下:

    1. 在非高峰时段(off peak hours),使用固定的限制hbase.hstore.compaction.throughput.offpeak(默认值是Long.MAX_VALUE,这意味着没有限制)
    2. 在正常时段,限制在hbase.hstore.compaction.throughput.lower.bound(默认10Mb/s)和hbase.hstore.compaction.throughput.higher.bound(默认20Mb/s)之间,使用公式"lower + (higer - lower) * param"计算,param范围:[0,1 ],并基于该RegionServer上StoreFile数量进行计算。
    3. 如果一些Store有太多的StoreFile(StoreFile数量大于上限hbase.hstore.blockingStoreFiles),那么没有限制,无论是高峰或非高峰。

    可以将hbase.regionserver.throughput.controller设置为org.apache.hadoop.hbase.regionserver.throttle.NoLimitThroughputController,禁用吞吐量控制。

    而且已经实现了ConfigurationObserver观察者,这意味着可以更改上面的所有配置,不需要重新启动群集。

    1.3.0版本的包路径 org.apache.hadoop.hbase.regionserver.throttle

    部分代码实现

    // NoLimitThroughputController不控制流量,代码实现无
    public class PressureAwareCompactionThroughputController 
        implements CompactionThroughputController {
        
        // 控制Compact流量,如果速度太快通过Sleep控制
        @Override
        public long control(String compactionName, long size) throws InterruptedException {
            // 正在运行的Compaction
            ActiveCompaction compaction = activeCompactions.get(compactionName);
            compaction.totalSize += size;
            
            long deltaSize = compaction.totalSize - compaction.lastControlSize;}
            
            long now = EnvironmentEdgeManager.currentTime();
            double maxThroughputPerCompaction = this.maxThroughput / activeCompactions.size();
            // Compaction最低时间
            long minTimeAllowed = (long) (deltaSize / maxThroughputPerCompaction * 1000); 
            long elapsedTime = now - compaction.lastControlTime;
            compaction.lastControlSize = compaction.totalSize;
            if (elapsedTime >= minTimeAllowed) {
                // 如果速度正常
                compaction.lastControlTime = EnvironmentEdgeManager.currentTime();
                return 0;
            }
            // 如果速度太快,Compact时间少于最低时间
            // 睡眠一段时间
            long sleepTime = minTimeAllowed - elapsedTime;
                
            Thread.sleep(sleepTime);
            compaction.numberOfSleeps++;
            compaction.totalSleepTime += sleepTime;
            compaction.lastControlTime = EnvironmentEdgeManager.currentTime();
            return sleepTime;
        }
    }
    

    Flush限流

    有效版本 1.3.0+ 2.0.0+
    默认不开启

    HBASE-14969
    相关参数:
    hbase.regionserver.throughput.controller
    hbase.hstore.flush.throughput.upper.bound
    hbase.hstore.flush.throughput.lower.bound
    hbase.hstore.flush.throughput.tune.period

    解释如下:
    增加Flush的流量控制。默认没有限制,org.apache.hadoop.hbase.regionserver.throttle.NoLimitThroughputController,可以修改为org.apache.hadoop.hbase.regionserver.throttle.PressureAwareFlushThroughputController,允许设置流量的界限。参考Compaction限流逻辑

    代码实现参考Compaction限流实现

    相关文章

      网友评论

        本文标题:HBase性能优化系列(一)

        本文链接:https://www.haomeiwen.com/subject/nuajmftx.html