You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by bo...@apache.org on 2014/11/26 23:34:41 UTC
[03/21] storm git commit: Revert "Merge branch 'disruptor-update' of
https://github.com/miofthena/incubator-storm into STORM-350"
Revert "Merge branch 'disruptor-update' of https://github.com/miofthena/incubator-storm into STORM-350"
This reverts commit 78c5e231f679c84d14258d190c8658f8d0b98ad3, reversing
changes made to 9ac011129dc90418b9e8210abf0ff8e9f60be656.
Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/2ad95f69
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/2ad95f69
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/2ad95f69
Branch: refs/heads/master
Commit: 2ad95f694c9e0211f611a2f19426b6872190de4c
Parents: a725b23
Author: P. Taylor Goetz <pt...@gmail.com>
Authored: Mon Nov 17 14:39:03 2014 -0500
Committer: P. Taylor Goetz <pt...@gmail.com>
Committed: Mon Nov 17 14:39:03 2014 -0500
----------------------------------------------------------------------
pom.xml | 4 +-
storm-core/pom.xml | 2 +-
storm-core/src/clj/backtype/storm/disruptor.clj | 11 ++--
.../backtype/storm/utils/DisruptorQueue.java | 56 ++++++++++----------
.../storm/utils/DisruptorQueueTest.java | 25 ++++-----
5 files changed, 50 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/storm/blob/2ad95f69/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b63d332..e2b1a45 100644
--- a/pom.xml
+++ b/pom.xml
@@ -196,7 +196,7 @@
<snakeyaml.version>1.11</snakeyaml.version>
<httpclient.version>4.3.3</httpclient.version>
<clojure.tools.cli.version>0.2.4</clojure.tools.cli.version>
- <disruptor.version>3.2.1</disruptor.version>
+ <disruptor.version>2.10.1</disruptor.version>
<jgrapht.version>0.9.0</jgrapht.version>
<guava.version>16.0.1</guava.version>
<logback-classic.version>1.0.13</logback-classic.version>
@@ -419,7 +419,7 @@
<version>${clojure.tools.cli.version}</version>
</dependency>
<dependency>
- <groupId>com.lmax</groupId>
+ <groupId>com.googlecode.disruptor</groupId>
<artifactId>disruptor</artifactId>
<version>${disruptor.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/storm/blob/2ad95f69/storm-core/pom.xml
----------------------------------------------------------------------
diff --git a/storm-core/pom.xml b/storm-core/pom.xml
index 20bb82a..67f1eae 100644
--- a/storm-core/pom.xml
+++ b/storm-core/pom.xml
@@ -148,7 +148,7 @@
</dependency>
<dependency>
- <groupId>com.lmax</groupId>
+ <groupId>com.googlecode.disruptor</groupId>
<artifactId>disruptor</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/storm/blob/2ad95f69/storm-core/src/clj/backtype/storm/disruptor.clj
----------------------------------------------------------------------
diff --git a/storm-core/src/clj/backtype/storm/disruptor.clj b/storm-core/src/clj/backtype/storm/disruptor.clj
index 2bbeebd..a723601 100644
--- a/storm-core/src/clj/backtype/storm/disruptor.clj
+++ b/storm-core/src/clj/backtype/storm/disruptor.clj
@@ -16,17 +16,17 @@
(ns backtype.storm.disruptor
(:import [backtype.storm.utils DisruptorQueue])
- (:import [com.lmax.disruptor BlockingWaitStrategy SleepingWaitStrategy YieldingWaitStrategy
+ (:import [com.lmax.disruptor MultiThreadedClaimStrategy SingleThreadedClaimStrategy
+ BlockingWaitStrategy SleepingWaitStrategy YieldingWaitStrategy
BusySpinWaitStrategy])
- (:import [com.lmax.disruptor.dsl ProducerType])
(:require [clojure [string :as str]])
(:require [clojure [set :as set]])
(:use [clojure walk])
(:use [backtype.storm util log]))
(def CLAIM-STRATEGY
- {:multi-threaded (ProducerType/MULTI)
- :single-threaded (ProducerType/SINGLE)})
+ {:multi-threaded (fn [size] (MultiThreadedClaimStrategy. (int size)))
+ :single-threaded (fn [size] (SingleThreadedClaimStrategy. (int size)))})
(def WAIT-STRATEGY
{:block (fn [] (BlockingWaitStrategy.))
@@ -47,8 +47,7 @@
(defnk disruptor-queue
[^String queue-name buffer-size :claim-strategy :multi-threaded :wait-strategy :block]
(DisruptorQueue. queue-name
- (CLAIM-STRATEGY claim-strategy)
- buffer-size
+ ((CLAIM-STRATEGY claim-strategy) buffer-size)
(mk-wait-strategy wait-strategy)))
(defn clojure-handler
http://git-wip-us.apache.org/repos/asf/storm/blob/2ad95f69/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 7c56fe5..932af16 100644
--- a/storm-core/src/jvm/backtype/storm/utils/DisruptorQueue.java
+++ b/storm-core/src/jvm/backtype/storm/utils/DisruptorQueue.java
@@ -18,53 +18,56 @@
package backtype.storm.utils;
import com.lmax.disruptor.AlertException;
+import com.lmax.disruptor.ClaimStrategy;
import com.lmax.disruptor.EventFactory;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.InsufficientCapacityException;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.Sequence;
import com.lmax.disruptor.SequenceBarrier;
-import com.lmax.disruptor.TimeoutException;
+import com.lmax.disruptor.SingleThreadedClaimStrategy;
import com.lmax.disruptor.WaitStrategy;
-import com.lmax.disruptor.dsl.ProducerType;
import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.HashMap;
+import java.util.Map;
import backtype.storm.metric.api.IStatefulObject;
+
/**
*
* A single consumer queue that uses the LMAX Disruptor. They key to the performance is
* the ability to catch up to the producer by processing tuples in batches.
*/
public class DisruptorQueue implements IStatefulObject {
- private static final Object FLUSH_CACHE = new Object();
- private static final Object INTERRUPT = new Object();
- private static final String PREFIX = "disruptor-";
-
- private final String _queueName;
- private final RingBuffer<MutableObject> _buffer;
- private final Sequence _consumer;
- private final SequenceBarrier _barrier;
-
+ 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;
-
- private final HashMap<String, Object> state = new HashMap<String, Object>(4);
- private final ConcurrentLinkedQueue<Object> _cache = new ConcurrentLinkedQueue<Object>();
+ ConcurrentLinkedQueue<Object> _cache = new ConcurrentLinkedQueue();
+
private final ReentrantReadWriteLock cacheLock = new ReentrantReadWriteLock();
private final Lock readLock = cacheLock.readLock();
private final Lock writeLock = cacheLock.writeLock();
-
- public DisruptorQueue(String queueName, ProducerType producerType, int bufferSize, WaitStrategy wait) {
- this._queueName = PREFIX + queueName;
- _buffer = RingBuffer.create(producerType, new ObjectEventFactory(), bufferSize, wait);
+
+ private static String PREFIX = "disruptor-";
+ private String _queueName = "";
+
+ public DisruptorQueue(String queueName, ClaimStrategy claim, WaitStrategy wait) {
+ this._queueName = PREFIX + queueName;
+ _buffer = new RingBuffer<MutableObject>(new ObjectEventFactory(), claim, wait);
_consumer = new Sequence();
_barrier = _buffer.newBarrier();
- _buffer.addGatingSequences(_consumer);
- if(producerType == ProducerType.SINGLE) {
+ _buffer.setGatingSequences(_consumer);
+ if(claim instanceof SingleThreadedClaimStrategy) {
consumerStartedFlag = true;
} else {
// make sure we flush the pending messages in cache first
@@ -87,11 +90,11 @@ public class DisruptorQueue implements IStatefulObject {
public void haltWithInterrupt() {
publish(INTERRUPT);
}
-
+
public void consumeBatchWhenAvailable(EventHandler<Object> handler) {
try {
final long nextSequence = _consumer.get() + 1;
- final long availableSequence = _barrier.waitFor(nextSequence);
+ final long availableSequence = _barrier.waitFor(nextSequence, 10, TimeUnit.MILLISECONDS);
if(availableSequence >= nextSequence) {
consumeBatchToCursor(availableSequence, handler);
}
@@ -99,8 +102,6 @@ public class DisruptorQueue implements IStatefulObject {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
- } catch (TimeoutException e) {
- throw new RuntimeException(e);
}
}
@@ -130,7 +131,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
*/
@@ -141,11 +142,11 @@ 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;
@@ -196,6 +197,7 @@ public class DisruptorQueue implements IStatefulObject {
@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();
http://git-wip-us.apache.org/repos/asf/storm/blob/2ad95f69/storm-core/test/jvm/backtype/storm/utils/DisruptorQueueTest.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/backtype/storm/utils/DisruptorQueueTest.java b/storm-core/test/jvm/backtype/storm/utils/DisruptorQueueTest.java
index 835b4d9..653fd33 100644
--- a/storm-core/test/jvm/backtype/storm/utils/DisruptorQueueTest.java
+++ b/storm-core/test/jvm/backtype/storm/utils/DisruptorQueueTest.java
@@ -17,15 +17,15 @@
*/
package backtype.storm.utils;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.InsufficientCapacityException;
-import com.lmax.disruptor.dsl.ProducerType;
-import junit.framework.TestCase;
+import com.lmax.disruptor.MultiThreadedClaimStrategy;
import org.junit.Assert;
import org.junit.Test;
-
-import java.util.concurrent.atomic.AtomicBoolean;
+import junit.framework.TestCase;
public class DisruptorQueueTest extends TestCase {
@@ -42,7 +42,7 @@ public class DisruptorQueueTest extends TestCase {
Runnable producer = new Producer(queue, "2");
- final Object[] result = new Object[1];
+ final Object [] result = new Object[1];
Runnable consumer = new Consumer(queue, new EventHandler<Object>() {
private boolean head = true;
@@ -60,8 +60,8 @@ public class DisruptorQueueTest extends TestCase {
Assert.assertEquals("We expect to receive first published message first, but received " + result[0],
"1", result[0]);
}
-
- @Test
+
+ @Test
public void testConsumerHang() throws InterruptedException {
final AtomicBoolean messageConsumed = new AtomicBoolean(false);
@@ -91,10 +91,10 @@ public class DisruptorQueueTest extends TestCase {
producerThreads[i] = new Thread(producer);
producerThreads[i].start();
}
-
+
Thread consumerThread = new Thread(consumer);
consumerThread.start();
-
+
for (int i = 0; i < PRODUCER_NUM; i++) {
producerThreads[i].interrupt();
producerThreads[i].join(TIMEOUT);
@@ -122,7 +122,7 @@ public class DisruptorQueueTest extends TestCase {
return;
}
}
- }
+ };
private class Consumer implements Runnable {
private EventHandler handler;
@@ -144,9 +144,10 @@ public class DisruptorQueueTest extends TestCase {
//break
}
}
- }
+ };
private static DisruptorQueue createQueue(String name, int queueSize) {
- return new DisruptorQueue(name, ProducerType.MULTI, queueSize, new BlockingWaitStrategy());
+ return new DisruptorQueue(name, new MultiThreadedClaimStrategy(
+ queueSize), new BlockingWaitStrategy());
}
}