hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chenh...@apache.org
Subject hbase git commit: HBASE-14936 CombinedBlockCache should overwrite CacheStats#rollMetricsPeriod() (Jianwei Cui)
Date Mon, 14 Dec 2015 09:39:45 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 9e6acffca -> 3b9b8cc66


HBASE-14936 CombinedBlockCache should overwrite CacheStats#rollMetricsPeriod() (Jianwei Cui)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/3b9b8cc6
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/3b9b8cc6
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/3b9b8cc6

Branch: refs/heads/branch-1
Commit: 3b9b8cc667d3a7ffb3473ac8f181f27cff8c1a4e
Parents: 9e6acff
Author: chenheng <chenheng@apache.org>
Authored: Mon Dec 14 17:20:50 2015 +0800
Committer: chenheng <chenheng@apache.org>
Committed: Mon Dec 14 17:34:16 2015 +0800

----------------------------------------------------------------------
 .../hadoop/hbase/io/hfile/CacheStats.java       |  7 +-
 .../hbase/io/hfile/CombinedBlockCache.java      | 48 ++++++----
 .../hbase/io/hfile/TestCombinedBlockCache.java  | 98 ++++++++++++++++++++
 3 files changed, 134 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/3b9b8cc6/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheStats.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheStats.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheStats.java
index 2dae66f..fff6585 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheStats.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheStats.java
@@ -260,13 +260,14 @@ public class CacheStats {
   }
 
   public double getHitRatioPastNPeriods() {
-    double ratio = ((double)sum(hitCounts)/(double)sum(requestCounts));
+    double ratio = ((double)getSumHitCountsPastNPeriods() /
+        (double)getSumRequestCountsPastNPeriods());
     return Double.isNaN(ratio) ? 0 : ratio;
   }
 
   public double getHitCachingRatioPastNPeriods() {
-    double ratio =
-      ((double)sum(hitCachingCounts)/(double)sum(requestCachingCounts));
+    double ratio = ((double)getSumHitCachingCountsPastNPeriods() /
+        (double)getSumRequestCachingCountsPastNPeriods());
     return Double.isNaN(ratio) ? 0 : ratio;
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/3b9b8cc6/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CombinedBlockCache.java
----------------------------------------------------------------------
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 fbc19a0..ed6a4bb 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
@@ -201,22 +201,38 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize
{
     }
 
     @Override
-    public double getHitRatioPastNPeriods() {
-      double ratio = ((double) (lruCacheStats.getSumHitCountsPastNPeriods() + bucketCacheStats
-          .getSumHitCountsPastNPeriods()) / (double) (lruCacheStats
-          .getSumRequestCountsPastNPeriods() + bucketCacheStats
-          .getSumRequestCountsPastNPeriods()));
-      return Double.isNaN(ratio) ? 0 : ratio;
-    }
-
-    @Override
-    public double getHitCachingRatioPastNPeriods() {
-      double ratio = ((double) (lruCacheStats
-          .getSumHitCachingCountsPastNPeriods() + bucketCacheStats
-          .getSumHitCachingCountsPastNPeriods()) / (double) (lruCacheStats
-          .getSumRequestCachingCountsPastNPeriods() + bucketCacheStats
-          .getSumRequestCachingCountsPastNPeriods()));
-      return Double.isNaN(ratio) ? 0 : ratio;
+    public void rollMetricsPeriod() {
+      lruCacheStats.rollMetricsPeriod();
+      bucketCacheStats.rollMetricsPeriod();
+    }
+    
+    @Override
+    public long getFailedInserts() {
+      return lruCacheStats.getFailedInserts() + bucketCacheStats.getFailedInserts();
+    }
+
+    @Override
+    public long getSumHitCountsPastNPeriods() {
+      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();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/3b9b8cc6/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCombinedBlockCache.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCombinedBlockCache.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCombinedBlockCache.java
new file mode 100644
index 0000000..50bf331
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestCombinedBlockCache.java
@@ -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);
+  }
+}


Mime
View raw message