hbase优化实践

简介: hbase优化一:垃圾回收优化 :region服务器处理过大的负载,内存分配策略无法安全地只依赖JRE对程序的行为的各种假设,需要使用JRE提供的选项调整垃圾回收策略应对。

hbase优化

一:垃圾回收优化 :

region服务器处理过大的负载,内存分配策略无法安全地只依赖JRE对程序的行为的各种假设,需要使用JRE提供的选项调整垃圾回收策略应对。

写入磁盘的数据客户端不连续,导致Java虚拟机堆内存出现空洞。

年轻代空间:128~512M之间 老生代:好几G。

配置文件添加:

hbase-env.sh:

HBASEOPTS或者HBASEREGIONSERVER_OPT(推荐) 推荐配置:

exportHBASE_REGIONOBSERVER_OPTS="

-Xmx8g  \

-Xms8g  \

-Xmn128m\

-XX:+UseParNewGC\

-XX:+UseConcMarkSweepGC \

-XX:CMSInitiatingOccupancyFraction=70  \

-verbose:gc \

-XX:+PrintGCDetails\

-XX:+PrintGCTimeStamps  \

-Xloggc:$HBASE_HOME/logs/gc-${HOSTNAME}-hbase.log"

参照:

http://blog.csdn.net/kthq/article/details/8618052

http://swcdxd.iteye.com/blog/1859858

二:hbase压缩

可用编码器:GZIP/LZO/Snappy

Snappy性能稍好,多使用Snappy

hbase启动检查压缩:

hbase.regionserver.codecs

snappy,lzo

启用压缩:

hbase> create 'test2', { NAME => 'cf2', COMPRESSION => 'SNAPPY' }

hbase> describe 'test'

DESCRIPTION  ENABLED

'test', {NAME => 'cf', DATA_BLOCK_ENCODING => 'NONE  false

', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0',

VERSIONS => '1', COMPRESSION => 'GZ', MIN_VERSIONS

=> '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'fa

lse', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}

1 row(s) in 0.1070 seconds

或者:hbase> disable 'test'

hbase> alter 'test', {NAME => 'cf', COMPRESSION => 'GZ'}

hbase> enable 'test'

三:优化拆分与合并

3.1管理拆分

hbase可能出现‘拆分/合并风暴’

关闭自动管理拆分,启用手动

To disable automatic splitting, set hbase.hregion.max.filesize to a very large value,

such as 100 GB It is not recommended to set it to its absolute maximum value of Long.MAX_VALUE.

3.2 region热点问题

/rowkey的设计一:salting前缀设计/

byte prefix = (byte) (Long.hashCode(System.currentTimeMillis()) % 8);

byte[] rowkey1 = Bytes.add(Bytes.toBytes(prefix), Bytes.toBytes(System.currentTimeMillis()));

/rowkey的设计二:字段交换,提升权重/

value + System.currentTimeMillis();

/rowkey的设计三:随机化/

MessageDigest md = MessageDigest.getInstance("MD5");

byte[] rowkey3 = md.digest(Bytes.toBytes(System.currentTimeMillis()));

/rowkey的设计四:时间顺序/

long rowkey4 = Long.MAX_VALUE - System.currentTimeMillis();

还可以使用API中move()region移动到另一个regionserver;或者UNassign移除受影响的表的region

3.3预拆分region

创建表指定需要的region数目

hbase>create 't1','f',SPLITS => ['10','20',30']

hbase>create 't14','f',SPLITS_FILE=>'splits.txt'

# create table with four regions based on random bytes keys

hbase>create 't2','f1', { NUMREGIONS => 4 , SPLITALGO => 'UniformSplit' }

# create table with five regions based on hex keys

hbase>create 't3','f1', { NUMREGIONS => 5, SPLITALGO => 'HexStringSplit' }

参考:http://hbase.apache.org/book.html#compression

四:负载均衡:

Use the shell to disable the balancer:

hbase(main):001:0> balance_switch false

true

0 row(s) in 0.3590 seconds

This turns the balancer OFF. To reenable, do:

hbase(main):001:0> balance_switch true

false

0 row(s) in 0.3590 seconds

五:合并region:

某些特出情况下,用户需要合并region(删除了大量数据)

$ bin/hbase org.apache.hadoop.hbase.util.Merge

(If you feel you have too many regions and want to consolidate them, Merge is the utility you need.

Merge must run be done when the cluster is down)

六:客户端api优化:

6.1禁止自动刷写

有大量的写入操作

When performing a lot of Puts, make sure that setAutoFlush is set to false on your Table instance.

Otherwise, the Puts will be sent one at a time to the RegionServer.

Puts added via table.add(Put) and table.add( Put) wind up in the same write buffer.

If autoFlush = false, these messages are not sent until the write-buffer is filled.

To explicitly flush the messages, call flushCommits.

Calling close on the Table instance will invoke flushCommits.

6.2使用扫描缓存

比如:hbase作为mapreduce输入源。

设置setCaching比默认值大多的值。

If HBase is used as an input source for a MapReduce job,

for example, make sure that the input Scan instance to the MapReduce job has setCaching set to something greater than the default (which is 1).

Using the default value means that the map-task will make call back to the region-server for every record processed.

Setting this value to 500, for example, will transfer 500 rows at a time to the client to be processed

6.3限定扫描范围

6.4关闭resultScanner

七:配置优化;

7.1减少zookeeper超时

zookeeper.session.timeout

默认三分钟

7.2增加regionserver处理线程

hbase.regionserver.handler.count

默认10

7.3增加region大小

管理较少的region可以集群运行更平稳

默认256M

7.4减少最大日志文件数目

对于写压力比较大的应用,降低值强迫服务器频繁将数据写到磁盘,刷写到磁盘的数据的日志就可以丢弃了。

7.5启用数据压缩

相关实践学习
云数据库HBase版使用教程
  相关的阿里云产品:云数据库 HBase 版 面向大数据领域的一站式NoSQL服务,100%兼容开源HBase并深度扩展,支持海量数据下的实时存储、高并发吞吐、轻SQL分析、全文检索、时序时空查询等能力,是风控、推荐、广告、物联网、车联网、Feeds流、数据大屏等场景首选数据库,是为淘宝、支付宝、菜鸟等众多阿里核心业务提供关键支撑的数据库。 了解产品详情: https://cn.aliyun.com/product/hbase   ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
4月前
|
机器学习/深度学习 分布式计算 Hadoop
一种HBase表数据迁移方法的优化
一种HBase表数据迁移方法的优化
50 0
|
1月前
|
SQL 关系型数据库 MySQL
Sqoop【付诸实践 01】Sqoop1最新版 MySQL与HDFS\Hive\HBase 核心导入导出案例分享+多个WRAN及Exception问题处理(一篇即可学会在日常工作中使用Sqoop)
【2月更文挑战第9天】Sqoop【付诸实践 01】Sqoop1最新版 MySQL与HDFS\Hive\HBase 核心导入导出案例分享+多个WRAN及Exception问题处理(一篇即可学会在日常工作中使用Sqoop)
95 7
|
12月前
|
存储 SQL 消息中间件
Kylin 在贝壳的性能挑战和 HBase 优化实践(2)
Kylin 在贝壳的性能挑战和 HBase 优化实践
Kylin 在贝壳的性能挑战和 HBase 优化实践(2)
|
12月前
|
SQL 分布式计算 监控
Kylin 在贝壳的性能挑战和 HBase 优化实践(1)
Kylin 在贝壳的性能挑战和 HBase 优化实践
Kylin 在贝壳的性能挑战和 HBase 优化实践(1)
|
分布式数据库 Hbase
|
NoSQL 数据挖掘 分布式数据库
《第十二届 BigData NoSQL Meetup — 快手HBase在千亿级用户特征数据分析中的应用与实践》电子版地址
第十二届 BigData NoSQL Meetup — 快手HBase在千亿级用户特征数据分析中的应用与实践
94 0
《第十二届 BigData NoSQL Meetup — 快手HBase在千亿级用户特征数据分析中的应用与实践》电子版地址
|
分布式数据库 Hbase
|
缓存 安全 Java
HBase 优化_3 | 学习笔记
快速学习 HBase 优化_3
132 0
|
存储 缓存 分布式数据库
HBase 优化_2 | 学习笔记
快速学习 HBase 优化_2
98 0
|
存储 负载均衡 分布式数据库
HBase 优化_1 | 学习笔记
快速学习 HBase 优化_1
103 0