com.lmax.disruptor.WaitStrategy Java Examples

The following examples show how to use com.lmax.disruptor.WaitStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisruptorUtil.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
static WaitStrategy createWaitStrategy(final String propertyName, final long timeoutMillis) {
    final String strategy = PropertiesUtil.getProperties().getStringProperty(propertyName, "TIMEOUT");
    LOGGER.trace("property {}={}", propertyName, strategy);
    final String strategyUp = strategy.toUpperCase(Locale.ROOT); // TODO Refactor into Strings.toRootUpperCase(String)
    switch (strategyUp) { // TODO Define a DisruptorWaitStrategy enum?
    case "SLEEP":
        return new SleepingWaitStrategy();
    case "YIELD":
        return new YieldingWaitStrategy();
    case "BLOCK":
        return new BlockingWaitStrategy();
    case "BUSYSPIN":
        return new BusySpinWaitStrategy();
    case "TIMEOUT":
        return new TimeoutBlockingWaitStrategy(timeoutMillis, TimeUnit.MILLISECONDS);
    default:
        return new TimeoutBlockingWaitStrategy(timeoutMillis, TimeUnit.MILLISECONDS);
    }
}
 
Example #2
Source File: RingBufferWorkProcessor.java    From camunda-bpm-reactor with Apache License 2.0 6 votes vote down vote up
private RingBufferWorkProcessor(String name,
                                ExecutorService executor,
                                int bufferSize,
                                WaitStrategy waitStrategy,
                                boolean share,
                                boolean autoCancel) {
  super(name, executor, autoCancel);

  this.ringBuffer = RingBuffer.create(
    share ? ProducerType.MULTI : ProducerType.SINGLE,
    new EventFactory<MutableSignal<E>>() {
      @Override
      public MutableSignal<E> newInstance() {
        return new MutableSignal<E>();
      }
    },
    bufferSize,
    waitStrategy
  );

  ringBuffer.addGatingSequences(workSequence);

}
 
Example #3
Source File: DisruptorQueueImpl.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public DisruptorQueueImpl(String queueName, ProducerType producerType, int bufferSize, WaitStrategy wait, boolean isBatch, int batchSize, long flushMs) {
    _queueName = PREFIX + queueName;
    _buffer = RingBuffer.create(producerType, new ObjectEventFactory(), bufferSize, wait);
    _consumer = new Sequence();
    _barrier = _buffer.newBarrier();
    _buffer.addGatingSequences(_consumer);
    _isBatch = isBatch;
    _cache = new ArrayList<>();
    _inputBatchSize = batchSize;
    if (_isBatch) {
        _batcher = new ThreadLocalBatch();
        _flusher = new DisruptorFlusher(Math.max(flushMs, 1));
        _flusher.start();
    } else {
        _batcher = null;
    }
}
 
Example #4
Source File: DisruptorEventQueue.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
DisruptorEventQueue(
    int bufferSize, WaitStrategy waitStrategy, SpanProcessor spanProcessor, boolean blocking) {
  // Create new Disruptor for processing. Note that Disruptor creates a single thread per
  // consumer (see https://github.com/LMAX-Exchange/disruptor/issues/121 for details);
  // this ensures that the event handler can take unsynchronized actions whenever possible.
  Disruptor<DisruptorEvent> disruptor =
      new Disruptor<>(
          EVENT_FACTORY,
          bufferSize,
          new DaemonThreadFactory(WORKER_THREAD_NAME),
          ProducerType.MULTI,
          waitStrategy);
  disruptor.handleEventsWith(new DisruptorEventHandler(spanProcessor));
  this.ringBuffer = disruptor.start();
  this.blocking = blocking;
}
 
Example #5
Source File: RingBufferProcessor.java    From camunda-bpm-reactor with Apache License 2.0 6 votes vote down vote up
private RingBufferProcessor(String name,
                            ExecutorService executor,
                            int bufferSize,
                            WaitStrategy waitStrategy,
                            boolean shared,
                            boolean autoCancel) {
  super(name, executor, autoCancel);

  this.ringBuffer = RingBuffer.create(
    shared ? ProducerType.MULTI : ProducerType.SINGLE,
    new EventFactory<MutableSignal<E>>() {
      @Override
      public MutableSignal<E> newInstance() {
        return new MutableSignal<E>();
      }
    },
    bufferSize,
    waitStrategy
  );

  this.recentSequence = new Sequence(Sequencer.INITIAL_CURSOR_VALUE);
  this.barrier = ringBuffer.newBarrier();
  //ringBuffer.addGatingSequences(recentSequence);
}
 
Example #6
Source File: NettyUnitTest.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: RetryProcessorImpl.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Inject
RetryProcessorImpl(@Named("RetryStrategy") WaitStrategy strategy,
                   MetricsRegistry metrics,
                   CommitTable commitTable,
                   ReplyProcessor replyProc,
                   Panicker panicker,
                   ObjectPool<Batch> batchPool)
        throws InterruptedException, ExecutionException, IOException {

    // ------------------------------------------------------------------------------------------------------------
    // Disruptor initialization
    // ------------------------------------------------------------------------------------------------------------

    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("retry-%d").build();
    this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory);

    this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, SINGLE, strategy);
    disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith()
    disruptor.handleEventsWith(this);
    this.retryRing = disruptor.start();

    // ------------------------------------------------------------------------------------------------------------
    // Attribute initialization
    // ------------------------------------------------------------------------------------------------------------

    this.commitTableClient = commitTable.getClient();
    this.replyProc = replyProc;
    this.batchPool = batchPool;

    // Metrics configuration
    this.txAlreadyCommittedMeter = metrics.meter(name("tso", "retries", "commits", "tx-already-committed"));
    this.invalidTxMeter = metrics.meter(name("tso", "retries", "aborts", "tx-invalid"));
    this.noCTFoundMeter = metrics.meter(name("tso", "retries", "aborts", "tx-without-commit-timestamp"));

    LOG.info("RetryProcessor initialized");

}
 
Example #8
Source File: RingBufferWorkerPoolFactory.java    From netty-pubsub with MIT License 5 votes vote down vote up
/**
 * 
 * @param type  ����������  �������� ��������
 * @param bufferSize  ringbuffer������
 * @param waitStrategy   �ȴ�����
 * @param messageConsumers  ������
 */
@SuppressWarnings("unchecked")
public void initAndStart(ProducerType type, int bufferSize, WaitStrategy waitStrategy, MessageConsumer[] messageConsumers) {
	if(!startFlag){
	//1. ����ringBuffer����
	this.ringBuffer = RingBuffer.create(type,
			new EventFactory<MessageWrapper>() {
				public MessageWrapper newInstance() {
					return new MessageWrapper();
				}
			},
			bufferSize,
			waitStrategy);
	//2.�������դ��
	this.sequenceBarrier = this.ringBuffer.newBarrier();
	//3.���ù�����
	this.workerPool = new WorkerPool(this.ringBuffer,
			this.sequenceBarrier, 
			new EventExceptionHandler(), messageConsumers);
	//4 �����������������������
	for(MessageConsumer mc : messageConsumers){
		this.consumers.put(mc.getConsumerId(), mc);
	}
	//5 ������ǵ�sequences
	this.ringBuffer.addGatingSequences(this.workerPool.getWorkerSequences());
	//6 �������ǵĹ�����
	this.workerPool.start(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()/2));
	//7.����������־����ֹ�ظ�����
	startFlag=true;
	}
}
 
Example #9
Source File: DisruptorUtil.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
static WaitStrategy createWaitStrategy(final String propertyName) {
    final String key = propertyName.startsWith("AsyncLogger.")
            ? "AsyncLogger.Timeout"
            : "AsyncLoggerConfig.Timeout";
    final long timeoutMillis = DisruptorUtil.getTimeout(key, 10L);
    return createWaitStrategy(propertyName, timeoutMillis);
}
 
Example #10
Source File: ThreadInfo.java    From litchi with Apache License 2.0 5 votes vote down vote up
public static ThreadInfo valueOf(String name, int threadId, int threadNum, WaitStrategy waitStrategy) {
    ThreadInfo info = new ThreadInfo();
    info.name = name;
    info.threadId = threadId;
    info.threadNum = threadNum;
    info.waitStrategy = waitStrategy;
    return info;
}
 
Example #11
Source File: DisruptorService.java    From litchi with Apache License 2.0 5 votes vote down vote up
public void addThread(String name, int threadId, int threadNum, WaitStrategy waitStrategy) {
    List<MessageThread> threadList = threadMaps.getOrDefault(threadId, new ArrayList<>());
    if (!threadMaps.containsKey(threadId)) {
        threadMaps.put(threadId, threadList);
    }

    for (int t = 0; t < threadNum; t++) {
        MessageThread thread = new MessageThread(litchi, name + "-" + t, ringBufferSize, waitStrategy);
        threadList.add(thread);
    }
}
 
Example #12
Source File: MessageThread.java    From litchi with Apache License 2.0 5 votes vote down vote up
public MessageThread(String threadName, int bufferSize, EventHandler<MessageBuffer> handler, WaitStrategy waitStrategy) {
    this.disruptor = new Disruptor<>(
            () -> new MessageBuffer(),
            bufferSize,
            new NamedThreadFactory(threadName),
            ProducerType.MULTI,
            waitStrategy
    );

    disruptor.handleEventsWith(handler);
    disruptor.setDefaultExceptionHandler(new ErrorHandler<>());
}
 
Example #13
Source File: DisruptorModule.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    switch (config.getWaitStrategyEnum()) {
    // A low-cpu usage Disruptor configuration for using in local/test environments
    case LOW_CPU:
         bind(WaitStrategy.class).annotatedWith(Names.named("PersistenceStrategy")).to(BlockingWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("ReplyStrategy")).to(BlockingWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("RetryStrategy")).to(BlockingWaitStrategy.class);
         break;
    // The default high-cpu usage Disruptor configuration for getting high throughput on production environments
    case HIGH_THROUGHPUT:
    default:
         bind(WaitStrategy.class).annotatedWith(Names.named("PersistenceStrategy")).to(BusySpinWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("ReplyStrategy")).to(BusySpinWaitStrategy.class);
         bind(WaitStrategy.class).annotatedWith(Names.named("RetryStrategy")).to(YieldingWaitStrategy.class);
         break;
    }

    if (config.getLowLatency()) {
        bind(RequestProcessor.class).to(RequestProcessorSkipCT.class).in(Singleton.class);
        bind(PersistenceProcessor.class).to(PersitenceProcessorNullImpl.class).in(Singleton.class);
    } else {
        bind(PersistenceProcessor.class).to(PersistenceProcessorImpl.class).in(Singleton.class);
        bind(RequestProcessor.class).to(RequestProcessorPersistCT.class).in(Singleton.class);
    }

    bind(ReplyProcessor.class).to(ReplyProcessorImpl.class).in(Singleton.class);
    bind(RetryProcessor.class).to(RetryProcessorImpl.class).in(Singleton.class);

}
 
Example #14
Source File: PersistenceProcessorImpl.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Inject
PersistenceProcessorImpl(TSOServerConfig config,
                         @Named("PersistenceStrategy") WaitStrategy strategy,
                         CommitTable commitTable,
                         ObjectPool<Batch> batchPool,
                         Panicker panicker,
                         PersistenceProcessorHandler[] handlers,
                         MetricsRegistry metrics)
        throws Exception {

    // ------------------------------------------------------------------------------------------------------------
    // Disruptor initialization
    // ------------------------------------------------------------------------------------------------------------

    ThreadFactoryBuilder threadFactory = new ThreadFactoryBuilder().setNameFormat("persist-%d");
    this.disruptorExec = Executors.newFixedThreadPool(config.getNumConcurrentCTWriters(), threadFactory.build());

    this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 20, disruptorExec , SINGLE, strategy);
    disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith()
    disruptor.handleEventsWithWorkerPool(handlers);
    this.persistRing = disruptor.start();

    // ------------------------------------------------------------------------------------------------------------
    // Attribute initialization
    // ------------------------------------------------------------------------------------------------------------

    this.metrics = metrics;
    this.batchSequence = 0L;
    this.batchPool = batchPool;
    this.currentBatch = batchPool.borrowObject();

    LOG.info("PersistentProcessor initialized");
}
 
Example #15
Source File: Worker.java    From jstorm with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #16
Source File: DisruptorWorkerPoolExecutionStrategy.java    From gridgo with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public DisruptorWorkerPoolExecutionStrategy(ProducerType type, final int bufferSize, final int numWorkers,
        final WaitStrategy waitStrategy, final ThreadFactory threadFactory) {
    this.disruptor = new Disruptor<>(ExecutionContextEvent::new, bufferSize, threadFactory, type, waitStrategy);
    WorkHandler<ExecutionContextEvent<T, H>>[] workers = new WorkHandler[numWorkers];
    for (int i = 0; i < numWorkers; i++) {
        workers[i] = event -> {
            event.getContext().execute();
        };
    }
    this.disruptor.handleEventsWithWorkerPool(workers);
}
 
Example #17
Source File: Environment.java    From camunda-bpm-reactor with Apache License 2.0 5 votes vote down vote up
public RoundRobinSupplier(int poolsize,
                          String name,
                          int bufferSize,
                          Consumer<Throwable> errorHandler,
                          ProducerType producerType,
                          WaitStrategy waitStrategy) {
  this.poolsize = poolsize;
  this.name = name;
  this.bufferSize = bufferSize;
  this.errorHandler = errorHandler;
  this.producerType = producerType;
  this.waitStrategy = waitStrategy;
  dispatchers = new Dispatcher[poolsize];
  terminated = false;
}
 
Example #18
Source File: AsyncLoggerConfigDisruptor.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Increases the reference count and creates and starts a new Disruptor and associated thread if none currently
 * exists.
 *
 * @see #stop()
 */
@Override
public synchronized void start() {
    if (disruptor != null) {
        LOGGER.trace("AsyncLoggerConfigDisruptor not starting new disruptor for this configuration, "
                + "using existing object.");
        return;
    }
    LOGGER.trace("AsyncLoggerConfigDisruptor creating new disruptor for this configuration.");
    ringBufferSize = DisruptorUtil.calculateRingBufferSize("AsyncLoggerConfig.RingBufferSize");
    final WaitStrategy waitStrategy = DisruptorUtil.createWaitStrategy("AsyncLoggerConfig.WaitStrategy");

    final ThreadFactory threadFactory = new Log4jThreadFactory("AsyncLoggerConfig", true, Thread.NORM_PRIORITY) {
        @Override
        public Thread newThread(final Runnable r) {
            final Thread result = super.newThread(r);
            backgroundThreadId = result.getId();
            return result;
        }
    };
    asyncQueueFullPolicy = AsyncQueueFullPolicyFactory.create();

    translator = mutable ? MUTABLE_TRANSLATOR : TRANSLATOR;
    factory = mutable ? MUTABLE_FACTORY : FACTORY;
    disruptor = new Disruptor<>(factory, ringBufferSize, threadFactory, ProducerType.MULTI, waitStrategy);

    final ExceptionHandler<Log4jEventWrapper> errorHandler = DisruptorUtil.getAsyncLoggerConfigExceptionHandler();
    disruptor.setDefaultExceptionHandler(errorHandler);

    final Log4jEventWrapperHandler[] handlers = {new Log4jEventWrapperHandler()};
    disruptor.handleEventsWith(handlers);

    LOGGER.debug("Starting AsyncLoggerConfig disruptor for this configuration with ringbufferSize={}, "
            + "waitStrategy={}, exceptionHandler={}...", disruptor.getRingBuffer().getBufferSize(), waitStrategy
            .getClass().getSimpleName(), errorHandler);
    disruptor.start();
    super.start();
}
 
Example #19
Source File: MultiProducerSequencer.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a Sequencer with the selected wait strategy and buffer size.
 * 
 * @param bufferSize the size of the buffer that this will sequence over.
 * @param waitStrategy for those waiting on sequences.
 */
public MultiProducerSequencer(int bufferSize, final WaitStrategy waitStrategy) {
    super(bufferSize, waitStrategy);
    availableBuffer = new int[bufferSize];
    indexMask = bufferSize - 1;
    indexShift = Util.log2(bufferSize);
    initialiseAvailableBuffer();
}
 
Example #20
Source File: RingBuffer.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new Ring Buffer with the specified producer type (SINGLE or MULTI)
 * 
 * @param producerType producer type to use {@link ProducerType}.
 * @param factory used to create events within the ring buffer.
 * @param bufferSize number of elements to create within the ring buffer.
 * @param waitStrategy used to determine how to wait for new elements to become available.
 * @throws IllegalArgumentException if bufferSize is less than 1 or not a power of 2
 */
public static <E> RingBuffer<E> create(ProducerType producerType, EventFactory<E> factory, int bufferSize, WaitStrategy waitStrategy) {
    switch (producerType) {
    case SINGLE:
        return createSingleProducer(factory, bufferSize, waitStrategy);
    case MULTI:
        return createMultiProducer(factory, bufferSize, waitStrategy);
    default:
        throw new IllegalStateException(producerType.toString());
    }
}
 
Example #21
Source File: LogicProcessor.java    From Okra with Apache License 2.0 5 votes vote down vote up
public LogicProcessor(EventFactory<ConcurrentEvent> factory, EventHandler<ConcurrentEvent> handler, int rbSize, ExecutorService es, ProducerType pt, WaitStrategy ws) {
    this.disruptor = new Disruptor<>(factory, rbSize, es, pt, ws);
    this.disruptor.handleEventsWith(handler);
    //  disruptor.handleExceptionsWith();
    this.disruptor.start();
    this.msgQueue = newQueue();
}
 
Example #22
Source File: DisruptorMessageQueue.java    From akka-disruptor with MIT License 5 votes vote down vote up
DisruptorMessageQueue(int bufferSize, WaitStrategy waitStrategy) {
    ringBuffer = RingBuffer.createMultiProducer(EVENT_FACTORY, bufferSize, waitStrategy);
    ringBuffer.addGatingSequences(sequence);
    sequenceBarrier = ringBuffer.newBarrier();
    mask = bufferSize - 1;
    buffer = new Envelope[bufferSize];
}
 
Example #23
Source File: DisruptorMessageQueue.java    From akka-disruptor with MIT License 5 votes vote down vote up
DisruptorMessageQueue(int bufferSize, WaitStrategy waitStrategy) {
    ringBuffer = RingBuffer.createMultiProducer(EVENT_FACTORY, bufferSize, waitStrategy);
    ringBuffer.addGatingSequences(sequence);
    sequenceBarrier = ringBuffer.newBarrier();
    mask = bufferSize - 1;
    buffer = new Envelope[bufferSize];
}
 
Example #24
Source File: MessageThread.java    From litchi with Apache License 2.0 4 votes vote down vote up
public MessageThread(Litchi litchi, String threadName, int bufferSize, WaitStrategy waitStrategy) {
    this(threadName, bufferSize, new MessageEventHandler(litchi), waitStrategy);
}
 
Example #25
Source File: BaseExecutors.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public BaseExecutors(Task task) {
    this.task = task;
    this.storm_conf = task.getStormConf();

    this.userTopologyCtx = task.getUserContext();
    this.sysTopologyCtx = task.getTopologyContext();
    this.taskStats = task.getTaskStats();
    this.taskId = sysTopologyCtx.getThisTaskId();
    this.innerTaskTransfer = task.getInnerTaskTransfer();
    this.topologyId = sysTopologyCtx.getTopologyId();
    this.componentId = sysTopologyCtx.getThisComponentId();
    this.idStr = JStormServerUtils.getName(componentId, taskId);

    this.taskStatus = task.getTaskStatus();
    this.executorStatus = new TaskStatus();
    this.reportError = task.getReportErrorDie();
    this.taskTransfer = task.getTaskTransfer();
    this.metricsReporter = task.getWorkerData().getMetricsReporter();

    messageTimeoutSecs = JStormUtils.parseInt(storm_conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS), 30);

    int queue_size = Utils.getInt(storm_conf.get(Config.TOPOLOGY_EXECUTOR_RECEIVE_BUFFER_SIZE), 256);
    long timeout = JStormUtils.parseLong(storm_conf.get(Config.TOPOLOGY_DISRUPTOR_WAIT_TIMEOUT), 10);
    WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS);
    boolean isDisruptorBatchMode = ConfigExtension.isDisruptorQueueBatchMode(storm_conf);
    int disruptorBatch = ConfigExtension.getDisruptorBufferSize(storm_conf);
    long flushMs = ConfigExtension.getDisruptorBufferFlushMs(storm_conf);

    this.exeQueue = DisruptorQueue.mkInstance(idStr, ProducerType.MULTI, queue_size,
            waitStrategy, isDisruptorBatchMode, disruptorBatch, flushMs);
    //this.exeQueue.consumerStarted();
    queue_size = Utils.getInt(storm_conf.get(Config.TOPOLOGY_CTRL_BUFFER_SIZE), 32);
    this.controlQueue = DisruptorQueue.mkInstance(
            idStr + " for control message", ProducerType.MULTI, queue_size, waitStrategy, false, 0, 0);
    //this.controlQueue.consumerStarted();

    this.registerInnerTransfer(exeQueue);
    this.task.getControlQueues().put(taskId, this.controlQueue);

    QueueGauge exeQueueGauge = new QueueGauge(exeQueue, idStr, MetricDef.EXECUTE_QUEUE);
    JStormMetrics.registerTaskMetric(MetricUtils.taskMetricName(
                    topologyId, componentId, taskId, MetricDef.EXECUTE_QUEUE, MetricType.GAUGE),
            new AsmGauge(exeQueueGauge));
    JStormHealthCheck.registerTaskHealthCheck(taskId, MetricDef.EXECUTE_QUEUE, exeQueueGauge);
    //metric for control queue
    QueueGauge controlQueueGauge = new QueueGauge(controlQueue, idStr, MetricDef.CONTROL_QUEUE);
    JStormMetrics.registerTaskMetric(MetricUtils.taskMetricName(
                    topologyId, componentId, taskId, MetricDef.CONTROL_QUEUE, MetricType.GAUGE),
            new AsmGauge(controlQueueGauge));
    JStormHealthCheck.registerTaskHealthCheck(taskId, MetricDef.CONTROL_QUEUE, controlQueueGauge);

    rotatingMapTrigger = new RotatingMapTrigger(storm_conf, idStr + "_rotating", controlQueue);
    rotatingMapTrigger.register();
    taskHbTrigger = new TaskHeartbeatTrigger(storm_conf, idStr + "_taskHeartbeat", controlQueue,
            taskId, componentId, sysTopologyCtx, reportError, executorStatus);
    assignmentTs = System.currentTimeMillis();
    isBatchMode = ConfigExtension.isTaskBatchTuple(storm_conf);
}
 
Example #26
Source File: BusySpinWaitStrategyFactory.java    From fastjgame with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public WaitStrategy newWaitStrategy(DisruptorEventLoop eventLoop) {
    return new BusySpinWaitStrategy(eventLoop, loopOnceSpinTries);
}
 
Example #27
Source File: YieldWaitStrategyFactory.java    From fastjgame with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public WaitStrategy newWaitStrategy(DisruptorEventLoop eventLoop) {
    return new YieldWaitStrategy(eventLoop, spinTries, loopOnceSpinTries);
}
 
Example #28
Source File: ReplyProcessorImpl.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
@Inject
ReplyProcessorImpl(@Named("ReplyStrategy") WaitStrategy strategy,
                   MetricsRegistry metrics,
                   Panicker panicker,
                   ObjectPool<Batch> batchPool,
                   LowWatermarkWriter lowWatermarkWriter) {
    this.lowWatermarkWriter = lowWatermarkWriter;

    // ------------------------------------------------------------------------------------------------------------
    // Disruptor initialization
    // ------------------------------------------------------------------------------------------------------------

    ThreadFactoryBuilder threadFactory = new ThreadFactoryBuilder().setNameFormat("reply-%d");
    this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory.build());

    this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, MULTI, strategy);
    disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker));
    disruptor.handleEventsWith(this);
    this.replyRing = disruptor.start();

    // ------------------------------------------------------------------------------------------------------------
    // Attribute initialization
    // ------------------------------------------------------------------------------------------------------------

    this.batchPool = batchPool;
    this.nextIDToHandle.set(0);
    this.futureEvents = new PriorityQueue<>(10, new Comparator<ReplyBatchEvent>() {
        public int compare(ReplyBatchEvent replyBatchEvent1, ReplyBatchEvent replyBatchEvent2) {
            return Long.compare(replyBatchEvent1.getBatchSequence(), replyBatchEvent2.getBatchSequence());
        }
    });

    // Metrics config
    this.abortMeter = metrics.meter(name("tso", "aborts"));
    this.commitMeter = metrics.meter(name("tso", "commits"));
    this.timestampMeter = metrics.meter(name("tso", "timestampAllocation"));
    this.fenceMeter = metrics.meter(name("tso", "fences"));

    LOG.info("ReplyProcessor initialized");

    highestLowWaterMarkSeen = -1;
}
 
Example #29
Source File: AbstractSequencerExt.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public AbstractSequencerExt(int bufferSize, WaitStrategy waitStrategy) {
    super(bufferSize, waitStrategy);
}
 
Example #30
Source File: AgileWaitingStrategy.java    From camunda-bpm-reactor with Apache License 2.0 4 votes vote down vote up
public WaitStrategy current() {
  return currentStrategy;
}