1. 程式人生 > >HBase記憶體配置及JVM優化

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的環境變數指令碼中實現 ![](https://img2020.cnblogs.com/blog/1247138/202012/1247138-20201230094456070-918493241.png) ## 讀寫記憶體規劃 - 寫多讀少型規劃 在詳細說明具體的容量規劃前,首先要明確on heap模式下的記憶體分佈圖,如下圖所示: ![](https://img2020.cnblogs.com/blog/1247138/202012/1247138-20201230094601780-1337388836.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.xmll ``` ``` - 讀多寫少型規劃 與 on heap模式相比,讀多寫少型需要更多的讀快取,在對讀請求響應時間沒有太嚴苛的情況下,會開啟off heap即啟用堆外記憶體的中的bucket cache作為讀快取的補充,如下圖所示 ![](https://img2020.cnblogs.com/blog/1247138/202012/1247138-20201230095127486-1721217610.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.xml ``` ``` hbase-env.sh ``` export HBASE_REGIONSERVER_OPTS="-XX:+UseG1GC -Xms30g –Xmx30g -XX:MaxDirectMemorySize=50g ``` ## 讀寫記憶體的使用情況 知己知彼方能百戰不殆,在HBase群集的執行過程中,我們需要了解HBase實際情況下的讀寫記憶體使用,才能最大化的對配置做出最加的調整,接下來說下如何查詢HBase執行中讀寫記憶體使用情況 Jmx查詢