WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS); boolean isDisruptorBatchMode = ConfigExtension.isDisruptorQueueBatchMode(stormConf); int disruptorBatch = ConfigExtension.getDisruptorBufferSize(stormConf);
@Test public void shouldTimeoutWaitFor() throws Exception { final SequenceBarrier sequenceBarrier = new DummySequenceBarrier(); long theTimeout = 500; TimeoutBlockingWaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(theTimeout, TimeUnit.MILLISECONDS); Sequence cursor = new Sequence(5); Sequence dependent = cursor; long t0 = System.currentTimeMillis(); try { waitStrategy.waitFor(6, cursor, dependent, sequenceBarrier); fail("TimeoutException should have been thrown"); } catch (TimeoutException e) { } long t1 = System.currentTimeMillis(); long timeWaiting = t1 - t0; assertTrue(timeWaiting >= theTimeout); } }
@Override public long tryWaitFor(long sequence, Sequence cursor, Sequence dependentSequence, SequenceBarrier barrier, long spin) throws AlertException, InterruptedException, TimeoutException { return waitFor(sequence, cursor, dependentSequence, barrier); }
WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS); this.transferCtrlQueue = DisruptorQueue.mkInstance( "TotalTransfer", ProducerType.MULTI, queueSize, waitStrategy, false, 0, 0);
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); }
WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS); boolean isDisruptorBatchMode = ConfigExtension.isDisruptorQueueBatchMode(stormConf); int disruptorBatch = ConfigExtension.getDisruptorBufferSize(stormConf);
break; case TIMEOUT_BLOCKING_WAIT: waitStrategy = new TimeoutBlockingWaitStrategy(1000, TimeUnit.MILLISECONDS); break; case LITE_TIMEOUT_BLOCKING_WAIT:
break; case TIMEOUT_BLOCKING_WAIT: waitStrategy = new TimeoutBlockingWaitStrategy(1000, TimeUnit.MILLISECONDS); break; case LITE_TIMEOUT_BLOCKING_WAIT:
WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS); boolean isDisruptorBatchMode = ConfigExtension.isDisruptorQueueBatchMode(storm_conf); int disruptorBatch = ConfigExtension.getDisruptorBufferSize(storm_conf);
public EventResultHandlerImp(int timeoutforeturnResult) { super(); RingBuffer ringBuffer = RingBuffer.createSingleProducer(new EventResultFactory(), 1, new TimeoutBlockingWaitStrategy(timeoutforeturnResult, TimeUnit.MILLISECONDS)); this.valueEventProcessor = new ValueEventProcessor(ringBuffer); }
public static WaitStrategy create(DisruptorWaitStrategy strategy, Environment env, Function<String, String> prefix) { try { switch(strategy) { case PhasedBackoffWaitStrategy: return new PhasedBackoffWaitStrategy(env.getRequiredProperty(prefix.apply("PhasedBackoffWaitStrategy.spinTimeout"), Long.class), env.getRequiredProperty(prefix.apply("PhasedBackoffWaitStrategy.yieldTimeout"), Long.class), env.getRequiredProperty(prefix.apply("PhasedBackoffWaitStrategy.unit"), TimeUnit.class), create(env.getRequiredProperty(prefix.apply("PhasedBackoffWaitStrategy.fallbackStrategy"), DisruptorWaitStrategy.class), env, prefix)); case SleepingWaitStrategy: return new SleepingWaitStrategy(env.getProperty(prefix.apply("SleepingWaitStrategy."), Integer.class, 200)); case TimeoutBlockingWaitStrategy: return new TimeoutBlockingWaitStrategy(env.getRequiredProperty(prefix.apply("TimeoutBlockingWaitStrategy.timeout"), Long.class), env.getRequiredProperty(prefix.apply("TimeoutBlockingWaitStrategy.unit"), TimeUnit.class)); default: return (WaitStrategy) DisruptorCommandQueue.class.getClassLoader().loadClass(BlockingWaitStrategy.class.getPackage().getName() + "." + strategy.toString()).newInstance(); } } catch(Exception e) { throw new RuntimeException("Could not create wait strategy: '" + strategy + "'!", e); } }
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); } }
AbstractRequestProcessor(MetricsRegistry metrics, TimestampOracle timestampOracle, Panicker panicker, TSOServerConfig config, LowWatermarkWriter lowWatermarkWriter, ReplyProcessor replyProcessor) throws IOException { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ TimeoutBlockingWaitStrategy timeoutStrategy = new TimeoutBlockingWaitStrategy(config.getBatchPersistTimeoutInMs(), MILLISECONDS); ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("request-%d").build(); this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, MULTI, timeoutStrategy); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith() disruptor.handleEventsWith(this); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.metrics = metrics; this.timestampOracle = timestampOracle; this.hashmap = new CommitHashMap(config.getConflictMapSize()); this.tableFences = new HashMap<Long, Long>(); this.lowWatermarkWriter = lowWatermarkWriter; this.replyProcessor = replyProcessor; LOG.info("RequestProcessor initialized"); }
@Inject RequestProcessorImpl(MetricsRegistry metrics, TimestampOracle timestampOracle, PersistenceProcessor persistProc, Panicker panicker, TSOServerConfig config) throws IOException { // ------------------------------------------------------------------------------------------------------------ // Disruptor initialization // ------------------------------------------------------------------------------------------------------------ TimeoutBlockingWaitStrategy timeoutStrategy = new TimeoutBlockingWaitStrategy(config.getBatchPersistTimeoutInMs(), MILLISECONDS); ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("request-%d").build(); this.disruptorExec = Executors.newSingleThreadExecutor(threadFactory); this.disruptor = new Disruptor<>(EVENT_FACTORY, 1 << 12, disruptorExec, MULTI, timeoutStrategy); disruptor.handleExceptionsWith(new FatalExceptionHandler(panicker)); // This must be before handleEventsWith() disruptor.handleEventsWith(this); this.requestRing = disruptor.start(); // ------------------------------------------------------------------------------------------------------------ // Attribute initialization // ------------------------------------------------------------------------------------------------------------ this.metrics = metrics; this.persistProc = persistProc; this.timestampOracle = timestampOracle; this.hashmap = new CommitHashMap(config.getConflictMapSize()); LOG.info("RequestProcessor initialized"); }
@Inject RequestProcessorImpl(MetricsRegistry metrics, TimestampOracle timestampOracle, PersistenceProcessor persistProc, Panicker panicker, TSOServerConfig config) throws IOException { this.metrics = metrics; this.persistProc = persistProc; this.timestampOracle = timestampOracle; this.hashmap = new CommitHashMap(config.getMaxItems()); final TimeoutBlockingWaitStrategy timeoutStrategy = new TimeoutBlockingWaitStrategy(config.getBatchPersistTimeoutInMs(), TimeUnit.MILLISECONDS); // Set up the disruptor thread requestRing = RingBuffer.createMultiProducer(RequestEvent.EVENT_FACTORY, 1 << 12, timeoutStrategy); SequenceBarrier requestSequenceBarrier = requestRing.newBarrier(); BatchEventProcessor<RequestEvent> requestProcessor = new BatchEventProcessor<>(requestRing, requestSequenceBarrier, this); requestRing.addGatingSequences(requestProcessor.getSequence()); requestProcessor.setExceptionHandler(new FatalExceptionHandler(panicker)); ExecutorService requestExec = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setNameFormat("request-%d").build()); // Each processor runs on a separate thread requestExec.submit(requestProcessor); }
= new TimeoutBlockingWaitStrategy(config.getBatchPersistTimeoutMS(), TimeUnit.MILLISECONDS);
monitor.busySpinStrategy(); } else if ("timeout".equalsIgnoreCase(strategyType)) { waitStrategy = new TimeoutBlockingWaitStrategy(blockingTimeoutNanos, TimeUnit.NANOSECONDS); monitor.timeoutStrategy(blockingTimeoutNanos); } else {
public DisruptorQueue(String queueName, ProducerType type, int size, long readTimeout, int inputBatchSize, long flushInterval, String topologyId, String componentId, Integer taskId, int port) { this._queueName = PREFIX + queueName; WaitStrategy wait; if (readTimeout <= 0) { wait = new LiteBlockingWaitStrategy(); } else { wait = new TimeoutBlockingWaitStrategy(readTimeout, TimeUnit.MILLISECONDS); } _buffer = RingBuffer.create(type, new ObjectEventFactory(), size, wait); _consumer = new Sequence(); _barrier = _buffer.newBarrier(); _buffer.addGatingSequences(_consumer); _metrics = new QueueMetrics(); _disruptorMetrics = StormMetricRegistry.disruptorMetrics(_queueName, topologyId, componentId, taskId, port); //The batch size can be no larger than half the full queue size. //This is mostly to avoid contention issues. _inputBatchSize = Math.max(1, Math.min(inputBatchSize, size/2)); _flusher = new Flusher(Math.max(flushInterval, 1), _queueName); _flusher.start(); if(!METRICS_REPORTER_EXECUTOR.isShutdown()) { METRICS_REPORTER_EXECUTOR.scheduleAtFixedRate(new Runnable() { @Override public void run() { _disruptorMetrics.set(_metrics); } }, 15, 15, TimeUnit.SECONDS); } }
monitor.busySpinStrategy(); } else if ("timeout".equalsIgnoreCase(strategyType)) { waitStrategy = new TimeoutBlockingWaitStrategy(blockingTimeoutNanos, TimeUnit.NANOSECONDS); monitor.timeoutStrategy(blockingTimeoutNanos); } else {
break; case "timeout": waitStrategy1 = new TimeoutBlockingWaitStrategy(10, TimeUnit.MILLISECONDS); break; case "sleep":