Search in sources :

Example 11 with DisruptorQueue

use of backtype.storm.utils.DisruptorQueue in project jstorm by alibaba.

the class Worker method startDispatchThread.

private AsyncLoopThread startDispatchThread() {
    // send tuple directly from netty server
    // send control tuple to dispatch thread
    // startDispatchDisruptor();
    IContext context = workerData.getContext();
    String topologyId = workerData.getTopologyId();
    //create recv connection
    Map stormConf = workerData.getStormConf();
    long timeout = JStormUtils.parseLong(stormConf.get(Config.TOPOLOGY_DISRUPTOR_WAIT_TIMEOUT), 10);
    WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS);
    int queueSize = JStormUtils.parseInt(stormConf.get(Config.TOPOLOGY_CTRL_BUFFER_SIZE), 256);
    DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI, queueSize, waitStrategy, false, 0, 0);
    //metric for recvControlQueue
    QueueGauge revCtrlGauge = new QueueGauge(recvControlQueue, MetricDef.RECV_CTRL_QUEUE);
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.RECV_CTRL_QUEUE, MetricType.GAUGE), new AsmGauge(revCtrlGauge));
    IConnection recvConnection = context.bind(topologyId, workerData.getPort(), workerData.getDeserializeQueues(), recvControlQueue, false, workerData.getTaskids());
    workerData.setRecvConnection(recvConnection);
    // create recvice control messages's thread
    RunnableCallback recvControlDispather = new VirtualPortCtrlDispatch(workerData, recvConnection, recvControlQueue, MetricDef.RECV_THREAD);
    return new AsyncLoopThread(recvControlDispather, false, Thread.MAX_PRIORITY, true);
}
Also used : IContext(backtype.storm.messaging.IContext) DisruptorQueue(backtype.storm.utils.DisruptorQueue) IConnection(backtype.storm.messaging.IConnection) RunnableCallback(com.alibaba.jstorm.callback.RunnableCallback) QueueGauge(com.alibaba.jstorm.common.metric.QueueGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread) AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) WaitStrategy(com.lmax.disruptor.WaitStrategy)

Example 12 with DisruptorQueue

use of backtype.storm.utils.DisruptorQueue in project jstorm by alibaba.

the class TaskTransfer method transfer.

public void transfer(TupleExt tuple) {
    int taskId = tuple.getTargetTaskId();
    DisruptorQueue exeQueue = innerTaskTransfer.get(taskId);
    DisruptorQueue targetQueue;
    if (exeQueue == null) {
        taskId = 0;
        targetQueue = serializeQueue;
    } else {
        targetQueue = exeQueue;
    }
    if (isBackpressureEnable) {
        Boolean backpressureStatus = targetTaskBackpressureStatus.get(taskId);
        if (backpressureStatus == null) {
            backpressureStatus = false;
            targetTaskBackpressureStatus.put(taskId, backpressureStatus);
        }
        if (backpressureStatus) {
            while (targetQueue.pctFull() > lowMark) {
                JStormUtils.sleepMs(1);
            }
            targetTaskBackpressureStatus.put(taskId, false);
            targetQueue.publish(tuple);
        } else {
            targetQueue.publish(tuple);
            if (targetQueue.pctFull() > highMark) {
                targetTaskBackpressureStatus.put(taskId, true);
            }
        }
    } else {
        targetQueue.publish(tuple);
    }
}
Also used : DisruptorQueue(backtype.storm.utils.DisruptorQueue) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 13 with DisruptorQueue

use of backtype.storm.utils.DisruptorQueue in project jstorm by alibaba.

the class MkLocalFirst method getActiveTask.

@Override
protected int getActiveTask(RandomRange randomrange, List<Integer> outTasks) {
    int index = randomrange.nextInt();
    int size = outTasks.size();
    int i = 0;
    for (i = 0; i < size; i++) {
        Integer taskId = outTasks.get(index);
        boolean taskStatus = workerData.isOutboundTaskActive(taskId);
        DisruptorQueue exeQueue = (workerData.getInnerTaskTransfer().get(taskId));
        float queueLoadRatio = exeQueue != null ? exeQueue.pctFull() : 0;
        if (taskStatus && queueLoadRatio < loadMark)
            break;
        else
            index = randomrange.nextInt();
    }
    return (i < size ? index : -1);
}
Also used : DisruptorQueue(backtype.storm.utils.DisruptorQueue)

Example 14 with DisruptorQueue

use of backtype.storm.utils.DisruptorQueue in project jstorm by alibaba.

the class NettyUnitTest method initNettyServer.

private IConnection initNettyServer(int port) {
    ConcurrentHashMap<Integer, DisruptorQueue> deserializeQueues = new ConcurrentHashMap<Integer, DisruptorQueue>();
    //ConcurrentHashMap<Integer, DisruptorQueue> deserializeCtrlQueues = new ConcurrentHashMap<Integer, DisruptorQueue>();
    WaitStrategy wait = (WaitStrategy) Utils.newInstance("com.lmax.disruptor.TimeoutBlockingWaitStrategy", 5, TimeUnit.MILLISECONDS);
    DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI, 256, wait, false, 0, 0);
    Set<Integer> taskSet = new HashSet<Integer>();
    taskSet.add(1);
    IConnection server = context.bind(null, port, deserializeQueues, recvControlQueue, true, taskSet);
    WaitStrategy waitStrategy = new BlockingWaitStrategy();
    DisruptorQueue recvQueue = DisruptorQueue.mkInstance("NettyUnitTest", ProducerType.SINGLE, 1024, waitStrategy, false, 0, 0);
    server.registerQueue(task, recvQueue);
    return server;
}
Also used : BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) DisruptorQueue(backtype.storm.utils.DisruptorQueue) BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) WaitStrategy(com.lmax.disruptor.WaitStrategy) IConnection(backtype.storm.messaging.IConnection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 15 with DisruptorQueue

use of backtype.storm.utils.DisruptorQueue in project jstorm by alibaba.

the class DisruptorTest method testSingleProducer.

@Test
public void testSingleProducer() throws InterruptedException {
    System.out.println("!!!!!!!!!!!!!!Begin testSingleProducer!!!!!!!!!!!!!!");
    final AtomicBoolean messageConsumed = new AtomicBoolean(false);
    // Set queue length to 1, so that the RingBuffer can be easily full
    // to trigger consumer blocking
    DisruptorQueue queue = createQueue("consumerHang", ProducerType.SINGLE, 1);
    push(queue, 1);
    Runnable producer = new Producer(queue);
    Runnable consumer = new Consumer(queue, new EventHandler<Object>() {

        long count = 0;

        @Override
        public void onEvent(Object obj, long sequence, boolean endOfBatch) throws Exception {
            messageConsumed.set(true);
            System.out.println("Consume " + count++);
        }
    });
    run(producer, 0, 0, consumer, 50);
    Assert.assertTrue("disruptor message is never consumed due to consumer thread hangs", messageConsumed.get());
    System.out.println("!!!!!!!!!!!!!!End testSingleProducer!!!!!!!!!!!!!!");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DisruptorQueue(backtype.storm.utils.DisruptorQueue) InsufficientCapacityException(com.lmax.disruptor.InsufficientCapacityException) Test(org.junit.Test)

Aggregations

DisruptorQueue (backtype.storm.utils.DisruptorQueue)15 Test (org.junit.Test)5 IConnection (backtype.storm.messaging.IConnection)3 InsufficientCapacityException (com.lmax.disruptor.InsufficientCapacityException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 KryoException (com.esotericsoftware.kryo.KryoException)2 TimeoutBlockingWaitStrategy (com.lmax.disruptor.TimeoutBlockingWaitStrategy)2 WaitStrategy (com.lmax.disruptor.WaitStrategy)2 IContext (backtype.storm.messaging.IContext)1 TaskMessage (backtype.storm.messaging.TaskMessage)1 WorkerSlot (backtype.storm.scheduler.WorkerSlot)1 AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)1 RunnableCallback (com.alibaba.jstorm.callback.RunnableCallback)1 AsmGauge (com.alibaba.jstorm.common.metric.AsmGauge)1 QueueGauge (com.alibaba.jstorm.common.metric.QueueGauge)1 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)1 TimeoutException (com.lmax.disruptor.TimeoutException)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1