HBase 优化_1 | 学习笔记

简介: 快速学习 HBase 优化_1

开发者学堂课程【HBase 入门教程HBase 优化_1】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/397/detail/5093


HBase 优化_1


一、 Pre-Creating Regions

默认情况下,在创建 HBase 表的时候会自动创建-region 分区,当导入数据的时候,所有的 HBase 客户端都向这一个 region 写数据,直到这个 region 足够大了才进行切分。一种可以加快批量写入速度的方法是通过预先创建一些空的 regions ,这样当数据写入 HBase 时,会按照 region 分区情况,在集群内做数据的负载均衡。

public static boolean createTable(HBaseAdmin admin, HTableDescriptor table, byte[][]splits)

throws IOException {

try {

admin.createTable(table, splits);

return true;

} catch (TableExistsException e) {

logger.info("table " + table.getNameAsString() + " already exists");

// the table already exists...

return false;

}

}

有关预分区,详情参见:Table Creation: Pre-Creating Regions,下面是一个例子:

public static boolean createTable(HBaseAdmin admin,HTableDescriptor table,byte[][]splits)

throws IOException {

try {

admin.createTable(table, splits);

return true;

} catch (TableExistsException e) {

logger.info("table " + table.getNameAsString() + " already exists");

// the table already exists...

return false;

}

}

public static byte[][] getHexSplits(String startKey, String endKey, int numRegions) {

byte[][] splits = new byte[numRegions-1][];

BigInteger lowestKey = new BigInteger(startKey, 16);

BigInteger highestKey = new BigInteger(endKey, 16);

BigInteger range = highestKey.subtract(lowestKey);

BigInteger regionIncrement = range.divide(BigInteger.valueOf(numRegions));

lowestKey = lowestKey.add(regionIncrement);

for(int i=0; i < numRegions-1;i++) {

BigInteger key = lowestKey.add(regionIncrement.multiply(BigInteger.valueOf(i)));

byte[] b = String.format("%016x", key).getBytes();

splits[i] = b;

}

return splits;

}


二、Row Key

HBase row key 用来检索表中的记录,支持以下三种方式:

1. 通过单个 row key 访问:即按照某个 row key 键值进行 get 操作;

2. 通过 rowkey range 进行 scan:即通过设置 startRowKey endRowKey ,在这个范围内进行扫描;

3. 全表扫描:即直接扫描整张表中所有行记录。

HBase 中,row key 可以是任意字符串,最大长度64KB,实际应用中一般为10~100bytes,存为 byte[] 字节数组,一般设计成定长的。

row key 是按照字典序存储,因此,设计 row key 时,要充分利用这个排序特点,将经常一起读取的数据存储到一块,将最近可能会被访问的数据放在一块。

举个例子:如果最近写入 HBase 表中的数据是最可能被访问的,可以考虑将时间戳作为 row key 的一部分,由于是字典序排序,所以可以使用 Long.MAX_VALUE - timestamp 作为 row key ,这样能保证新写入的数据在读取时可以被快速命中。

相关文章
|
机器学习/深度学习 分布式计算 Hadoop
一种HBase表数据迁移方法的优化
一种HBase表数据迁移方法的优化
228 0
|
缓存 监控 Java
"Java垃圾回收太耗时?阿里HBase GC优化秘籍大公开,让你的应用性能飙升90%!"
【8月更文挑战第17天】阿里巴巴在HBase实践中成功将Java垃圾回收(GC)时间降低90%。通过选用G1垃圾回收器、精细调整JVM参数(如设置堆大小、目标停顿时间等)、优化代码减少内存分配(如使用对象池和缓存),并利用监控工具分析GC行为,有效缓解了高并发大数据场景下的性能瓶颈,极大提升了系统运行效率。
423 4
|
存储 前端开发 Cloud Native
基于 HBase 快速构架海量订单存储系统|学习笔记
快速学习基于 HBase 快速构架海量订单存储系统
基于 HBase 快速构架海量订单存储系统|学习笔记
|
存储 搜索推荐 Java
如何基于 HBase 构建图片、视频数据的统一存储检索方案|学习笔记
快速学习如何基于 HBase 构建图片、视频数据的统一存储检索方案
如何基于 HBase 构建图片、视频数据的统一存储检索方案|学习笔记
|
存储 SQL 消息中间件
Kylin 在贝壳的性能挑战和 HBase 优化实践(2)
Kylin 在贝壳的性能挑战和 HBase 优化实践
287 0
Kylin 在贝壳的性能挑战和 HBase 优化实践(2)
|
SQL 分布式计算 监控
Kylin 在贝壳的性能挑战和 HBase 优化实践(1)
Kylin 在贝壳的性能挑战和 HBase 优化实践
317 0
Kylin 在贝壳的性能挑战和 HBase 优化实践(1)
|
SQL 存储 边缘计算
HBase&Hive 2(三)|学习笔记
快速学习 HBase&Hive 2(三)
195 0
HBase&Hive 2(三)|学习笔记
|
SQL 存储 分布式计算
HBase&Hive 2(二)|学习笔记
快速学习 HBase&Hive 2(二)
152 0
HBase&Hive 2(二)|学习笔记
|
存储 SQL 分布式计算
HBase&Hive 2(一)|学习笔记
快速学习 HBase&Hive 2(一)
200 0
HBase&Hive 2(一)|学习笔记
|
存储 SQL 缓存
HBase&HIve 1|学习笔记
快速学习 HBase&HIve 1
345 0
HBase&HIve 1|学习笔记