From 40d43397aedf80d961bac56909e9c5aeec6ee78c Mon Sep 17 00:00:00 2001 From: Biju Nair Date: Fri, 18 Aug 2017 17:14:54 -0400 Subject: [PATCH] HBASE-18532 Improve cache related stats rendered on RS UI --- .../hadoop/hbase/io/hfile/MemcachedBlockCache.java | 10 ++++++++ .../hbase/tmpl/regionserver/BlockCacheTmpl.jamon | 8 +++---- .../apache/hadoop/hbase/io/hfile/BlockCache.java | 12 ++++++++++ .../hadoop/hbase/io/hfile/CombinedBlockCache.java | 10 ++++++++ .../hadoop/hbase/io/hfile/LruBlockCache.java | 28 +++++++++++++++++++++- .../hadoop/hbase/io/hfile/bucket/BucketCache.java | 10 ++++++++ .../hbase/regionserver/TestHeapMemoryManager.java | 10 ++++++++ 7 files changed, 83 insertions(+), 5 deletions(-) diff --git a/hbase-external-blockcache/src/main/java/org/apache/hadoop/hbase/io/hfile/MemcachedBlockCache.java b/hbase-external-blockcache/src/main/java/org/apache/hadoop/hbase/io/hfile/MemcachedBlockCache.java index e74176080b..965bcbe927 100644 --- a/hbase-external-blockcache/src/main/java/org/apache/hadoop/hbase/io/hfile/MemcachedBlockCache.java +++ b/hbase-external-blockcache/src/main/java/org/apache/hadoop/hbase/io/hfile/MemcachedBlockCache.java @@ -209,11 +209,21 @@ public class MemcachedBlockCache implements BlockCache { } @Override + public long getCurrentDataSize() { + return 0; + } + + @Override public long getBlockCount() { return 0; } @Override + public long getDataBlockCount() { + return 0; + } + + @Override public Iterator iterator() { return new Iterator() { @Override diff --git a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon index daa5d76877..3afd4f9b86 100644 --- a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon +++ b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon @@ -327,25 +327,25 @@ are combined counts. Request count is sum of hits and misses.

Count - <% String.format("%,d", cbsbf.getCount()) %> + <% String.format("%,d", bc.getBlockCount()) %> Count of Blocks <%if !bucketCache %> Count - <% String.format("%,d", cbsbf.getDataCount()) %> + <% String.format("%,d", bc.getDataBlockCount()) %> Count of DATA Blocks Size - <% TraditionalBinaryPrefix.long2String(cbsbf.getSize(), "B", 1) %> + <% TraditionalBinaryPrefix.long2String(bc.getCurrentSize(), "B", 1) %> Size of Blocks <%if !bucketCache %> Size - <% TraditionalBinaryPrefix.long2String(cbsbf.getDataSize(), "B", 1) %> + <% TraditionalBinaryPrefix.long2String(bc.getCurrentDataSize(), "B", 1) %> Size of DATA Blocks diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCache.java index cef7e02d45..3674033eb6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockCache.java @@ -103,10 +103,22 @@ public interface BlockCache extends Iterable { long getCurrentSize(); /** + * Returns the occupied size of data blocks, in bytes. + * @return occupied space in cache, in bytes + */ + long getCurrentDataSize(); + + /** * Returns the number of blocks currently cached in the block cache. * @return number of blocks in the cache */ long getBlockCount(); + + /** + * Returns the number of data blocks currently cached in the block cache. + * @return number of blocks in the cache + */ + long getDataBlockCount(); /** * @return Iterator over the blocks in the cache. diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CombinedBlockCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CombinedBlockCache.java index 3efd3fe784..abccdfc24d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CombinedBlockCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CombinedBlockCache.java @@ -114,6 +114,11 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize { } @Override + public long getCurrentDataSize() { + return lruCache.getCurrentDataSize() + l2Cache.getCurrentDataSize(); + } + + @Override public long getFreeSize() { return lruCache.getFreeSize() + l2Cache.getFreeSize(); } @@ -128,6 +133,11 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize { return lruCache.getBlockCount() + l2Cache.getBlockCount(); } + @Override + public long getDataBlockCount() { + return lruCache.getDataBlockCount() + l2Cache.getDataBlockCount(); + } + public static class CombinedCacheStats extends CacheStats { private final CacheStats lruCacheStats; private final CacheStats bucketCacheStats; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java index c1870221ac..74a3629b6c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java @@ -176,9 +176,15 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { /** Current size of cache */ private final AtomicLong size; + /** Current size of data blocks */ + private final AtomicLong dataBlockSize; + /** Current number of cached elements */ private final AtomicLong elements; + /** Current number of cached data block elements */ + private final AtomicLong dataBlockElements; + /** Cache access count (sequential ID) */ private final AtomicLong count; @@ -314,6 +320,8 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { this.stats = new CacheStats(this.getClass().getSimpleName()); this.count = new AtomicLong(0); this.elements = new AtomicLong(0); + this.dataBlockElements = new AtomicLong(0); + this.dataBlockSize = new AtomicLong(0); this.overhead = calculateOverhead(maxSize, blockSize, mapConcurrencyLevel); this.size = new AtomicLong(this.overhead); this.hardCapacityLimitFactor = hardLimitFactor; @@ -399,6 +407,8 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { long newSize = updateSizeMetrics(cb, false); map.put(cacheKey, cb); long val = elements.incrementAndGet(); + if (buf.getBlockType().isData()) + dataBlockElements.incrementAndGet(); if (LOG.isTraceEnabled()) { long size = map.size(); assertCounterSanity(size, val); @@ -454,9 +464,13 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { */ private long updateSizeMetrics(LruCachedBlock cb, boolean evict) { long heapsize = cb.heapSize(); + BlockType bt = cb.getBuffer().getBlockType(); if (evict) { heapsize *= -1; } + if (bt != null && bt.isData()) { + dataBlockSize.addAndGet(heapsize); + } return size.addAndGet(heapsize); } @@ -561,6 +575,8 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { long size = map.size(); assertCounterSanity(size, val); } + if (block.getBuffer().getBlockType().isData()) + dataBlockElements.decrementAndGet(); if (evictedByEvictionProcess) { // When the eviction of the block happened because of invalidation of HFiles, no need to // update the stats counter. @@ -831,6 +847,11 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { } @Override + public long getCurrentDataSize() { + return this.dataBlockSize.get(); + } + + @Override public long getFreeSize() { return getMaxSize() - getCurrentSize(); } @@ -845,6 +866,11 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { return this.elements.get(); } + @Override + public long getDataBlockCount() { + return this.dataBlockElements.get(); + } + EvictionThread getEvictionThread() { return this.evictionThread; } @@ -958,7 +984,7 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize { } public final static long CACHE_FIXED_OVERHEAD = ClassSize.align( - (4 * Bytes.SIZEOF_LONG) + (9 * ClassSize.REFERENCE) + + (4 * Bytes.SIZEOF_LONG) + (11 * ClassSize.REFERENCE) + (6 * Bytes.SIZEOF_FLOAT) + (2 * Bytes.SIZEOF_BOOLEAN) + ClassSize.OBJECT); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java index 79b1f4d7cb..939d53a903 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java @@ -1190,6 +1190,11 @@ public class BucketCache implements BlockCache, HeapSize { } @Override + public long getCurrentDataSize() { + return size(); + } + + @Override public long getFreeSize() { return this.bucketAllocator.getFreeSize(); } @@ -1200,6 +1205,11 @@ public class BucketCache implements BlockCache, HeapSize { } @Override + public long getDataBlockCount() { + return getBlockCount(); + } + + @Override public long getCurrentSize() { return this.bucketAllocator.getUsedSize(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java index e1a8d5fb64..0840ac5027 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHeapMemoryManager.java @@ -748,11 +748,21 @@ public class TestHeapMemoryManager { } @Override + public long getCurrentDataSize() { + return 0; + } + + @Override public long getBlockCount() { return 0; } @Override + public long getDataBlockCount() { + return 0; + } + + @Override public void setMaxSize(long size) { this.maxSize = size; } -- 2.11.0 (Apple Git-81)