HBASE-27186 Report block cache size metrics separately for L1 and L2 (#4608)

Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
Bryan Beaudreault 2022-07-11 22:00:04 -04:00
parent c39025ff0e
commit f5500dc495
7 changed files with 183 additions and 0 deletions

View File

@ -309,6 +309,8 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
String BLOCK_CACHE_FREE_DESC = "Size of the block cache that is not occupied.";
String BLOCK_CACHE_COUNT = "blockCacheCount";
String BLOCK_CACHE_COUNT_DESC = "Number of block in the block cache.";
String BLOCK_CACHE_DATA_BLOCK_COUNT = "blockCacheDataBlockCount";
String BLOCK_CACHE_DATA_BLOCK_COUNT_DESC = "Number of DATA block in the block cache.";
String BLOCK_CACHE_SIZE = "blockCacheSize";
String BLOCK_CACHE_SIZE_DESC = "Size of the block cache.";
String BLOCK_CACHE_HIT_COUNT = "blockCacheHitCount";
@ -358,6 +360,15 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
String BLOCK_CACHE_GENERAL_BLOOM_META_HIT_COUNT = "blockCacheGeneralBloomMetaHitCount";
String BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT = "blockCacheDeleteFamilyBloomHitCount";
String BLOCK_CACHE_TRAILER_HIT_COUNT = "blockCacheTrailerHitCount";
String L1_CACHE_FREE_SIZE = "l1CacheFreeSize";
String L1_CACHE_FREE_SIZE_DESC = "Amount of free bytes in the L1 cache";
String L1_CACHE_SIZE = "l1CacheSize";
String L1_CACHE_SIZE_DESC = "Size of the L1 cache in bytes";
String L1_CACHE_COUNT = "l1CacheCount";
String L1_CACHE_COUNT_DESC = "Count of blocks in the L1 cache";
String L1_CACHE_EVICTION_COUNT = "l1CacheEvictionCount";
String L1_CACHE_EVICTION_COUNT_DESC = "Count of blocks evicted from the L1 cache";
String L1_CACHE_HIT_COUNT = "l1CacheHitCount";
String L1_CACHE_HIT_COUNT_DESC = "L1 cache hit count.";
String L1_CACHE_MISS_COUNT = "l1CacheMissCount";
@ -366,6 +377,14 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
String L1_CACHE_HIT_RATIO_DESC = "L1 cache hit ratio.";
String L1_CACHE_MISS_RATIO = "l1CacheMissRatio";
String L1_CACHE_MISS_RATIO_DESC = "L1 cache miss ratio.";
String L2_CACHE_FREE_SIZE = "l2CacheFreeSize";
String L2_CACHE_FREE_SIZE_DESC = "Amount of free bytes in the L2 cache";
String L2_CACHE_SIZE = "l2CacheSize";
String L2_CACHE_SIZE_DESC = "Size of the L2 cache in bytes";
String L2_CACHE_COUNT = "l2CacheCount";
String L2_CACHE_COUNT_DESC = "Count of blocks in the L2 cache";
String L2_CACHE_EVICTION_COUNT = "l2CacheEvictionCount";
String L2_CACHE_EVICTION_COUNT_DESC = "Count of blocks evicted from the L2 cache";
String L2_CACHE_HIT_COUNT = "l2CacheHitCount";
String L2_CACHE_HIT_COUNT_DESC = "L2 cache hit count.";
String L2_CACHE_MISS_COUNT = "l2CacheMissCount";

View File

@ -257,6 +257,11 @@ public interface MetricsRegionServerWrapper {
*/
long getBlockCacheCount();
/**
* Get the number of DATA blocks in the block cache.
*/
long getBlockCacheDataBlockCount();
/**
* Get the total size (in bytes) of the block cache.
*/
@ -307,6 +312,26 @@ public interface MetricsRegionServerWrapper {
*/
long getBlockCacheFailedInsertions();
/**
* Cache size (bytes) of L1 cache
*/
long getL1CacheSize();
/**
* Free cache size (bytes) of L1 cache
*/
long getL1CacheFreeSize();
/**
* Number of blocks in L1 cache
*/
long getL1CacheCount();
/**
* Number of blocks evicted from L1 cache
*/
long getL1CacheEvictedCount();
/**
* Hit count of L1 cache.
*/
@ -327,6 +352,26 @@ public interface MetricsRegionServerWrapper {
*/
double getL1CacheMissRatio();
/**
* Cache size (bytes) of L2 cache
*/
long getL2CacheSize();
/**
* Free cache size (bytes) of L2 cache
*/
long getL2CacheFreeSize();
/**
* Number of blocks in L2 cache
*/
long getL2CacheCount();
/**
* Number of blocks evicted from L2 cache
*/
long getL2CacheEvictedCount();
/**
* Hit count of L2 cache.
*/

View File

@ -528,11 +528,19 @@ public class MetricsRegionServerSourceImpl extends BaseSourceImpl
rsWrap.getBlockCacheFreeSize())
.addGauge(Interns.info(BLOCK_CACHE_COUNT, BLOCK_CACHE_COUNT_DESC),
rsWrap.getBlockCacheCount())
.addGauge(Interns.info(BLOCK_CACHE_DATA_BLOCK_COUNT, BLOCK_CACHE_DATA_BLOCK_COUNT_DESC),
rsWrap.getBlockCacheDataBlockCount())
.addGauge(Interns.info(BLOCK_CACHE_SIZE, BLOCK_CACHE_SIZE_DESC), rsWrap.getBlockCacheSize())
.addGauge(Interns.info(BLOCK_CACHE_HIT_PERCENT, BLOCK_CACHE_HIT_PERCENT_DESC),
rsWrap.getBlockCacheHitPercent())
.addGauge(Interns.info(BLOCK_CACHE_EXPRESS_HIT_PERCENT, BLOCK_CACHE_EXPRESS_HIT_PERCENT_DESC),
rsWrap.getBlockCacheHitCachingPercent())
.addGauge(Interns.info(L1_CACHE_SIZE, L1_CACHE_SIZE_DESC), rsWrap.getL1CacheSize())
.addGauge(Interns.info(L1_CACHE_FREE_SIZE, L1_CACHE_FREE_SIZE_DESC),
rsWrap.getL1CacheFreeSize())
.addGauge(Interns.info(L1_CACHE_COUNT, L1_CACHE_COUNT_DESC), rsWrap.getL1CacheCount())
.addCounter(Interns.info(L1_CACHE_EVICTION_COUNT, L1_CACHE_EVICTION_COUNT_DESC),
rsWrap.getL1CacheEvictedCount())
.addGauge(Interns.info(L1_CACHE_HIT_COUNT, L1_CACHE_HIT_COUNT_DESC),
rsWrap.getL1CacheHitCount())
.addGauge(Interns.info(L1_CACHE_MISS_COUNT, L1_CACHE_MISS_COUNT_DESC),
@ -541,6 +549,12 @@ public class MetricsRegionServerSourceImpl extends BaseSourceImpl
rsWrap.getL1CacheHitRatio())
.addGauge(Interns.info(L1_CACHE_MISS_RATIO, L1_CACHE_MISS_RATIO_DESC),
rsWrap.getL1CacheMissRatio())
.addGauge(Interns.info(L2_CACHE_SIZE, L2_CACHE_SIZE_DESC), rsWrap.getL2CacheSize())
.addGauge(Interns.info(L2_CACHE_FREE_SIZE, L2_CACHE_FREE_SIZE_DESC),
rsWrap.getL2CacheFreeSize())
.addGauge(Interns.info(L2_CACHE_COUNT, L2_CACHE_COUNT_DESC), rsWrap.getL2CacheCount())
.addCounter(Interns.info(L2_CACHE_EVICTION_COUNT, L2_CACHE_EVICTION_COUNT_DESC),
rsWrap.getL2CacheEvictedCount())
.addGauge(Interns.info(L2_CACHE_HIT_COUNT, L2_CACHE_HIT_COUNT_DESC),
rsWrap.getL2CacheHitCount())
.addGauge(Interns.info(L2_CACHE_MISS_COUNT, L2_CACHE_MISS_COUNT_DESC),

View File

@ -377,4 +377,8 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize {
public FirstLevelBlockCache getFirstLevelCache() {
return l1Cache;
}
public BlockCache getSecondLevelCache() {
return l2Cache;
}
}

View File

@ -66,6 +66,8 @@ class MetricsRegionServerWrapperImpl implements MetricsRegionServerWrapper {
private final ByteBuffAllocator allocator;
private BlockCache blockCache;
private BlockCache l1Cache = null;
private BlockCache l2Cache = null;
private MobFileCache mobFileCache;
private CacheStats cacheStats;
private CacheStats l1Stats = null;
@ -171,6 +173,14 @@ class MetricsRegionServerWrapperImpl implements MetricsRegionServerWrapper {
l1Stats = this.cacheStats;
}
}
if (this.blockCache != null) {
if (this.blockCache instanceof CombinedBlockCache) {
l1Cache = ((CombinedBlockCache) this.blockCache).getFirstLevelCache();
l2Cache = ((CombinedBlockCache) this.blockCache).getSecondLevelCache();
} else {
l1Cache = this.blockCache;
}
}
}
/**
@ -274,6 +284,11 @@ class MetricsRegionServerWrapperImpl implements MetricsRegionServerWrapper {
return this.blockCache != null ? this.blockCache.getBlockCount() : 0L;
}
@Override
public long getBlockCacheDataBlockCount() {
return this.blockCache != null ? this.blockCache.getDataBlockCount() : 0L;
}
@Override
public long getMemStoreLimit() {
return this.regionServer.getRegionServerAccounting().getGlobalMemStoreLimit();
@ -352,6 +367,38 @@ class MetricsRegionServerWrapperImpl implements MetricsRegionServerWrapper {
return this.cacheStats != null ? this.cacheStats.getFailedInserts() : 0L;
}
public long getL1CacheSize() {
return this.l1Cache != null ? this.l1Cache.getCurrentSize() : 0L;
}
public long getL1CacheFreeSize() {
return this.l1Cache != null ? this.l1Cache.getFreeSize() : 0L;
}
public long getL1CacheCount() {
return this.l1Cache != null ? this.l1Cache.getBlockCount() : 0L;
}
public long getL1CacheEvictedCount() {
return this.l1Stats != null ? this.l1Stats.getEvictedCount() : 0L;
}
public long getL2CacheSize() {
return this.l2Cache != null ? this.l2Cache.getCurrentSize() : 0L;
}
public long getL2CacheFreeSize() {
return this.l2Cache != null ? this.l2Cache.getFreeSize() : 0L;
}
public long getL2CacheCount() {
return this.l2Cache != null ? this.l2Cache.getBlockCount() : 0L;
}
public long getL2CacheEvictedCount() {
return this.l2Stats != null ? this.l2Stats.getEvictedCount() : 0L;
}
@Override
public long getL1CacheHitCount() {
return this.l1Stats != null ? this.l1Stats.getHitCount() : 0L;

View File

@ -282,6 +282,11 @@ public class MetricsRegionServerWrapperStub implements MetricsRegionServerWrappe
return 414;
}
@Override
public long getBlockCacheDataBlockCount() {
return 300;
}
@Override
public long getBlockCacheSize() {
return 415;
@ -332,6 +337,26 @@ public class MetricsRegionServerWrapperStub implements MetricsRegionServerWrappe
return 36;
}
@Override
public long getL1CacheSize() {
return 123;
}
@Override
public long getL1CacheFreeSize() {
return 100;
}
@Override
public long getL1CacheCount() {
return 50;
}
@Override
public long getL1CacheEvictedCount() {
return 1000;
}
@Override
public long getL1CacheHitCount() {
return 200;
@ -352,6 +377,26 @@ public class MetricsRegionServerWrapperStub implements MetricsRegionServerWrappe
return 20;
}
@Override
public long getL2CacheSize() {
return 456;
}
@Override
public long getL2CacheFreeSize() {
return 200;
}
@Override
public long getL2CacheCount() {
return 75;
}
@Override
public long getL2CacheEvictedCount() {
return 2000;
}
@Override
public long getL2CacheHitCount() {
return 800;

View File

@ -104,6 +104,7 @@ public class TestMetricsRegionServer {
HELPER.assertGauge("flushQueueLength", 412, serverSource);
HELPER.assertGauge("blockCacheFreeSize", 413, serverSource);
HELPER.assertGauge("blockCacheCount", 414, serverSource);
HELPER.assertGauge("blockCacheDataBlockCount", 300, serverSource);
HELPER.assertGauge("blockCacheSize", 415, serverSource);
HELPER.assertCounter("blockCacheHitCount", 416, serverSource);
HELPER.assertCounter("blockCacheMissCount", 417, serverSource);
@ -111,10 +112,18 @@ public class TestMetricsRegionServer {
HELPER.assertGauge("blockCacheCountHitPercent", 98, serverSource);
HELPER.assertGauge("blockCacheExpressHitPercent", 97, serverSource);
HELPER.assertCounter("blockCacheFailedInsertionCount", 36, serverSource);
HELPER.assertGauge("l1CacheFreeSize", 100, serverSource);
HELPER.assertGauge("l1CacheSize", 123, serverSource);
HELPER.assertGauge("l1CacheCount", 50, serverSource);
HELPER.assertCounter("l1CacheEvictionCount", 1000, serverSource);
HELPER.assertGauge("l1CacheHitCount", 200, serverSource);
HELPER.assertGauge("l1CacheMissCount", 100, serverSource);
HELPER.assertGauge("l1CacheHitRatio", 80, serverSource);
HELPER.assertGauge("l1CacheMissRatio", 20, serverSource);
HELPER.assertGauge("l2CacheFreeSize", 200, serverSource);
HELPER.assertGauge("l2CacheSize", 456, serverSource);
HELPER.assertGauge("l2CacheCount", 75, serverSource);
HELPER.assertCounter("l2CacheEvictionCount", 2000, serverSource);
HELPER.assertGauge("l2CacheHitCount", 800, serverSource);
HELPER.assertGauge("l2CacheMissCount", 200, serverSource);
HELPER.assertGauge("l2CacheHitRatio", 90, serverSource);