<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=5">
    <title>剖析HBase负载均衡和性能指标详解大数据 | 云图网</title>
    <meta name="keywords" content="分布式文件系统，分布式数据库,并行处理（MPP）数据库，数据挖掘,开源大数据平台,数据中台,数据分析,数据开发,数据治理,数据湖,数据采集">
<meta name="description" content="1.概述 　　在分布式系统中，负载均衡是一个非常重要的功能，在HBase中通过Region的数量来实现负载均衡，HBase中可以通过hbase.master.loadbalancer.class来实现自定义负载均衡算法。下面将为大家剖析HBase负载均衡的相关内容以及性能指标。 2.内容 　　在HBase系统中，负载均…">
<meta property="og:type" content="article">
<meta property="og:url" content="https://blog.ytso.com/tech/bigdata/9875.html">
<meta property="og:site_name" content="云图网">
<meta property="og:title" content="剖析HBase负载均衡和性能指标详解大数据">
<meta property="og:image" content="http://blog.ytso.com/zb_users/plugin/LazyLoad/usr/loading.gif">
<meta property="og:description" content="1.概述 　　在分布式系统中，负载均衡是一个非常重要的功能，在HBase中通过Region的数量来实现负载均衡，HBase中可以通过hbase.master.loadbalancer.class来实现自定义负载均衡算法。下面将为大家剖析HBase负载均衡的相关内容以及性能指标。 2.内容 　　在HBase系统中，负载均…">
<link rel="canonical" href="https://blog.ytso.com/tech/bigdata/9875.html">
<meta name="applicable-device" content="pc,mobile">
<meta http-equiv="Cache-Control" content="no-transform">
<link rel="shortcut icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg">
<link rel='dns-prefetch' href='//cdnjs.cloudflare.com' />
<style id='wp-img-auto-sizes-contain-inline-css' type='text/css'>
img:is([sizes=auto i],[sizes^="auto," i]){contain-intrinsic-size:3000px 1500px}
/*# sourceURL=wp-img-auto-sizes-contain-inline-css */
</style>
<link rel='stylesheet' id='stylesheet-css' href='https://blog.ytso.com/wp-content/themes/justnews/css/style.css?ver=6.21.5' type='text/css' media='all' />
<link rel='stylesheet' id='material-icons-css' href='https://blog.ytso.com/wp-content/themes/justnews/themer/assets/css/material-icons.css?ver=6.21.5' type='text/css' media='all' />
<link rel='stylesheet' id='remixicon-css' href='https://cdnjs.cloudflare.com/ajax/libs/remixicon/4.2.0/remixicon.min.css?ver=6.9.4' type='text/css' media='all' />
<link rel='stylesheet' id='font-awesome-css' href='https://blog.ytso.com/wp-content/themes/justnews/themer/assets/css/font-awesome.css?ver=6.21.5' type='text/css' media='all' />
<style id='wp-block-library-inline-css' type='text/css'>
:root{--wp-block-synced-color:#7a00df;--wp-block-synced-color--rgb:122,0,223;--wp-bound-block-color:var(--wp-block-synced-color);--wp-editor-canvas-background:#ddd;--wp-admin-theme-color:#007cba;--wp-admin-theme-color--rgb:0,124,186;--wp-admin-theme-color-darker-10:#006ba1;--wp-admin-theme-color-darker-10--rgb:0,107,160.5;--wp-admin-theme-color-darker-20:#005a87;--wp-admin-theme-color-darker-20--rgb:0,90,135;--wp-admin-border-width-focus:2px}@media (min-resolution:192dpi){:root{--wp-admin-border-width-focus:1.5px}}.wp-element-button{cursor:pointer}:root .has-very-light-gray-background-color{background-color:#eee}:root .has-very-dark-gray-background-color{background-color:#313131}:root .has-very-light-gray-color{color:#eee}:root .has-very-dark-gray-color{color:#313131}:root .has-vivid-green-cyan-to-vivid-cyan-blue-gradient-background{background:linear-gradient(135deg,#00d084,#0693e3)}:root .has-purple-crush-gradient-background{background:linear-gradient(135deg,#34e2e4,#4721fb 50%,#ab1dfe)}:root .has-hazy-dawn-gradient-background{background:linear-gradient(135deg,#faaca8,#dad0ec)}:root .has-subdued-olive-gradient-background{background:linear-gradient(135deg,#fafae1,#67a671)}:root .has-atomic-cream-gradient-background{background:linear-gradient(135deg,#fdd79a,#004a59)}:root .has-nightshade-gradient-background{background:linear-gradient(135deg,#330968,#31cdcf)}:root .has-midnight-gradient-background{background:linear-gradient(135deg,#020381,#2874fc)}:root{--wp--preset--font-size--normal:16px;--wp--preset--font-size--huge:42px}.has-regular-font-size{font-size:1em}.has-larger-font-size{font-size:2.625em}.has-normal-font-size{font-size:var(--wp--preset--font-size--normal)}.has-huge-font-size{font-size:var(--wp--preset--font-size--huge)}.has-text-align-center{text-align:center}.has-text-align-left{text-align:left}.has-text-align-right{text-align:right}.has-fit-text{white-space:nowrap!important}#end-resizable-editor-section{display:none}.aligncenter{clear:both}.items-justified-left{justify-content:flex-start}.items-justified-center{justify-content:center}.items-justified-right{justify-content:flex-end}.items-justified-space-between{justify-content:space-between}.screen-reader-text{border:0;clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;word-wrap:normal!important}.screen-reader-text:focus{background-color:#ddd;clip-path:none;color:#444;display:block;font-size:1em;height:auto;left:5px;line-height:normal;padding:15px 23px 14px;text-decoration:none;top:5px;width:auto;z-index:100000}html :where(.has-border-color){border-style:solid}html :where([style*=border-top-color]){border-top-style:solid}html :where([style*=border-right-color]){border-right-style:solid}html :where([style*=border-bottom-color]){border-bottom-style:solid}html :where([style*=border-left-color]){border-left-style:solid}html :where([style*=border-width]){border-style:solid}html :where([style*=border-top-width]){border-top-style:solid}html :where([style*=border-right-width]){border-right-style:solid}html :where([style*=border-bottom-width]){border-bottom-style:solid}html :where([style*=border-left-width]){border-left-style:solid}html :where(img[class*=wp-image-]){height:auto;max-width:100%}:where(figure){margin:0 0 1em}html :where(.is-position-sticky){--wp-admin--admin-bar--position-offset:var(--wp-admin--admin-bar--height,0px)}@media screen and (max-width:600px){html :where(.is-position-sticky){--wp-admin--admin-bar--position-offset:0px}}
/*wp_block_styles_on_demand_placeholder:69c90313574cf*/
/*# sourceURL=wp-block-library-inline-css */
</style>
<style id='classic-theme-styles-inline-css' type='text/css'>
/*! This file is auto-generated */
.wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none}
/*# sourceURL=/wp-includes/css/classic-themes.min.css */
</style>
<link rel='stylesheet' id='wpcom-member-css' href='https://blog.ytso.com/wp-content/plugins/wpcom-member/css/style.css?ver=1.7.19' type='text/css' media='all' />
<script type="text/javascript" src="https://blog.ytso.com/wp-includes/js/jquery/jquery.min.js?ver=3.7.1" id="jquery-core-js"></script>
<script type="text/javascript" src="https://blog.ytso.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=3.4.1" id="jquery-migrate-js"></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://blog.ytso.com/xmlrpc.php?rsd" />
<meta name='description' content='1.概述 　　在分布式系统中，负载均衡是一个非常重要的功能，在HBase中通过Region的数量来实现负载均衡，HBase中可以通过hbase.master.loadbalancer.class来实现自定义负载均衡算法。下面将为大家剖析HBase负载均衡…' />
<meta name='keywords' content='分布式文件系统，分布式数据库,并行处理（MPP）数据库，数据挖掘,开源大数据平台,数据中台,数据分析,数据开发,数据治理,数据湖,数据采集' />
<style>:root{--theme-color: #08c; --theme-hover: #07c; --logo-height: 32px; --logo-height-mobile: 26px; --menu-item-gap: 28px; --member-login-bg: url('https://blog.ytso.com/loginwall.jpg'); --header-bg-color: #fff; --header-bg-image: none; --theme-border-radius-s: 3px; --theme-border-radius-m: 5px; --theme-border-radius-l: 8px; --theme-border-radius-xl: 12px; --thumb-ratio-default: 480 / 300; --thumb-ratio-post: 480 / 300; --post-video-ratio: 860 / 482;}</style>
<link rel="icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" sizes="32x32" />
<link rel="icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" sizes="192x192" />
<link rel="apple-touch-icon" href="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" />
<meta name="msapplication-TileImage" content="https://imgcdn.ytso.com/wp-content/uploads/2024/10/20241015181503433.jpg" />
    <!--[if lte IE 11]><script src="https://blog.ytso.com/wp-content/themes/justnews/js/update.js"></script><![endif]-->
</head>
<body class="wp-singular post-template-default single single-post postid-9875 single-format-standard wp-theme-justnews lang-cn el-boxed header-fixed">
<header class="header header-fluid">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse" aria-label="menu">
                <span class="icon-bar icon-bar-1"></span>
                <span class="icon-bar icon-bar-2"></span>
                <span class="icon-bar icon-bar-3"></span>
            </button>
                        <div class="logo">
                <a href="https://blog.ytso.com/" rel="home">
                    <img src="https://imgcdn.ytso.com/wp-content/uploads/2021/12/20211207181156143.png" alt="云图网">
                </a>
            </div>
        </div>
        <div class="collapse navbar-collapse mobile-style-0">
            <nav class="primary-menu"><ul id="menu-justnews-footer-menu" class="nav navbar-nav wpcom-adv-menu"><li class="menu-item"><a href="https://blog.ytso.com/category/industrynews">业界资讯</a></li>
<li class="menu-item current-post-ancestor active menu-item-style menu-item-style-1 dropdown"><a target="_blank" href="https://blog.ytso.com/category/tech" class="dropdown-toggle">技术专区</a>
<ul class="dropdown-menu menu-item-wrap menu-item-col-5">
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/cloud">云计算</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/ai">人工智能</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/safety">信息安全</a></li>
	<li class="menu-item current-post-ancestor current-post-parent active"><a href="https://blog.ytso.com/category/tech/bigdata">大数据</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/dev">研发管理</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/webdev">大前端</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/opensource">开源</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/aiops">智能运维</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/pnotes">编程笔记</a></li>
	<li class="menu-item"><a href="https://blog.ytso.com/category/tech/wp">WordPress</a></li>
</ul>
</li>
<li class="menu-item"><a href="https://blog.ytso.com/category/enterprise-strategic-planning">企业战略规划</a></li>
<li class="menu-item"><a href="https://blog.ytso.com/category/download">下载专区</a></li>
<li class="menu-item"><a href="https://blog.ytso.com/category/it%e6%b1%9f%e6%b9%96%e5%8f%b2">江湖史</a></li>
<li class="menu-item"><a href="https://blog.ytso.com/category/notes">随笔记录</a></li>
</ul></nav>            <div class="navbar-action">
                <div class="navbar-search-icon j-navbar-search"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-search"></use></svg></i></div><form class="navbar-search" action="https://blog.ytso.com/" method="get" role="search"><div class="navbar-search-inner"><i class="wpcom-icon wi navbar-search-close"><svg aria-hidden="true"><use xlink:href="#wi-close"></use></svg></i><input type="text" name="s" class="navbar-search-input" autocomplete="off" maxlength="100" placeholder="输入关键词搜索..." value=""><button class="navbar-search-btn" type="submit" aria-label="搜索"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-search"></use></svg></i></button></div></form>                    <div id="j-user-wrap">
                        <a class="login" href="https://blog.ytso.com/login">登录</a>
                        <a class="login register" href="https://blog.ytso.com/register">注册</a>
                    </div>
                                            <a class="wpcom-btn btn-primary btn-xs publish" href="https://blog.ytso.com/contribute">
                            <i class="fa fa-edit"></i> 投稿                        </a>
                                </div>
        </div>
    </div><!-- /.container -->
</header>

<div id="wrap">    <div class="wrap container">
        <ol class="breadcrumb" vocab="https://schema.org/" typeof="BreadcrumbList"><li class="home" property="itemListElement" typeof="ListItem"><a href="https://blog.ytso.com" property="item" typeof="WebPage"><span property="name" class="hide">云图网</span>首页</a><meta property="position" content="1"></li><li property="itemListElement" typeof="ListItem"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-right-3"></use></svg></i><a href="https://blog.ytso.com/category/tech" property="item" typeof="WebPage"><span property="name">技术专区</span></a><meta property="position" content="2"></li><li property="itemListElement" typeof="ListItem"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-right-3"></use></svg></i><a href="https://blog.ytso.com/category/tech/bigdata" property="item" typeof="WebPage"><span property="name">大数据</span></a><meta property="position" content="3"></li></ol>        <main class="main">
                            <article id="post-9875" class="post-9875 post type-post status-publish format-standard hentry category-bigdata tag-117 tag-mpp tag-121 tag-125 tag-119 tag-120 tag-123 tag-124 tag-122 entry">
                    <div class="entry-main">
                                                                        <div class="entry-head">
                            <h1 class="entry-title">剖析HBase负载均衡和性能指标详解大数据</h1>
                            <div class="entry-info">
                                                                <time class="entry-date published" datetime="2021-07-19T11:37:53+08:00" pubdate>
                                    2021年7月19日 11:37                                </time>
                                <span class="dot">•</span>
                                <a href="https://blog.ytso.com/category/tech/bigdata" rel="category tag">大数据</a>                                                            </div>
                        </div>
                        
                                                <div class="entry-content text-indent text-justify">
                            <div id="toc">
<p class="toc-title"><strong>文章目录</strong><span class="toc-controller toc-controller-show">[隐藏]</span></p>
<ul>
<li class="toc-level1"><a href="#toc_1">1.概述</a></li>
<li class="toc-level1"><a href="#toc_2">2.内容</a>
<ul>
<li class="toc-level2"><a href="#toc_3">2.1 负载均衡算法</a></li>
<li class="toc-level2"><a href="#toc_4">2.2 实例分析</a></li>
</ul>
</li>
<li class="toc-level1"><a href="#toc_5">3.性能指标</a></li>
<li class="toc-level1"><a href="#toc_6">4.总结</a></li>
<li class="toc-level1"><a href="#toc_7">5.结束语&nbsp;</a></li>
</ul>
</div>
<h1 id="toc_1">1.概述</h1>
<p>　　在分布式系统中，负载均衡是一个非常重要的功能，在HBase中通过Region的数量来实现负载均衡，HBase中可以通过hbase.master.loadbalancer.class来实现自定义负载均衡算法。下面将为大家剖析HBase负载均衡的相关内容以及性能指标。</p>
<h1 id="toc_2">2.内容</h1>
<p>　　在HBase系统中，负载均衡是一个周期性的操作，通过负载均衡来均匀分配Region到各个RegionServer上，通过hbase.balancer.period属性来控制负载均衡的时间间隔，默认是5分钟。触发负载均衡操作是有条件的，但是如果发生如下情况，则不会触发负载均衡操作：</p>
<ul>
<li>负载均衡自动操作balance_switch关闭，即：balance_switch false</li>
<li>HBase Master节点正在初始化操作</li>
<li>HBase集群中正在执行RIT，即Region正在迁移中</li>
<li>HBase集群正在处理离线的RegionServer</li>
</ul>
<h2 id="toc_3">2.1 负载均衡算法</h2>
<p>　　HBase在执行负载均衡操作时，如何判断各个RegionServer节点上的Region个数是否均衡，这里通过以下步骤来判断：</p>
<ol>
<li>计算均衡值的区间范围，通过总Region个数以及RegionServer节点个数，算出平均Region个数，然后在此基础上计算最小值和最大值</li>
<li>遍历超过Region最大值的RegionServer节点，将该节点上的Region值迁移出去，直到该节点的Region个数小于等于最大值的Region</li>
<li>遍历低于Region最小值的RegionServer节点，分配集群中的Region到这些RegionServer上，直到大于等于最小值的Region</li>
<li>负责上述操作，直到集群中所有的RegionServer上的Region个数在最小值与最大值之间，集群才算到达负载均衡，之后，即使再次手动执行均衡命令，HBase底层逻辑判断会执行忽略操作</li>
</ol>
<h2 id="toc_4">2.2 实例分析</h2>
<p>　　下面笔者通过一个实际的应用场景来给大家剖析HBase负载均衡算法的实现流程。举个例子，假如我们当前有一个5台节点规模的HBase集群（包含Master和RegionServer），其中2台Master和3台RegionServer组成，每台RegionServer上的Region个数，如下图所示。</p>
<p>　　<noscript><img decoding="async" src="http://blog.ytso.com/zb_users/plugin/LazyLoad/usr/loading.gif" data-original="/img/f072663f-0ad9-450f-94e6-059850e2ee72.png" alt="剖析HBase负载均衡和性能指标详解大数据"></noscript><img decoding="async" class="j-lazy" src="https://blog.ytso.com/wp-content/themes/justnews/themer/assets/images/lazy.png" data-original="http://blog.ytso.com/zb_users/plugin/LazyLoad/usr/loading.gif" data-original="/img/f072663f-0ad9-450f-94e6-059850e2ee72.png" alt="剖析HBase负载均衡和性能指标详解大数据"></p>
<p>　　在执行负载均衡操作之前，会计算集群中总的Region个数，当前实例中集群中的Region总个数为175+56+99=330。然后计算每个RegionServer需要容纳的Region平均值。计算结果如下：</p>
<div class="cnblogs_code">
<pre class="prism-language-java">平均值(<span style="color: rgba(128, 0, 128, 1)">110</span>) = 总Region个数(<span style="color: rgba(128, 0, 128, 1)">330</span>) / RegionServers总数(<span style="color: rgba(128, 0, 128, 1)">3</span>)</pre>
</div>
<p>　　计算最小值和最大值来判断HBase集群是否需要进行负载均衡操作，计算公式如下：</p>
<div class="cnblogs_code">
<pre class="prism-language-java"># hbase.regions.slop 权重值，默认为0.<span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)"> 
最小值 </span>= Math.floor(平均值 * (<span style="color: rgba(128, 0, 128, 1)">1</span>-<span style="color: rgba(128, 0, 128, 1)">0.2</span><span style="color: rgba(0, 0, 0, 1)">)) 
最大值 </span>= Math.ceil(平均值 * (<span style="color: rgba(128, 0, 128, 1)">1</span>+<span style="color: rgba(128, 0, 128, 1)">0.2</span>))</pre>
</div>
<p>　　HBase集群如果判断各个RegionServer中的最小Region个数大于计算后的最小值，并且最大Region个数小于最大值，这是直接返回不会触发负载均衡操作。根据实例中给出的Region数，计算得出最小值Region为88，最大值Region为132。</p>
<p>　　由于实例中RegionServer2的Region个数为56，小于最小值Region数88，而RegionServer1的Region个数为175，大于了最大值Region数132，所以需要负载均衡操作。</p>
<p>　　HBase系统有提供管理员命令，来操作负载均衡，具体操作如下：</p>
<div class="cnblogs_code">
<pre class="prism-language-java"><span style="color: rgba(0, 0, 0, 1)"># 使用hbase shell命令进入到HBase控制台，然后开启自动执行负载均衡 
hbase(main):</span><span style="color: rgba(128, 0, 128, 1)">001</span>:<span style="color: rgba(128, 0, 128, 1)">0</span>&gt; balance_switch <span style="color: rgba(0, 0, 255, 1)">true</span></pre>
</div>
<p>　　这样HBase负载均衡自动操作就开启了，但是，如果我们需要立即均衡集群中的Region个数怎么办？这里HBase也提供了管理命令，通过balancer命令来实现，操作如下：</p>
<div class="cnblogs_code">
<pre class="prism-language-java">hbase(main):<span style="color: rgba(128, 0, 128, 1)">001</span>:<span style="color: rgba(128, 0, 128, 1)">0</span>&gt; balancer</pre>
</div>
<p>　　但是，这样每次手动执行，每次均衡的个数不一定能满足要求，那么我们可以通过封装该命令，用脚本来调度执行，具体实现代码如下：</p>
<div class="cnblogs_code">
<pre class="prism-language-java">#! /bin/<span style="color: rgba(0, 0, 0, 1)">bash 
 
num</span>=$<span style="color: rgba(128, 0, 128, 1)">1</span> 
 
<span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">[`date </span><span style="color: rgba(128, 0, 0, 1)">"</span>+%Y-%m-%d %H:%M:%S<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">`] INFO : RegionServer Start Balancer...</span><span style="color: rgba(128, 0, 0, 1)">"</span> 
<span style="color: rgba(0, 0, 255, 1)">if</span> [ ! -n <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">$num</span><span style="color: rgba(128, 0, 0, 1)">"</span> ]; <span style="color: rgba(0, 0, 255, 1)">then</span> 
    <span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">[`date </span><span style="color: rgba(128, 0, 0, 1)">"</span>+%Y-%m-%d %H:%M:%S<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">`] INFO : Default Balancer 20 Times.</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> 
    num</span>=<span style="color: rgba(128, 0, 128, 1)">20</span> 
<span style="color: rgba(0, 0, 255, 1)">elif</span> [[ $num == *[!<span style="color: rgba(128, 0, 128, 1)">0</span>-<span style="color: rgba(128, 0, 128, 1)">9</span>]* ]]; <span style="color: rgba(0, 0, 255, 1)">then</span> 
    <span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">[`date </span><span style="color: rgba(128, 0, 0, 1)">"</span>+%Y-%m-%d %H:%M:%S<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">`] INFO : Input [$num] Times Must Be Number.</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> 
    exit </span><span style="color: rgba(128, 0, 128, 1)">1</span> 
<span style="color: rgba(0, 0, 255, 1)">else</span> 
    <span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">[`date </span><span style="color: rgba(128, 0, 0, 1)">"</span>+%Y-%m-%d %H:%M:%S<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">`] INFO : User-Defined Balancer [$num] Times.</span><span style="color: rgba(128, 0, 0, 1)">"</span> 
<span style="color: rgba(0, 0, 255, 1)">fi</span> 
 
<span style="color: rgba(0, 0, 255, 1)">for</span> (( i=<span style="color: rgba(128, 0, 128, 1)">1</span>; i&lt;=$num; i++<span style="color: rgba(0, 0, 0, 1)"> )) 
</span><span style="color: rgba(0, 0, 255, 1)">do</span> 
    <span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">[`date </span><span style="color: rgba(128, 0, 0, 1)">"</span>+%Y-%m-%d %H:%M:%S<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">`] INFO : Balancer [$i] Times,Total [$num] Times.</span><span style="color: rgba(128, 0, 0, 1)">"</span> 
    <span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">balancer</span><span style="color: rgba(128, 0, 0, 1)">"</span>|<span style="color: rgba(0, 0, 0, 1)">hbase shell 
    </span><span style="color: rgba(0, 0, 255, 1)">sleep</span> <span style="color: rgba(128, 0, 128, 1)">5</span> 
<span style="color: rgba(0, 0, 255, 1)">done</span></pre>
</div>
<p>　　脚本默认执行20次，可以通过输入一个整型参数来自定义执行次数。</p>
<p>　　当HBase集群检查完所有的RegionServer上的Region个数已打要求，那么此时集群的负载均衡操作就已经完成了。如果没有达到要求，可以再次执行上述脚本，直到所有的Region个数在最小值和最大值之间为止。当HBase集群中所有的RegionServer完成负载均衡后，实例中的各个RegionServer上的Region个数分布，如下图所示。</p>
<p><noscript><img decoding="async" src="http://blog.ytso.com/zb_users/plugin/LazyLoad/usr/loading.gif" data-original="/img/71360d17-61f3-4cf2-9874-779b7ee19d23.png" alt="剖析HBase负载均衡和性能指标详解大数据"></noscript><img decoding="async" class="j-lazy" src="https://blog.ytso.com/wp-content/themes/justnews/themer/assets/images/lazy.png" data-original="http://blog.ytso.com/zb_users/plugin/LazyLoad/usr/loading.gif" data-original="/img/71360d17-61f3-4cf2-9874-779b7ee19d23.png" alt="剖析HBase负载均衡和性能指标详解大数据"></p>
<p>　　此时，各个RegionServer节点上的Region个数均在最小值和最大值范围内，HBase集群各个RegionServer节点上的Region处理均衡状态。</p>
<h1 id="toc_5">3.性能指标</h1>
<p>　　在HBase系统中，有一个非常重要的性能指标，那就是集群处理请求的延时。HBase系统为了反应集群内部处理请求所耗费的时间，提供了一个工具类，即：org.apache.hadoop.hbase.tool.Canary，这个类主要用户检查HBase系统的耗时状态。如果不知道使用方法，可以通过help命令来查看具体的用法，命令如下：</p>
<div class="cnblogs_code">
<pre class="prism-language-java">hbase org.apache.hadoop.hbase.tool.Canary -help</pre>
</div>
<p>（1）查看集群中每个表中每个Region的耗时情况</p>
<div class="cnblogs_code">
<pre class="prism-language-java">hbase org.apache.hadoop.hbase.tool.Canary</pre>
</div>
<p>（2）查看money表中每个Region的耗时情况，多个表之间使用空格分割</p>
<div class="cnblogs_code">
<pre class="prism-language-java"><span style="color: rgba(0, 0, 0, 1)"># 查看money表和person表 
hbase org.apache.hadoop.hbase.tool.Canary money person</span></pre>
</div>
<p>（3）查看每个RegionServer的耗时情况</p>
<div class="cnblogs_code">
<pre class="prism-language-java">hbase org.apache.hadoop.hbase.tool.Canary -regionserver dn1</pre>
</div>
<p>　　通常情况下，我们比较关注每个RegionServer节点的耗时情况，将该命令封装一下，然后打印集群中每个RegionServer的耗时情况，脚本实现如下所示：</p>
<div class="cnblogs_code">
<pre class="prism-language-java"><span style="color: rgba(0, 0, 0, 1)">######################################################### 
# 将捕获的RS耗时，写入到InfluxDB中进行存储，用于绘制历史趋势图 
######################################################### 
#</span>!/bin/<span style="color: rgba(0, 0, 0, 1)">bash 
  
post_influxdb_write</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">http://influxdb:8086/write?db=telegraf_rs</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> 
 
source </span>/home/hadoop/<span style="color: rgba(0, 0, 0, 1)">.bash_profile 
  
</span><span style="color: rgba(0, 0, 255, 1)">for</span> i <span style="color: rgba(0, 0, 255, 1)">in</span> `<span style="color: rgba(0, 0, 255, 1)">cat</span><span style="color: rgba(0, 0, 0, 1)"> rs.list` 
    </span><span style="color: rgba(0, 0, 255, 1)">do</span><span style="color: rgba(0, 0, 0, 1)"> 
        timespanStr</span>=`(hbase org.apache.hadoop.hbase.tool.Canary -regionserver $i <span style="color: rgba(128, 0, 128, 1)">2</span>&gt;&amp;<span style="color: rgba(128, 0, 128, 1)">1</span>) | <span style="color: rgba(0, 0, 255, 1)">grep</span><span style="color: rgba(0, 0, 0, 1)"> tool.Canary` 
        timespanMs</span>=`<span style="color: rgba(0, 0, 255, 1)">echo</span> $timespanStr|<span style="color: rgba(0, 0, 255, 1)">awk</span> -F <span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">{print $NF}</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">` 
        timespan</span>=`<span style="color: rgba(0, 0, 255, 1)">echo</span> $timespanMs|<span style="color: rgba(0, 0, 255, 1)">awk</span> -F <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">ms</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">{print $1}</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">` 
        </span><span style="color: rgba(0, 0, 255, 1)">echo</span> `<span style="color: rgba(0, 0, 255, 1)">date</span> +<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">%Y-%m-%d %H:%M:%S</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">` INFO : RegionServer $i delay $timespanMs . 
        currentTime</span>=`<span style="color: rgba(0, 0, 255, 1)">date</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">+%Y-%m-%d %H:%M:%S</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">` 
        currentTimeStamp</span>=`<span style="color: rgba(0, 0, 255, 1)">date</span> -d <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">$currentTime</span><span style="color: rgba(128, 0, 0, 1)">"</span> +%<span style="color: rgba(0, 0, 0, 1)">s` 
        insert_sql</span>=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">regionsever,host=$i value=$timespan ${currentTimeStamp}000000000</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> 
        #</span><span style="color: rgba(0, 0, 255, 1)">echo</span><span style="color: rgba(0, 0, 0, 1)"> $insert_sql 
        curl </span>-i -X POST <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">$post_influxdb_write</span><span style="color: rgba(128, 0, 0, 1)">"</span> --data-binary <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">$insert_sql</span><span style="color: rgba(128, 0, 0, 1)">"</span> 
    <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">  
exit</span></pre>
</div>
<h1 id="toc_6">4.总结</h1>
<p>　　在维护HBase集群时，比如重启某几个RegionServer节点后，可能会发送Region不均衡的情况，这时如果开启自动均衡后，需要立即使当前集群上其他RegionServer上的Region处于均衡状态，那么就可以使用手动均衡操作。另外，HBase集群中各个RegionServer的耗时情况，能够反映当前集群的健康状态。</p>
<h1 id="toc_7">5.结束语&nbsp;</h1>
<p>　　这篇博客就和大家分享到这里，如果大家在研究学习的过程当中有什么问题，可以加群进行讨论或发送邮件给我，我会尽我所能为您解答，与君共勉！</p>
<p>　　另外，博主出书了《Hadoop大数据挖掘从入门到进阶实战》，喜欢的朋友或同学，&nbsp;可以在公告栏那里点击购买链接购买博主的书进行学习，在此感谢大家的支持。</p>
<p></p>
<div class="entry-readmore"><div class="entry-readmore-btn"></div></div>                                                        <div class="entry-copyright"><p>原创文章，作者：Maggie-Hunter，如若转载，请注明出处：https://blog.ytso.com/tech/bigdata/9875.html</p></div>                        </div>

                        <div class="entry-tag"><a href="https://blog.ytso.com/tag/%e5%88%86%e5%b8%83%e5%bc%8f%e6%96%87%e4%bb%b6%e7%b3%bb%e7%bb%9f%ef%bc%8c%e5%88%86%e5%b8%83%e5%bc%8f%e6%95%b0%e6%8d%ae%e5%ba%93" rel="tag">分布式文件系统，分布式数据库</a><a href="https://blog.ytso.com/tag/%e5%b9%b6%e8%a1%8c%e5%a4%84%e7%90%86%ef%bc%88mpp%ef%bc%89%e6%95%b0%e6%8d%ae%e5%ba%93%ef%bc%8c%e6%95%b0%e6%8d%ae%e6%8c%96%e6%8e%98" rel="tag">并行处理（MPP）数据库，数据挖掘</a><a href="https://blog.ytso.com/tag/%e5%bc%80%e6%ba%90%e5%a4%a7%e6%95%b0%e6%8d%ae%e5%b9%b3%e5%8f%b0" rel="tag">开源大数据平台</a><a href="https://blog.ytso.com/tag/%e6%95%b0%e6%8d%ae%e4%b8%ad%e5%8f%b0" rel="tag">数据中台</a><a href="https://blog.ytso.com/tag/%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90" rel="tag">数据分析</a><a href="https://blog.ytso.com/tag/%e6%95%b0%e6%8d%ae%e5%bc%80%e5%8f%91" rel="tag">数据开发</a><a href="https://blog.ytso.com/tag/%e6%95%b0%e6%8d%ae%e6%b2%bb%e7%90%86" rel="tag">数据治理</a><a href="https://blog.ytso.com/tag/%e6%95%b0%e6%8d%ae%e6%b9%96" rel="tag">数据湖</a><a href="https://blog.ytso.com/tag/%e6%95%b0%e6%8d%ae%e9%87%87%e9%9b%86" rel="tag">数据采集</a></div>
                        <div class="entry-action">
                            <div class="btn-zan" data-id="9875"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-thumb-up-fill"></use></svg></i> 赞 <span class="entry-action-num">(0)</span></div>
                                                    </div>

                        <div class="entry-bar">
                            <div class="entry-bar-inner">
                                                                <div class="entry-bar-info entry-bar-info2">
                                    <div class="info-item meta">
                                                                                    <a class="meta-item j-heart" href="javascript:;" data-id="9875"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-star"></use></svg></i> <span class="data">0</span></a>                                        <a class="meta-item" href="#comments"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-comment"></use></svg></i> <span class="data">0</span></a>                                                                            </div>
                                    <div class="info-item share">
                                                                                    <a class="meta-item mobile j-mobile-share" href="javascript:;" data-id="9875" data-qrcode="https://blog.ytso.com/tech/bigdata/9875.html">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-share"></use></svg></i> 生成海报                                            </a>
                                                                                    <a class="meta-item wechat" data-share="wechat" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-wechat"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item weibo" data-share="weibo" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-weibo"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item qq" data-share="qq" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-qq"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item qzone" data-share="qzone" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-qzone"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item douban" data-share="douban" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-douban"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item linkedin" data-share="linkedin" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-linkedin"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item facebook" data-share="facebook" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-facebook"></use></svg></i>                                            </a>
                                                                                    <a class="meta-item twitter" data-share="twitter" target="_blank" rel="nofollow noopener noreferrer" href="#">
                                                <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-twitter"></use></svg></i>                                            </a>
                                                                            </div>
                                    <div class="info-item act">
                                        <a href="javascript:;" id="j-reading"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-article"></use></svg></i></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                                            <div class="entry-page">
                    <div class="entry-page-prev j-lazy" style="background-image: url('https://blog.ytso.com/wp-content/themes/justnews/themer/assets/images/lazy.png');" data-original="http://blog.ytso.com/zb_users/plugin/LazyLoad/usr/loading.gif">
                <a href="https://blog.ytso.com/tech/bigdata/9874.html" title="Kafka监控系统Kafka Eagle剖析详解大数据" rel="prev">
                    <span>Kafka监控系统Kafka Eagle剖析详解大数据</span>
                </a>
                <div class="entry-page-info">
                    <span class="pull-left"><i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-left-double"></use></svg></i> 上一篇</span>
                    <span class="pull-right">2021年7月19日 11:37</span>
                </div>
            </div>
                            <div class="entry-page-next j-lazy" style="background-image: url('https://blog.ytso.com/wp-content/themes/justnews/themer/assets/images/lazy.png');" data-original="http://blog.ytso.com/zb_users/plugin/LazyLoad/usr/loading.gif">
                <a href="https://blog.ytso.com/tech/bigdata/9876.html" title="Hadoop大数据挖掘从入门到进阶实战详解大数据" rel="next">
                    <span>Hadoop大数据挖掘从入门到进阶实战详解大数据</span>
                </a>
                <div class="entry-page-info">
                    <span class="pull-right">下一篇 <i class="wpcom-icon wi"><svg aria-hidden="true"><use xlink:href="#wi-arrow-right-double"></use></svg></i></span>
                    <span class="pull-left">2021年7月19日 11:37</span>
                </div>
            </div>
            </div>
                                        <error>
    <code>wp_die</code>
    <title><![CDATA[WordPress &amp;rsaquo; Error]]></title>
    <message><![CDATA[&lt;h1&gt;Error establishing a Redis connection&lt;/h1&gt;
&lt;p&gt;To disable Redis, delete the &lt;code&gt;object-cache.php&lt;/code&gt; file in the &lt;code&gt;/wp-content/&lt;/code&gt; directory.&lt;/p&gt;
]]></message>
    <data>
        <status>500</status>
    </data>
</error>
<!--
Performance optimized by Redis Object Cache. Learn more: https://wprediscache.com

Retrieved 1866 objects (699 KB) from Redis using Predis (v2.4.0).
-->
