From 768c4d6775797e99e2489c36d9b215d9553493b5 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Mon, 2 Jun 2014 09:29:59 -0700 Subject: [PATCH] HBASE-11238 Add info about SlabCache and BucketCache to Ref Guide (Misty Stanley-Jones) --- src/main/docbkx/book.xml | 488 +++++++++++++++++++++----------- src/main/docbkx/performance.xml | 101 ++++--- 2 files changed, 370 insertions(+), 219 deletions(-) diff --git a/src/main/docbkx/book.xml b/src/main/docbkx/book.xml index 94889dce7b6..b1e6b84491a 100644 --- a/src/main/docbkx/book.xml +++ b/src/main/docbkx/book.xml @@ -1883,98 +1883,161 @@ rs.close(); -
RegionServer - HRegionServer is the RegionServer implementation. It is responsible for serving and managing regions. - In a distributed cluster, a RegionServer runs on a . - -
Interface - The methods exposed by HRegionRegionInterface contain both data-oriented and region-maintenance methods: - - Data (get, put, delete, next, etc.) +
+ RegionServer + HRegionServer is the RegionServer implementation. It is responsible for + serving and managing regions. In a distributed cluster, a RegionServer runs on a . +
+ Interface + The methods exposed by HRegionRegionInterface contain both data-oriented + and region-maintenance methods: + + Data (get, put, delete, next, etc.) - Region (splitRegion, compactRegion, etc.) + + Region (splitRegion, compactRegion, etc.) - - For example, when the HBaseAdmin method majorCompact is invoked on a table, the client is actually iterating through - all regions for the specified table and requesting a major compaction directly to each region. - -
-
Processes - The RegionServer runs a variety of background threads: -
CompactSplitThread - Checks for splits and handle minor compactions. -
-
MajorCompactionChecker - Checks for major compactions. -
-
MemStoreFlusher - Periodically flushes in-memory writes in the MemStore to StoreFiles. -
-
LogRoller - Periodically checks the RegionServer's HLog. -
-
+ For example, when the HBaseAdmin method + majorCompact is invoked on a table, the client is actually iterating + through all regions for the specified table and requesting a major compaction directly to + each region. +
+
+ Processes + The RegionServer runs a variety of background threads: +
+ CompactSplitThread + Checks for splits and handle minor compactions. +
+
+ MajorCompactionChecker + Checks for major compactions. +
+
+ MemStoreFlusher + Periodically flushes in-memory writes in the MemStore to StoreFiles. +
+
+ LogRoller + Periodically checks the RegionServer's HLog. +
+
-
Coprocessors - Coprocessors were added in 0.92. There is a thorough Blog Overview of CoProcessors - posted. Documentation will eventually move to this reference guide, but the blog is the most current information available at this time. - -
+
+ Coprocessors + Coprocessors were added in 0.92. There is a thorough Blog Overview + of CoProcessors posted. Documentation will eventually move to this reference + guide, but the blog is the most current information available at this time. +
-
- Block Cache - Below we describe the default block cache implementation, the LRUBlockCache. - Read for an understanding of how it works and an overview of the facility it provides. - Other, off-heap options have since been added. These are described in the - javadoc org.apache.hadoop.hbase.io.hfile package description. - After reading the below, - be sure to visit the blog series BlockCache 101 by Nick Dimiduk - where other Block Cache implementations are described. - -
- Design - The Block Cache is an LRU cache that contains three levels of block priority to allow for scan-resistance and in-memory ColumnFamilies: - - - Single access priority: The first time a block is loaded from HDFS it normally has this priority and it will be part of the first group to be considered - during evictions. The advantage is that scanned blocks are more likely to get evicted than blocks that are getting more usage. +
+ Block Cache + + HBase provides three different BlockCache implementations: the default onheap + LruBlockCache, and BucketCache, and SlabCache, which are both offheap. This section + discusses benefits and drawbacks of each implementation, how to choose the appropriate + option, and configuration options for each. +
+ Cache Choices + LruBlockCache is the original implementation, and is entirely within the Java heap. + SlabCache and BucketCache are mainly intended for keeping blockcache data offheap, + although BucketCache can also keep data onheap and in files. + BucketCache has seen more production deploys and has more deploy options. Fetching + will always be slower when fetching from BucketCache or SlabCache, as compared with the + native onheap LruBlockCache. However, latencies tend to be less erratic over time, + because there is less garbage collection. + Anecdotal evidence indicates that BucketCache requires less garbage collection than + SlabCache so should be even less erratic (than SlabCache or LruBlockCache). + SlabCache tends to do more garbage collections, because blocks are always moved + between L1 and L2, at least given the way DoubleBlockCache currently works. Because the + hosting class for each implementation (DoubleBlockCache vs CombinedBlockCache) works so + differently, it is difficult to do a fair comparison between BucketCache and SlabCache. + See Nick Dimiduk's BlockCache 101 for some + numbers. See also the description of HBASE-7404 where + Chunhui Shen lists issues he found with BlockCache, such as inefficient use of memory + and garbage-collection overhead. + For more information about the off heap cache options, see . +
+ +
+ LruBlockCache Design + The LruBlockCache is an LRU cache that contains three levels of block priority to + allow for scan-resistance and in-memory ColumnFamilies: + + + Single access priority: The first time a block is loaded from HDFS it normally + has this priority and it will be part of the first group to be considered during + evictions. The advantage is that scanned blocks are more likely to get evicted than + blocks that are getting more usage. - Mutli access priority: If a block in the previous priority group is accessed again, it upgrades to this priority. It is thus part of the second group - considered during evictions. + + Mutli access priority: If a block in the previous priority group is accessed + again, it upgrades to this priority. It is thus part of the second group considered + during evictions. - In-memory access priority: If the block's family was configured to be "in-memory", it will be part of this priority disregarding the number of times it - was accessed. Catalog tables are configured like this. This group is the last one considered during evictions. + + In-memory access priority: If the block's family was configured to be + "in-memory", it will be part of this priority disregarding the number of times it + was accessed. Catalog tables are configured like this. This group is the last one + considered during evictions. - - - For more information, see the LruBlockCache source - -
-
- Usage - Block caching is enabled by default for all the user tables which means that any read operation will load the LRU cache. This might be good for a large number of use cases, - but further tunings are usually required in order to achieve better performance. An important concept is the - working set size, or WSS, which is: "the amount of memory needed to compute the answer to a problem". - For a website, this would be the data that's needed to answer the queries over a short amount of time. - - The way to calculate how much memory is available in HBase for caching is: - - + + For more information, see the LruBlockCache + source + +
+
+ LruBlockCache Usage + Block caching is enabled by default for all the user tables which means that any + read operation will load the LRU cache. This might be good for a large number of use + cases, but further tunings are usually required in order to achieve better performance. + An important concept is the working set size, or + WSS, which is: "the amount of memory needed to compute the answer to a problem". For a + website, this would be the data that's needed to answer the queries over a short amount + of time. + The way to calculate how much memory is available in HBase for caching is: + number of region servers * heap size * hfile.block.cache.size * 0.85 - The default value for the block cache is 0.25 which represents 25% of the available heap. The last value (85%) is the default acceptable loading factor in the LRU cache after - which eviction is started. The reason it is included in this equation is that it would be unrealistic to say that it is possible to use 100% of the available memory since this would - make the process blocking from the point where it loads new blocks. Here are some examples: - - - One region server with the default heap size (1GB) and the default block cache size will have 217MB of block cache available. + The default value for the block cache is 0.25 which represents 25% of the available + heap. The last value (85%) is the default acceptable loading factor in the LRU cache + after which eviction is started. The reason it is included in this equation is that it + would be unrealistic to say that it is possible to use 100% of the available memory + since this would make the process blocking from the point where it loads new blocks. + Here are some examples: + + + One region server with the default heap size (1GB) and the default block cache + size will have 217MB of block cache available. - 20 region servers with the heap size set to 8GB and a default block cache size will have 34GB of block cache. + + 20 region servers with the heap size set to 8GB and a default block cache size + will have 34GB of block cache. - 100 region servers with the heap size set to 24GB and a block cache size of 0.5 will have about 1TB of block cache. + + 100 region servers with the heap size set to 24GB and a block cache size of 0.5 + will have about 1TB of block cache. - Your data isn't the only resident of the block cache, here are others that you may have to take into account: + Your data is not the only resident of the block cache. Here are others that you may have to take into account: @@ -1990,20 +2053,20 @@ rs.close(); HFiles Indexes - HFile is the file format that HBase uses to store data in HDFS and it contains - a multi-layered index in order seek to the data without having to read the whole - file. The size of those indexes is a factor of the block size (64KB by default), - the size of your keys and the amount of data you are storing. For big data sets - it's not unusual to see numbers around 1GB per region server, although not all of - it will be in cache because the LRU will evict indexes that aren't used. + An hfile is the file format that HBase uses to store + data in HDFS. It contains a multi-layered index which allows HBase to seek to the + data without having to read the whole file. The size of those indexes is a factor + of the block size (64KB by default), the size of your keys and the amount of data + you are storing. For big data sets it's not unusual to see numbers around 1GB per + region server, although not all of it will be in cache because the LRU will evict + indexes that aren't used. Keys - Taking into account only the values that are being stored is missing half the - picture since every value is stored along with its keys (row key, family, - qualifier, and timestamp). See The values that are stored are only half the picture, since each value is + stored along with its keys (row key, family qualifier, and timestamp). See . @@ -2015,96 +2078,189 @@ rs.close(); - Currently the recommended way to measure HFile indexes and bloom filters sizes is to look at the region server web UI and checkout the relevant metrics. For keys, - sampling can be done by using the HFile command line tool and look for the average key size metric. - - It's generally bad to use block caching when the WSS doesn't fit in memory. This is the case when you have for example 40GB available across all your region servers' block caches - but you need to process 1TB of data. One of the reasons is that the churn generated by the evictions will trigger more garbage collections unnecessarily. Here are two use cases: - + Currently the recommended way to measure HFile indexes and bloom filters sizes is to + look at the region server web UI and checkout the relevant metrics. For keys, sampling + can be done by using the HFile command line tool and look for the average key size + metric. + It's generally bad to use block caching when the WSS doesn't fit in memory. This is + the case when you have for example 40GB available across all your region servers' block + caches but you need to process 1TB of data. One of the reasons is that the churn + generated by the evictions will trigger more garbage collections unnecessarily. Here are + two use cases: - Fully random reading pattern: This is a case where you almost never access the same row twice within a short amount of time such that the chance of hitting a cached block is close - to 0. Setting block caching on such a table is a waste of memory and CPU cycles, more so that it will generate more garbage to pick up by the JVM. For more information on monitoring GC, - see . + + Fully random reading pattern: This is a case where you almost never access the + same row twice within a short amount of time such that the chance of hitting a + cached block is close to 0. Setting block caching on such a table is a waste of + memory and CPU cycles, more so that it will generate more garbage to pick up by the + JVM. For more information on monitoring GC, see . - Mapping a table: In a typical MapReduce job that takes a table in input, every row will be read only once so there's no need to put them into the block cache. The Scan object has - the option of turning this off via the setCaching method (set it to false). You can still keep block caching turned on on this table if you need fast random read access. An example would be - counting the number of rows in a table that serves live traffic, caching every block of that table would create massive churn and would surely evict data that's currently in use. - - -
-
Offheap Block Cache - There are a few options for configuring an off-heap cache for blocks read from HDFS. - The options and their setup are described in a javadoc package doc. See - org.apache.hadoop.hbase.io.hfile package description. - -
+ + Mapping a table: In a typical MapReduce job that takes a table in input, every + row will be read only once so there's no need to put them into the block cache. The + Scan object has the option of turning this off via the setCaching method (set it to + false). You can still keep block caching turned on on this table if you need fast + random read access. An example would be counting the number of rows in a table that + serves live traffic, caching every block of that table would create massive churn + and would surely evict data that's currently in use. + + +
+
+ Offheap Block Cache +
+ Enable SlabCache + SlabCache is originally described in Caching + in Apache HBase: SlabCache. Quoting from the API documentation for DoubleBlockCache, + it is an abstraction layer that combines two caches, the smaller onHeapCache and the + larger offHeapCache. CacheBlock attempts to cache the block in both caches, while + readblock reads first from the faster on heap cache before looking for the block in + the off heap cache. Metrics are the combined size and hits and misses of both + caches. + To enable SlabCache, set the float + hbase.offheapcache.percentage to some value between 0 and 1 in + the hbase-site.xml file on the RegionServer. The value will be multiplied by the + setting for -XX:MaxDirectMemorySize in the RegionServer's + hbase-env.sh configuration file and the result is used by + SlabCache as its offheap store. The onheap store will be the value of the float + HConstants.HFILE_BLOCK_CACHE_SIZE_KEY setting (some value between + 0 and 1) multiplied by the size of the allocated Java heap. + Restart (or rolling restart) your cluster for the configurations to take effect. + Check logs for errors or unexpected behavior. +
+
+ Enable BucketCache + To enable BucketCache, set the value of + hbase.offheapcache.percentage to 0 in the RegionServer's + hbase-site.xml file. This disables SlabCache. Next, set the + various options for BucketCache to values appropriate to your situation. You can find + more information about all of the (more than 26) options at . + After setting the options, restart or rolling restart your cluster for the + configuration to take effect. Check logs for errors or unexpected behavior. + The offheap and onheap caches are managed by CombinedBlockCache + by default. The link describes the mechanism of CombinedBlockCache. To disable + CombinedBlockCache, and use the BucketCache as a strict L2 cache to the L1 + LruBlockCache, set CacheConfig.BUCKET_CACHE_COMBINED_KEY to + false. In this mode, on eviction from L1, blocks go to L2. + By default, CacheConfig.BUCKET_CACHE_COMBINED_PERCENTAGE_KEY + defaults to 0.9. This means that whatever size you set for the + bucket cache with CacheConfig.BUCKET_CACHE_SIZE_KEY, 90% will be + used for offheap and 10% will be used by the onheap LruBlockCache. + + BucketCache Example Configuration + This sample provides a configuration for a 4 GB offheap BucketCache with a 1 GB + onheap cache. Configuration is performed on the RegionServer. + + First, edit the RegionServer's hbase-env.sh and set + -XX:MaxDirectMemorySize to the total size of the desired onheap plus offheap, in + this case, 5 GB (but expressed as 5G). + -XX:MaxDirectMemorySize=5G + + + Next, add the following configuration to the RegionServer's + hbase-site.xml. This configuration uses 80% of the + -XX:MaxDirectMemorySize (4 GB) for offheap, and the remainder (1 GB) for + onheap. + + + hbase.bucketcache.ioengine + offheap + + + hbase.bucketcache.percentage.in.combinedcache + 0.8 + + + hbase.bucketcache.size + 5120 +]]> + + + + Restart or rolling restart your cluster, and check the logs for any + issues. + + +
+
-
- Write Ahead Log (WAL) +
+ Write Ahead Log (WAL) -
- Purpose +
+ Purpose - Each RegionServer adds updates (Puts, Deletes) to its write-ahead log (WAL) - first, and then to the for the affected . - This ensures that HBase has durable writes. Without WAL, there is the possibility of data loss in the case of a RegionServer failure - before each MemStore is flushed and new StoreFiles are written. HLog - is the HBase WAL implementation, and there is one HLog instance per RegionServer. - The WAL is in HDFS in /hbase/.logs/ with subdirectories per region. - - For more general information about the concept of write ahead logs, see the Wikipedia - Write-Ahead Log article. - -
-
- WAL Flushing - TODO (describe). - + Each RegionServer adds updates (Puts, Deletes) to its write-ahead log (WAL) first, + and then to the for the affected . This ensures that HBase has durable writes. Without WAL, there is + the possibility of data loss in the case of a RegionServer failure before each MemStore + is flushed and new StoreFiles are written. HLog + is the HBase WAL implementation, and there is one HLog instance per RegionServer. + The WAL is in HDFS in /hbase/.logs/ with subdirectories per + region. + For more general information about the concept of write ahead logs, see the + Wikipedia Write-Ahead Log + article. +
+
+ WAL Flushing + TODO (describe).
-
- WAL Splitting +
+ WAL Splitting -
How edits are recovered from a crashed RegionServer - When a RegionServer crashes, it will lose its ephemeral lease in - ZooKeeper...TODO -
-
- <varname>hbase.hlog.split.skip.errors</varname> +
+ How edits are recovered from a crashed RegionServer + When a RegionServer crashes, it will lose its ephemeral lease in + ZooKeeper...TODO +
+
+ <varname>hbase.hlog.split.skip.errors</varname> - When set to true, any error - encountered splitting will be logged, the problematic WAL will be - moved into the .corrupt directory under the hbase - rootdir, and processing will continue. If set to - false, the default, the exception will be propagated and the - split logged as failed. - See HBASE-2958 - When hbase.hlog.split.skip.errors is set to false, we fail the - split but thats it. We need to do more than just fail split - if this flag is set. - + When set to true, any error encountered splitting will be + logged, the problematic WAL will be moved into the .corrupt + directory under the hbase rootdir, and processing will continue. If + set to false, the default, the exception will be propagated and + the split logged as failed. + See HBASE-2958 When + hbase.hlog.split.skip.errors is set to false, we fail the split but thats + it. We need to do more than just fail split if this flag is set. + +
+ +
+ How EOFExceptions are treated when splitting a crashed RegionServers' + WALs + + If we get an EOF while splitting logs, we proceed with the split even when + hbase.hlog.split.skip.errors == false. An + EOF while reading the last log in the set of files to split is near-guaranteed since + the RegionServer likely crashed mid-write of a record. But we'll continue even if we + got an EOF reading other than the last file in the set. + For background, see HBASE-2643 Figure + how to deal with eof splitting logs + +
+
-
- How EOFExceptions are treated when splitting a crashed - RegionServers' WALs - - If we get an EOF while splitting logs, we proceed with the split - even when hbase.hlog.split.skip.errors == - false. An EOF while reading the last log in the - set of files to split is near-guaranteed since the RegionServer likely - crashed mid-write of a record. But we'll continue even if we got an - EOF reading other than the last file in the set. - For background, see HBASE-2643 - Figure how to deal with eof splitting logs - -
-
-
-
diff --git a/src/main/docbkx/performance.xml b/src/main/docbkx/performance.xml index cbe600e3816..dad9b0cd271 100644 --- a/src/main/docbkx/performance.xml +++ b/src/main/docbkx/performance.xml @@ -199,63 +199,58 @@ Managing Compactions For larger systems, managing compactions and splits may be something you want to - consider. + linkend="disable.splitting">compactions and splits may be + something you want to consider.
-
- <varname>hbase.regionserver.handler.count</varname> - See . +
+ <varname>hbase.regionserver.handler.count</varname> + See . +
-
- <varname>hfile.block.cache.size</varname> - See . A memory setting for the RegionServer process. - -
-
- <varname>hbase.regionserver.global.memstore.size</varname> - See . This memory setting is often - adjusted for the RegionServer process depending on needs. -
-
- <varname>hbase.regionserver.global.memstore.size.lower.limit</varname> - See . This memory setting is - often adjusted for the RegionServer process depending on needs. -
-
- <varname>hbase.hstore.blockingStoreFiles</varname> - See . If there is blocking in the RegionServer - logs, increasing this can help. -
-
- <varname>hbase.hregion.memstore.block.multiplier</varname> - See . If there is enough RAM, increasing - this can help. -
-
- <varname>hbase.regionserver.checksum.verify</varname> - Have HBase write the checksum into the datablock and save having to do the checksum seek - whenever you read. + - See , and For more information see the release note on HBASE-5074 support checksums - in HBase block cache. + +
+ <varname>hfile.block.cache.size</varname> + See . + A memory setting for the RegionServer process. + +
+
+ <varname>hbase.regionserver.global.memstore.size</varname> + See . + This memory setting is often adjusted for the RegionServer process depending on needs. + +
+
+ <varname>hbase.regionserver.global.memstore.size.lower.limit</varname> + See . + This memory setting is often adjusted for the RegionServer process depending on needs. + +
+
+ <varname>hbase.hstore.blockingStoreFiles</varname> + See . + If there is blocking in the RegionServer logs, increasing this can help. + +
+
+ <varname>hbase.hregion.memstore.block.multiplier</varname> + See . + If there is enough RAM, increasing this can help. + +
+
+ <varname>hbase.regionserver.checksum.verify</varname> + Have HBase write the checksum into the datablock and save + having to do the checksum seek whenever you read. + + See , + and + For more information see the + release note on HBASE-5074 support checksums in HBase block cache. +