java内存配置计算,HBase内存配置及JVM优化

前言

本文从HBase的内存布局说起,先充分了解HBase的内存区的使用与分配,随后给出了不同业务场景下的读写内存分配规划,并指导如何分析业务的内存使用情况,以及在使用当中写内存Memstore及读内存扩展bucketcache的一些注意事项,最后为了保障群集的稳定性减少和降低GC对于集群稳定性的影响,研究及分享了一些关于HBase JVM配置的一些关键参数机器作用和范例,希望这些不断充实的经验能确保HBase集群的稳定性能更上一个台阶,大家有任何的想法和建议也欢迎一起讨论。

HBase的内存布局

一台region server的内存使用(如下图所示)主要分成两部分:

1.JVM内存即我们通常俗称的堆内内存,这块内存区域的大小分配在HBase的环境脚本中设置,在堆内内存中主要有三块内存区域,

20%分配给hbase regionserver rpc请求队列及一些其他操作

80%分配给memstore + blockcache

2.java direct memory即堆外内存,

其中一部分内存用于HDFS SCR/NIO操作

另一部分用于堆外内存bucket cache,其内存大小的分配同样在hbase的环境变量脚本中实现

b9c45b64f3897b459b7984ac14ad2256.png

读写内存规划

写多读少型规划

在详细说明具体的容量规划前,首先要明确on heap模式下的内存分布图,如下图所示:

917e8c2e7c33588fe6d80b7f0f02831d.png

如图,整个RegionServer内存就是JVM所管理的内存,BlockCache用于读缓存;MemStore用于写流程,缓存用户写入KeyValue数据;还有部分用于RegionServer正常RPC请求运行所必须的内存;

步骤

原理

计算

jvm_heap

系统总内存的 2/3

128G/3*2

80G

blockcache

读缓存

80G*30%

24G

memstore

写缓存

80G*45%

36G

hbase-site.

hbase.regionserver.global.memstore.size0.45hfile.block.cache.size0.3

读多写少型规划

与 on heap模式相比,读多写少型需要更多的读缓存,在对读请求响应时间没有太严苛的情况下,会开启off heap即启用堆外内存的中的bucket cache作为读缓存的补充,如下图所示

1dbbc166d3304f4d8832cd7802f7729d.png

整个RegionServer内存分为两部分:JVM内存和堆外内存。其中JVM内存中BlockCache和堆外内存BucketCache一起构成了读缓存CombinedBlockCache,用于缓存读到的Block数据,其中BlockCache用于缓存Index Block和Bloom Block,BucketCache用于缓存实际用户数据Data Block

步骤

原理

计算

RS总内存

系统总内存的 2/3

128G/3*2

80G

combinedBlockCache

读缓存设置为整个RS内存的70%

80G*70%

56G

blockcache

主要缓存数据块元数据,数据量相对较小。设置为整个读缓存的10%

56G*10%

6G

bucketcache

主要缓存用户数据块,数据量相对较大。设置为整个读缓存的90%

56G*90%

50G

memstore

写缓存设置为jvm_heap的60%

30G*60%

18G

jvm_heap

rs总内存-堆外内存

80G-50G

30G

参数详解

Property

Default

Description

hbase.bucketcache.combinedcache.enabled

true

When BucketCache is enabled, use it as a L2 cache for LruBlockCache. If set to true, indexes and Bloom filters are kept in the LruBlockCache and the data blocks are kept in the BucketCache.

hbase.bucketcache.ioengine

none

Where to store the contents of the BucketCache. Its value can be offheap、heap、file

hfile.block.cache.size

0.4

A float between 0.0 and 1.0. This factor multiplied by the Java heap size is the size of the L1 cache. In other words, the percentage of the Java heap to use for the L1 cache.

hbase.bucketcache.size

not set

When using BucketCache, this is a float that represents one of two different values, depending on whether it is a floating-point decimal less than 1.0 or an integer greater than 1.0.

If less than 1.0, it represents a percentage of total heap memory size to give to the cache.

If greater than 1.0, it represents the capacity of the cache in megabytes

-XX:MaxDirectMemorySize

MaxDirectMemorySize = BucketCache + 1

A JVM option to configure the maximum amount of direct memory available for the JVM. It is automatically calculated and configured based on the following formula: MaxDirectMemorySize = BucketCache size + 1 GB for other features using direct memory, such as DFSClient. For example, if the BucketCache size is 8 GB, it will be -XX:MaxDirectMemorySize=9G.

hbase-site.

hbase.bucketcache.combinedcache.enabledtruehbase.bucketcache.ioengineoffheap #同时作为master的rs要用heaphbase.bucketcache.size50176 #单位MB。这个值至少要比bucketcache小1G,作为master的rs用heap,那么这里要填<1的值作为从heap中分配给bucketcache的百分比hbase.regionserver.global.memstore.size0.60 #heap减小了,那么heap中用于memstore的百分比要增大才能保证用于memstore的内存和原来一样hfile.block.cache.size0.20 #使用了bucketcache作为blockcache的一部分,那么heap中用于blockcache的百分比可以减小

hbase-env.sh

export HBASE_REGIONSERVER_OPTS="-XX:+UseG1GC-Xms30g –Xmx30g -XX:MaxDirectMemorySize=50g

读写内存的使用情况

知己知彼方能百战不殆,在HBase群集的运行过程中,我们需要了解HBase实际情况下的读写内存使用,才能最大化的对配置做出最加的调整,接下来说下如何查询HBase运行中读写内存使用情况

Jmx查询

memStoreSize代表RegionServer中所有HRegion中的memstore大小的总和,单位是Byte。该值的变化,可以反应出一个RegionServer上写请求的负载状况,可以观察memstoreSize的变化率,如果在单位时间内变化比较抖动,可以近似认为写操作频繁。

blockCacheFree代表block cache中空闲的内存大小。计算方法为:getMaxSize() – getCurrentSize(),单位是Byte,该值反映出当前BlockCache中还有多少空间可以被利用。

blockCacheSize代表当前使用的blockCache的大小。BlockCache. getCurrentSize(),单位是Byte,该值反映出BlockCache的使用状况。

以单台region server配置为例

配置项

配置值

内存分配值

实际使用量

HBASE_REGIONSERVER_OPTS

-Xms75g –Xmx75g

75g

75g

hbase.regionserver.global.memstore.size

0.22

80g*0.22 = 17.6g

10800044400/1024/1024/.........

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值