HBASE-14936 CombinedBlockCache should overwrite CacheStats#rollMetricsPeriod() (Jianwei Cui)
This commit is contained in:
parent
555d9b70bd
commit
04622254f7
|
@ -260,13 +260,14 @@ public class CacheStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHitRatioPastNPeriods() {
|
public double getHitRatioPastNPeriods() {
|
||||||
double ratio = ((double)sum(hitCounts)/(double)sum(requestCounts));
|
double ratio = ((double)getSumHitCountsPastNPeriods() /
|
||||||
|
(double)getSumRequestCountsPastNPeriods());
|
||||||
return Double.isNaN(ratio) ? 0 : ratio;
|
return Double.isNaN(ratio) ? 0 : ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getHitCachingRatioPastNPeriods() {
|
public double getHitCachingRatioPastNPeriods() {
|
||||||
double ratio =
|
double ratio = ((double)getSumHitCachingCountsPastNPeriods() /
|
||||||
((double)sum(hitCachingCounts)/(double)sum(requestCachingCounts));
|
(double)getSumRequestCachingCountsPastNPeriods());
|
||||||
return Double.isNaN(ratio) ? 0 : ratio;
|
return Double.isNaN(ratio) ? 0 : ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,22 +203,38 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getHitRatioPastNPeriods() {
|
public void rollMetricsPeriod() {
|
||||||
double ratio = ((double) (lruCacheStats.getSumHitCountsPastNPeriods() + bucketCacheStats
|
lruCacheStats.rollMetricsPeriod();
|
||||||
.getSumHitCountsPastNPeriods()) / (double) (lruCacheStats
|
bucketCacheStats.rollMetricsPeriod();
|
||||||
.getSumRequestCountsPastNPeriods() + bucketCacheStats
|
|
||||||
.getSumRequestCountsPastNPeriods()));
|
|
||||||
return Double.isNaN(ratio) ? 0 : ratio;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getHitCachingRatioPastNPeriods() {
|
public long getFailedInserts() {
|
||||||
double ratio = ((double) (lruCacheStats
|
return lruCacheStats.getFailedInserts() + bucketCacheStats.getFailedInserts();
|
||||||
.getSumHitCachingCountsPastNPeriods() + bucketCacheStats
|
}
|
||||||
.getSumHitCachingCountsPastNPeriods()) / (double) (lruCacheStats
|
|
||||||
.getSumRequestCachingCountsPastNPeriods() + bucketCacheStats
|
@Override
|
||||||
.getSumRequestCachingCountsPastNPeriods()));
|
public long getSumHitCountsPastNPeriods() {
|
||||||
return Double.isNaN(ratio) ? 0 : ratio;
|
return lruCacheStats.getSumHitCountsPastNPeriods()
|
||||||
|
+ bucketCacheStats.getSumHitCountsPastNPeriods();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSumRequestCountsPastNPeriods() {
|
||||||
|
return lruCacheStats.getSumRequestCountsPastNPeriods()
|
||||||
|
+ bucketCacheStats.getSumRequestCountsPastNPeriods();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSumHitCachingCountsPastNPeriods() {
|
||||||
|
return lruCacheStats.getSumHitCachingCountsPastNPeriods()
|
||||||
|
+ bucketCacheStats.getSumHitCachingCountsPastNPeriods();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSumRequestCachingCountsPastNPeriods() {
|
||||||
|
return lruCacheStats.getSumRequestCachingCountsPastNPeriods()
|
||||||
|
+ bucketCacheStats.getSumRequestCachingCountsPastNPeriods();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.hbase.io.hfile;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import org.apache.hadoop.hbase.io.hfile.CombinedBlockCache.CombinedCacheStats;
|
||||||
|
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
@Category({SmallTests.class})
|
||||||
|
public class TestCombinedBlockCache {
|
||||||
|
@Test
|
||||||
|
public void testCombinedCacheStats() {
|
||||||
|
CacheStats lruCacheStats = new CacheStats("lruCacheStats", 2);
|
||||||
|
CacheStats bucketCacheStats = new CacheStats("bucketCacheStats", 2);
|
||||||
|
CombinedCacheStats stats =
|
||||||
|
new CombinedCacheStats(lruCacheStats, bucketCacheStats);
|
||||||
|
|
||||||
|
double delta = 0.01;
|
||||||
|
|
||||||
|
// period 1:
|
||||||
|
// lru cache: 1 hit caching, 1 miss caching
|
||||||
|
// bucket cache: 2 hit non-caching,1 miss non-caching/primary,1 fail insert
|
||||||
|
lruCacheStats.hit(true);
|
||||||
|
lruCacheStats.miss(true, false);
|
||||||
|
bucketCacheStats.hit(false);
|
||||||
|
bucketCacheStats.hit(false);
|
||||||
|
bucketCacheStats.miss(false, true);
|
||||||
|
|
||||||
|
assertEquals(5, stats.getRequestCount());
|
||||||
|
assertEquals(2, stats.getRequestCachingCount());
|
||||||
|
assertEquals(2, stats.getMissCount());
|
||||||
|
assertEquals(1, stats.getPrimaryMissCount());
|
||||||
|
assertEquals(1, stats.getMissCachingCount());
|
||||||
|
assertEquals(3, stats.getHitCount());
|
||||||
|
assertEquals(3, stats.getPrimaryHitCount());
|
||||||
|
assertEquals(1, stats.getHitCachingCount());
|
||||||
|
assertEquals(0.6, stats.getHitRatio(), delta);
|
||||||
|
assertEquals(0.5, stats.getHitCachingRatio(), delta);
|
||||||
|
assertEquals(0.4, stats.getMissRatio(), delta);
|
||||||
|
assertEquals(0.5, stats.getMissCachingRatio(), delta);
|
||||||
|
|
||||||
|
|
||||||
|
// lru cache: 2 evicted, 1 evict
|
||||||
|
// bucket cache: 1 evict
|
||||||
|
lruCacheStats.evicted(1000, true);
|
||||||
|
lruCacheStats.evicted(1000, false);
|
||||||
|
lruCacheStats.evict();
|
||||||
|
bucketCacheStats.evict();
|
||||||
|
assertEquals(2, stats.getEvictionCount());
|
||||||
|
assertEquals(2, stats.getEvictedCount());
|
||||||
|
assertEquals(1, stats.getPrimaryEvictedCount());
|
||||||
|
assertEquals(1.0, stats.evictedPerEviction(), delta);
|
||||||
|
|
||||||
|
// lru cache: 1 fail insert
|
||||||
|
lruCacheStats.failInsert();
|
||||||
|
assertEquals(1, stats.getFailedInserts());
|
||||||
|
|
||||||
|
// rollMetricsPeriod
|
||||||
|
stats.rollMetricsPeriod();
|
||||||
|
assertEquals(3, stats.getSumHitCountsPastNPeriods());
|
||||||
|
assertEquals(5, stats.getSumRequestCountsPastNPeriods());
|
||||||
|
assertEquals(1, stats.getSumHitCachingCountsPastNPeriods());
|
||||||
|
assertEquals(2, stats.getSumRequestCachingCountsPastNPeriods());
|
||||||
|
assertEquals(0.6, stats.getHitRatioPastNPeriods(), delta);
|
||||||
|
assertEquals(0.5, stats.getHitCachingRatioPastNPeriods(), delta);
|
||||||
|
|
||||||
|
// period 2:
|
||||||
|
// lru cache: 3 hit caching
|
||||||
|
lruCacheStats.hit(true);
|
||||||
|
lruCacheStats.hit(true);
|
||||||
|
lruCacheStats.hit(true);
|
||||||
|
stats.rollMetricsPeriod();
|
||||||
|
assertEquals(6, stats.getSumHitCountsPastNPeriods());
|
||||||
|
assertEquals(8, stats.getSumRequestCountsPastNPeriods());
|
||||||
|
assertEquals(4, stats.getSumHitCachingCountsPastNPeriods());
|
||||||
|
assertEquals(5, stats.getSumRequestCachingCountsPastNPeriods());
|
||||||
|
assertEquals(0.75, stats.getHitRatioPastNPeriods(), delta);
|
||||||
|
assertEquals(0.8, stats.getHitCachingRatioPastNPeriods(), delta);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue