incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/2] git commit: Added in cache metrics.
Date Fri, 08 Mar 2013 02:53:45 GMT
Added in cache metrics.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/b298c086
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/b298c086
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/b298c086

Branch: refs/heads/0.2-dev
Commit: b298c0868e8b6a5fd08d11cd2f66c88a17ae72ee
Parents: 6cb3402
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Thu Mar 7 21:46:54 2013 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Thu Mar 7 21:46:54 2013 -0500

----------------------------------------------------------------------
 .../apache/blur/store/blockcache/BlockCache.java   |   10 +++++++
 .../blur/store/blockcache/BlockDirectoryCache.java |   21 ++++++++++++++-
 .../org/apache/blur/metrics/MetricsConstants.java  |    4 +++
 3 files changed, 34 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b298c086/src/blur-store/src/main/java/org/apache/blur/store/blockcache/BlockCache.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/store/blockcache/BlockCache.java
b/src/blur-store/src/main/java/org/apache/blur/store/blockcache/BlockCache.java
index 70b2860..b2947b9 100644
--- a/src/blur-store/src/main/java/org/apache/blur/store/blockcache/BlockCache.java
+++ b/src/blur-store/src/main/java/org/apache/blur/store/blockcache/BlockCache.java
@@ -16,12 +16,18 @@ package org.apache.blur.store.blockcache;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+import static org.apache.blur.metrics.MetricsConstants.*;
+
 import java.nio.ByteBuffer;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
 import com.googlecode.concurrentlinkedhashmap.EvictionListener;
+import com.yammer.metrics.Metrics;
+import com.yammer.metrics.core.Meter;
+import com.yammer.metrics.core.MetricName;
 
 public class BlockCache {
 
@@ -34,6 +40,7 @@ public class BlockCache {
   private final int _blockSize = _8K;
   private final int _numberOfBlocksPerSlab;
   private final int _maxEntries;
+  private Meter evictions;
 
   public BlockCache(boolean directAllocation, long totalMemory) {
     this(directAllocation, totalMemory, _128M);
@@ -56,11 +63,14 @@ public class BlockCache {
       _locks[i] = new BlockLocks(_numberOfBlocksPerSlab);
       _lockCounters[i] = new AtomicInteger();
     }
+    
+    evictions = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, CACHE, EVICTION), EVICTION,
TimeUnit.SECONDS);
 
     EvictionListener<BlockCacheKey, BlockCacheLocation> listener = new EvictionListener<BlockCacheKey,
BlockCacheLocation>() {
       @Override
       public void onEviction(BlockCacheKey key, BlockCacheLocation location) {
         releaseLocation(location);
+        evictions.mark();
       }
     };
     _cache = new ConcurrentLinkedHashMap.Builder<BlockCacheKey, BlockCacheLocation>().maximumWeightedCapacity(_maxEntries).listener(listener).build();

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b298c086/src/blur-store/src/main/java/org/apache/blur/store/blockcache/BlockDirectoryCache.java
----------------------------------------------------------------------
diff --git a/src/blur-store/src/main/java/org/apache/blur/store/blockcache/BlockDirectoryCache.java
b/src/blur-store/src/main/java/org/apache/blur/store/blockcache/BlockDirectoryCache.java
index 17155c9..f6e8b10 100644
--- a/src/blur-store/src/main/java/org/apache/blur/store/blockcache/BlockDirectoryCache.java
+++ b/src/blur-store/src/main/java/org/apache/blur/store/blockcache/BlockDirectoryCache.java
@@ -16,18 +16,32 @@ package org.apache.blur.store.blockcache;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+import static org.apache.blur.metrics.MetricsConstants.CACHE;
+import static org.apache.blur.metrics.MetricsConstants.HIT;
+import static org.apache.blur.metrics.MetricsConstants.MISS;
+import static org.apache.blur.metrics.MetricsConstants.ORG_APACHE_BLUR;
+
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import com.yammer.metrics.Metrics;
+import com.yammer.metrics.core.Meter;
+import com.yammer.metrics.core.MetricName;
 
 public class BlockDirectoryCache implements Cache {
+
   private BlockCache _blockCache;
   private AtomicInteger _counter = new AtomicInteger();
   private Map<String, Integer> _names = new ConcurrentHashMap<String, Integer>();
+  private Meter hits;
+  private Meter misses;
 
   public BlockDirectoryCache(BlockCache blockCache) {
     _blockCache = blockCache;
+    hits = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, CACHE, HIT), HIT, TimeUnit.SECONDS);
+    misses = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, CACHE, MISS), MISS, TimeUnit.SECONDS);
   }
 
   @Override
@@ -45,7 +59,7 @@ public class BlockDirectoryCache implements Cache {
     BlockCacheKey blockCacheKey = new BlockCacheKey();
     blockCacheKey.setBlock(blockId);
     blockCacheKey.setFile(file);
-    _blockCache.store(blockCacheKey, blockOffset, buffer, offset, length);  
+    _blockCache.store(blockCacheKey, blockOffset, buffer, offset, length);
   }
 
   @Override
@@ -58,6 +72,11 @@ public class BlockDirectoryCache implements Cache {
     blockCacheKey.setBlock(blockId);
     blockCacheKey.setFile(file);
     boolean fetch = _blockCache.fetch(blockCacheKey, b, blockOffset, off, lengthToReadInBlock);
+    if (fetch) {
+      hits.mark();
+    } else {
+      misses.mark();
+    }
     return fetch;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/b298c086/src/blur-util/src/main/java/org/apache/blur/metrics/MetricsConstants.java
----------------------------------------------------------------------
diff --git a/src/blur-util/src/main/java/org/apache/blur/metrics/MetricsConstants.java b/src/blur-util/src/main/java/org/apache/blur/metrics/MetricsConstants.java
index 1d0ee9c..f5e0a09 100644
--- a/src/blur-util/src/main/java/org/apache/blur/metrics/MetricsConstants.java
+++ b/src/blur-util/src/main/java/org/apache/blur/metrics/MetricsConstants.java
@@ -18,4 +18,8 @@ public class MetricsConstants {
   public static final String REMOTE = "remote";
   public static final String HDFS = "HDFS";
   public static final String LOCAL = "local";
+  public static final String HIT = "Hit";
+  public static final String MISS = "Miss";
+  public static final String CACHE = "Cache";
+  public static final String EVICTION = "Eviction";
 }


Mime
View raw message