You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by ka...@apache.org on 2015/09/02 00:39:14 UTC

[1/3] storm git commit: Created QueueMetrics inner class in DistruptorQueue to improve the extendibility and the readability of the metrics code.

Repository: storm
Updated Branches:
  refs/heads/master 3ff465c5c -> fec4b53fe


Created QueueMetrics inner class in DistruptorQueue to improve the extendibility and the readability of the metrics code.


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/4337ebe6
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/4337ebe6
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/4337ebe6

Branch: refs/heads/master
Commit: 4337ebe6e2398073e9a238e88bd51ca7b76b3437
Parents: 528958c
Author: wangli1426 <wa...@gmail.com>
Authored: Wed Aug 26 12:48:27 2015 +0800
Committer: wangli1426 <wa...@gmail.com>
Committed: Wed Aug 26 12:48:27 2015 +0800

----------------------------------------------------------------------
 .../backtype/storm/utils/DisruptorQueue.java    | 127 ++++++++++++-------
 1 file changed, 82 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/4337ebe6/storm-core/src/jvm/backtype/storm/utils/DisruptorQueue.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/utils/DisruptorQueue.java b/storm-core/src/jvm/backtype/storm/utils/DisruptorQueue.java
index 4d3f18b..c922ca5 100644
--- a/storm-core/src/jvm/backtype/storm/utils/DisruptorQueue.java
+++ b/storm-core/src/jvm/backtype/storm/utils/DisruptorQueue.java
@@ -45,31 +45,35 @@ import backtype.storm.metric.api.IStatefulObject;
 public class DisruptorQueue implements IStatefulObject {
     static final Object FLUSH_CACHE = new Object();
     static final Object INTERRUPT = new Object();
-    
+
     RingBuffer<MutableObject> _buffer;
     Sequence _consumer;
     SequenceBarrier _barrier;
-    
+
     // TODO: consider having a threadlocal cache of this variable to speed up reads?
     volatile boolean consumerStartedFlag = false;
     ConcurrentLinkedQueue<Object> _cache = new ConcurrentLinkedQueue();
-    
+
     private final ReentrantReadWriteLock cacheLock = new ReentrantReadWriteLock();
-    private final Lock readLock  = cacheLock.readLock();
+    private final Lock readLock = cacheLock.readLock();
     private final Lock writeLock = cacheLock.writeLock();
-    
+
     private static String PREFIX = "disruptor-";
     private String _queueName = "";
 
     private long _waitTimeout;
-    
+
+    private final QueueMetrics _metrics;
+
     public DisruptorQueue(String queueName, ClaimStrategy claim, WaitStrategy wait, long timeout) {
-         this._queueName = PREFIX + queueName;
+        this._queueName = PREFIX + queueName;
         _buffer = new RingBuffer<MutableObject>(new ObjectEventFactory(), claim, wait);
         _consumer = new Sequence();
         _barrier = _buffer.newBarrier();
         _buffer.setGatingSequences(_consumer);
-        if(claim instanceof SingleThreadedClaimStrategy) {
+        _metrics = new QueueMetrics();
+
+        if (claim instanceof SingleThreadedClaimStrategy) {
             consumerStartedFlag = true;
         } else {
             // make sure we flush the pending messages in cache first
@@ -82,19 +86,19 @@ public class DisruptorQueue implements IStatefulObject {
 
         _waitTimeout = timeout;
     }
-    
+
     public String getName() {
-      return _queueName;
+        return _queueName;
     }
-    
+
     public void consumeBatch(EventHandler<Object> handler) {
         consumeBatchToCursor(_barrier.getCursor(), handler);
     }
-    
+
     public void haltWithInterrupt() {
         publish(INTERRUPT);
     }
-    
+
     public void consumeBatchWhenAvailable(EventHandler<Object> handler) {
         try {
             final long nextSequence = _consumer.get() + 1;
@@ -111,22 +115,22 @@ public class DisruptorQueue implements IStatefulObject {
             throw new RuntimeException(e);
         }
     }
-    
-    
+
+
     private void consumeBatchToCursor(long cursor, EventHandler<Object> handler) {
-        for(long curr = _consumer.get() + 1; curr <= cursor; curr++) {
+        for (long curr = _consumer.get() + 1; curr <= cursor; curr++) {
             try {
                 MutableObject mo = _buffer.get(curr);
                 Object o = mo.o;
                 mo.setObject(null);
-                if(o==FLUSH_CACHE) {
+                if (o == FLUSH_CACHE) {
                     Object c = null;
-                    while(true) {                        
+                    while (true) {
                         c = _cache.poll();
-                        if(c==null) break;
+                        if (c == null) break;
                         else handler.onEvent(c, curr, true);
                     }
-                } else if(o==INTERRUPT) {
+                } else if (o == INTERRUPT) {
                     throw new InterruptedException("Disruptor processing interrupted");
                 } else {
                     handler.onEvent(o, curr, curr == cursor);
@@ -138,7 +142,7 @@ public class DisruptorQueue implements IStatefulObject {
         //TODO: only set this if the consumer cursor has changed?
         _consumer.set(cursor);
     }
-    
+
     /*
      * Caches until consumerStarted is called, upon which the cache is flushed to the consumer
      */
@@ -149,17 +153,17 @@ public class DisruptorQueue implements IStatefulObject {
             throw new RuntimeException("This code should be unreachable!");
         }
     }
-    
+
     public void tryPublish(Object obj) throws InsufficientCapacityException {
         publish(obj, false);
     }
-    
+
     public void publish(Object obj, boolean block) throws InsufficientCapacityException {
 
         boolean publishNow = consumerStartedFlag;
 
         if (!publishNow) {
-            readLock.lock(); 
+            readLock.lock();
             try {
                 publishNow = consumerStartedFlag;
                 if (!publishNow) {
@@ -169,15 +173,15 @@ public class DisruptorQueue implements IStatefulObject {
                 readLock.unlock();
             }
         }
-        
+
         if (publishNow) {
             publishDirect(obj, block);
         }
     }
-    
+
     private void publishDirect(Object obj, boolean block) throws InsufficientCapacityException {
         final long id;
-        if(block) {
+        if (block) {
             id = _buffer.next();
         } else {
             id = _buffer.tryNext(1);
@@ -186,39 +190,72 @@ public class DisruptorQueue implements IStatefulObject {
         m.setObject(obj);
         _buffer.publish(id);
     }
-    
+
     public void consumerStarted() {
 
         consumerStartedFlag = true;
-        
+
         // Use writeLock to make sure all pending cache add opearation completed
         writeLock.lock();
         writeLock.unlock();
     }
-    
-    public long  population() { return (writePos() - readPos()); }
-    public long  capacity()   { return _buffer.getBufferSize(); }
-    public long  writePos()   { return _buffer.getCursor(); }
-    public long  readPos()    { return _consumer.get(); }
-    public float pctFull()    { return (1.0F * population() / capacity()); }
 
     @Override
     public Object getState() {
-        Map state = new HashMap<String, Object>();
-        // get readPos then writePos so it's never an under-estimate
-        long rp = readPos();
-        long wp = writePos();
-        state.put("capacity",   capacity());
-        state.put("population", wp - rp);
-        state.put("write_pos",  wp);
-        state.put("read_pos",   rp);
-        return state;
+        return _metrics.getState();
     }
 
     public static class ObjectEventFactory implements EventFactory<MutableObject> {
         @Override
         public MutableObject newInstance() {
             return new MutableObject();
-        }        
+        }
     }
+
+    //This method enables the metrics to be accessed from outside of the DisruptorQueue class
+    public QueueMetrics getMetrics() {
+        return _metrics;
+    }
+
+
+    /**
+     * This inner class provides methods to access the metrics of the disruptor queue.
+     */
+    public class QueueMetrics {
+
+        public long writePos() {
+            return _buffer.getCursor();
+        }
+
+        public long readPos() {
+            return _consumer.get();
+        }
+
+        public long population() {
+            return writePos() - readPos();
+        }
+
+        public long capacity() {
+            return _buffer.getBufferSize();
+        }
+
+        public float pctFull() {
+            return (1.0F * population() / capacity());
+        }
+
+        public Object getState() {
+            Map state = new HashMap<String, Object>();
+
+            // get readPos then writePos so it's never an under-estimate
+            long rp = readPos();
+            long wp = writePos();
+            state.put("capacity", capacity());
+            state.put("population", wp - rp);
+            state.put("write_pos", wp);
+            state.put("read_pos", rp);
+
+            return state;
+        }
+    }
+
 }


[2/3] storm git commit: Merge branch 'master' of https://github.com/wangli1426/storm into STORM-1008

Posted by ka...@apache.org.
Merge branch 'master' of https://github.com/wangli1426/storm into STORM-1008


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

Branch: refs/heads/master
Commit: cce0362713102c8620b98e69ad1da9aa6ba6b3c4
Parents: 3ff465c 4337ebe
Author: Jungtaek Lim <ka...@gmail.com>
Authored: Wed Sep 2 07:22:03 2015 +0900
Committer: Jungtaek Lim <ka...@gmail.com>
Committed: Wed Sep 2 07:22:03 2015 +0900

----------------------------------------------------------------------
 .../backtype/storm/utils/DisruptorQueue.java    | 127 ++++++++++++-------
 1 file changed, 82 insertions(+), 45 deletions(-)
----------------------------------------------------------------------



[3/3] storm git commit: add STORM-1008 to CHANGELOG.md

Posted by ka...@apache.org.
add STORM-1008 to CHANGELOG.md


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

Branch: refs/heads/master
Commit: fec4b53fef52dfe47b9db7e626733b8981e0fdd5
Parents: cce0362
Author: Jungtaek Lim <ka...@gmail.com>
Authored: Wed Sep 2 07:38:51 2015 +0900
Committer: Jungtaek Lim <ka...@gmail.com>
Committed: Wed Sep 2 07:38:51 2015 +0900

----------------------------------------------------------------------
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/fec4b53f/CHANGELOG.md
----------------------------------------------------------------------
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e384de7..1698145 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
 ## 0.11.0
+ * STORM-1008: Isolate the code for metric collection and retrieval from DisruptorQueue
  * STORM-991: General cleanup of the generics (storm.trident.spout package)
  * STORM-1000: Use static member classes when permitted 
  * STORM-1003: In cluster.clj replace task-id with component-id in the declaration