正文
hbase怎么验证预分区,hbase 怎么根据rowkey 预分区
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
HBase性能优化-Rowkey&列族设计
必须在设计上保证RowKey的唯一性。由于在HBase中数据存储是Key-Value形式,若向HBase中同一张表插入相同RowKey的数据,则原先存在的数据会被新的数据覆盖。设计的RowKey应均匀的分布在各个HBase节点上,避免数据热点现象。
必须在设计上保证RowKey的唯一性。由于在HBase中数据存储是Key-Value形式,若向HBase中同一张表插入相同RowKey的数据,则原先存在的数据会被新的数据覆盖。设计的RowKey应均匀的分布在各个HBase节点上, 避免数据热点现象。
我这里只分了三个region,用hbase shell命令创建表,设置预分区数量为3 下图中,可以看到,预分区以后,数据的读写访问请求数量均匀分布在3台RegionServer上,避免了热点问题。
HBase的Rowkey是按照ASCII有序设计的,我们在设计Rowkey时要充分利用这点。比如视频网站上对影片《泰坦尼克号》的弹幕信息,这个弹幕是按照时间倒排序展示视频里,这个时候我们设计的Rowkey要和时间顺序相关。
hbase预分区与region切割的关系
默认,HBase 在创建表的时候,会自动为表分配一个 Region,正处于混沌时期,start-end key 无边界,所有 RowKey 都往这个 Region里分配。
虽然Region分裂后可以提高HBase的读写性能,但是Region分裂过程会对集群网络造成很大的压力,尤其是要分裂的Region尺寸过大、数目过多时,甚至可以使整个集群瘫痪。
整个region切分是一个比较复杂的过程,涉及子步骤,因此必须保证整个 Split 过程的事务性,即要么完全成功,要么完全未开始,在任何情况下也不能出现 Split 只完成一半的情况。
以fileServer为例,在使用默认的split策略--IncreasingToUpperBoundRegionSplitPolicy 的情况下,16个预分区Region, 则单个Resion容量达到 min(32,50),即32GB时分裂。
默认情况下,在创建HBase表的时候会自动创建一个region分区,当导入数据的时候,所有的HBase客户端都向这一个region写数据,直到这个region足够大了才进行切分。
如何hbase如何预先划分region
BusyRegionSplitPolicy (HBase-x Only))按照 RowKey 的前缀去拆分 Region,但是什么时候拆分,原 Region 容量的最大值是多少还是需要使用 IncreasingToUpperBoundRegionSplitPolicy 的方法去计算 。
HBase表的列族在创建之初只有一个Region,随着插入数据的增多Region变得越来越大。
一张表预分区N个,那就是一开始就设定了N个region;hbase.hregion.max.filesize 设定的region大小,超过了就会split,就会增加一个region,对预分区没什么影响。
一个表刚被创建的时候,Hbase 默认分配一个 Region 给表,所有的读写请求都会访问到一个 RegionServer 上的唯一一个 Region。
LSM-Tree模式的设计让hbase的写入性能非常良好,单次写入通常在1-3ms内即可响应完成,且性能不随数据量的增长而下降。region(相当于数据库的分表)可以ms级动态的切分和移动,保证了负载均衡性。
HBase调优:预分区与行键设计
1、像这样预先创建hbase表分区的方式,称之为预分区。hash(主键) + 年月日时(2019062315)这里只取hash(主键)的前6位,使得行键的长度正好是16,也就是8的整数倍,在64位计算机中,效果最好。
2、像这样预先创建hbase表分区的方式,称之为预分区。hash(主键)+年月日时(2019062315)这里只取hash(主键)的前6位,使得行键的长度正好是16,也就是8的整数倍,在64位计算机中,效果最好。
3、HBase 在创建表的时候,会自动为表分配一个Region,当一个 Region 达到拆分条件时(shouldSplit 为 true),HBase 中该 Region 将会进行 split,分裂为2个 Region,以此类推。
4、具体可以参考官方jira: https://issues.apache.org/jira/browse/HBASE-12848 该特性也是对WAL进行改造,当前WAL设计为一个RegionServer上所有Region共享一个WAL,可以想象在写入吞吐量较高的时候必然存在资源竞争,降低整体性能。
5、默认情况下,在创建HBase表的时候会自动创建一个region分区,当导入数据的时候,所有的HBase客户端都向这一个region写数据,直到这个region足够大了才进行切分。
6、目前我们已经确定了hbase存储,并且采用预分区的方式并且采用rowkey进行过滤查询,那么现在考虑rowkey的设计。
Hbase分区
partition 顾名思义就是分区式,这种分区有点类似于 mapreduce 中的 partitioner,将区域用长整数作为分区号,每个 Region 管理着相应的区域数据,在 RowKey 生成时,将 id 取模后,然后拼上 id 整体作为 RowKey 。
具体步骤如下:需要知道要查询的表名和分区的起始行键或结束行键。可以使用scan命令来扫描hbase:meta表,这个表存储了所有分区的元数据信息。可以使用PrefixFilter或RowFilter来过滤出要查询的分区的记录。
hbase.hregion.max.filesize 设定的region大小,超过了就会split,就会增加一个region,对预分区没什么影响。
rowkey的设计主要为了方便后期的查询(条件查询语句),如果设计的合理,查询速率可以大大提升 分区的设计,主要考量的是入库HBase的速率。如果设计的不合理,会导致局部入库数据过热,严重的有可能出现入库失败的情况。
hbase swap分区使用率根据相应信息分析系统状况的需要。在系统维护的过程中,随时可能有需要查看CPU使用率,并根据相应信息分析系统状况的需要。在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况。
默认情况下,在创建HBase表的时候会自动创建一个region分区,当导入数据的时候,所有的HBase客户端都向这一个region写数据,直到这个region足够大了才进行切分。
什么是hbase中的散列和预分区
HBase Table 的每个 Column family 维护一个 MemStore,当满足一定条件时 MemStore 会执行一次 flush,文件系统中生成新的 HFile。 而每次 Flush 的最小单位是 Region 。
rowkey的设计主要为了方便后期的查询(条件查询语句),如果设计的合理,查询速率可以大大提升 分区的设计,主要考量的是入库HBase的速率。如果设计的不合理,会导致局部入库数据过热,严重的有可能出现入库失败的情况。
我们都知道 HBase 的数据根据 rowkey 字典序排序的,理解这个概念很重要。根据 wiki 解释:通俗的理解,字典序是把字符左对齐,从 左到右比 大小的排序,一旦比出大小就停止比较后续的字符。
所有的HBase客户端都向这一个region写数据,直到这个region足够大了才进行切分。一种可以加快批量写入速度的方法是通过预先创建一些空的regions,这样当数据写入HBase时,会按照region分区情况,在集群内做数据的负载均衡。
可以使用Long.MAX_VALUE - 弹幕发表时间的 long 值作为 Rowkey 的前缀 散列 我们设计的Rowkey应均匀的分布在各个HBase节点上。
上一篇文章主要介绍了HBase读性能优化的基本套路,本篇文章来说道说道如何诊断HBase写数据的异常问题以及优化写性能。
关于hbase怎么验证预分区和hbase 怎么根据rowkey 预分区的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。