private WaitStrategy getWaitStrategy(String waitStrategyName, String configOptionName) { switch (waitStrategyName) { case "sleeping": return new SleepingWaitStrategy(); case "yielding": return new YieldingWaitStrategy(); case "blocking": return new BlockingWaitStrategy(); case "busy_spinning": return new BusySpinWaitStrategy(); default: LOG.warn("Invalid setting for [{}]:" + " Falling back to default: BlockingWaitStrategy.", configOptionName); return new BlockingWaitStrategy(); } }
protected WaitStrategy getWaitStrategy(String waitStrategyName, String configOptionName) { switch (waitStrategyName) { case "sleeping": return new SleepingWaitStrategy(); case "yielding": return new YieldingWaitStrategy(); case "blocking": return new BlockingWaitStrategy(); case "busy_spinning": return new BusySpinWaitStrategy(); default: log.warn("Invalid setting for [{}]:" + " Falling back to default: BlockingWaitStrategy.", configOptionName); return new BlockingWaitStrategy(); } }
@Test public void shouldWaitForValue() throws Exception { assertWaitForWithDelayOf(50, new BusySpinWaitStrategy()); } }
ProducerType.MULTI, new BusySpinWaitStrategy()); RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer(); disruptor.setDefaultExceptionHandler(new FatalExceptionHandler());
final SingleProducerSequencer sequencer = new SingleProducerSequencer(16, new BusySpinWaitStrategy()); final EventPoller.Handler<Object> handler = new EventPoller.Handler<Object>()
@Test public void shouldNotUpdateCursorDuringHasAvailableCapacity() throws Exception { SingleProducerSequencer sequencer = new SingleProducerSequencer(16, new BusySpinWaitStrategy()); for (int i = 0; i < 32; i++) { long next = sequencer.next(); assertThat(sequencer.cursor.get(), not(next)); sequencer.hasAvailableCapacity(13); assertThat(sequencer.cursor.get(), not(next)); sequencer.publish(next); } } }
break; case BUSY_SPIN_WAIT: waitStrategy = new BusySpinWaitStrategy(); break; default:
break; case BUSY_SPIN_WAIT: waitStrategy = new BusySpinWaitStrategy(); break; default:
@Test public void shouldAlwaysHalt() throws InterruptedException WaitStrategy waitStrategy = new BusySpinWaitStrategy(); final SingleProducerSequencer sequencer = new SingleProducerSequencer(8, waitStrategy); final ProcessingSequenceBarrier barrier = new ProcessingSequenceBarrier(
/** * Set {@link com.lmax.disruptor.BusySpinWaitStrategy} as wait strategy. * * @return {@literal this} */ public ProcessorSpec<T> busySpinWaitStrategy() { this.waitStrategy = new BusySpinWaitStrategy(); return this; }
public WaitStrategy create() { switch (this) { case SLEEPING: return new SleepingWaitStrategy(); case BUSY_SPIN: return new BusySpinWaitStrategy(); case YIELDING: default: return new YieldingWaitStrategy(); } }
@Inject ReplyProcessorImpl(MetricsRegistry metrics, Panicker panicker) { replyRing = RingBuffer.<ReplyEvent>createMultiProducer(ReplyEvent.EVENT_FACTORY, 1<<12, new BusySpinWaitStrategy()); SequenceBarrier replySequenceBarrier = replyRing.newBarrier(); BatchEventProcessor<ReplyEvent> replyProcessor = new BatchEventProcessor<ReplyEvent>( replyRing, replySequenceBarrier, this); replyProcessor.setExceptionHandler(new FatalExceptionHandler(panicker)); replyRing.addGatingSequences(replyProcessor.getSequence()); ExecutorService replyExec = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setNameFormat("reply-%d").build()); replyExec.submit(replyProcessor); abortMeter = metrics.meter(name("tso", "aborts")); commitMeter = metrics.meter(name("tso", "commits")); timestampMeter = metrics.meter(name("tso", "timestampAllocation")); }
@Created public void initialize() { ExecutorService exec = Executors.newCachedThreadPool(); // FIXME make configurable: WaitStrategy disruptor = new Disruptor<PathTrackingEntry>( new EventFactory<PathTrackingEntry>() { @Override public PathTrackingEntry newInstance() { return new PathTrackingEntry(); } }, ringBufferSize, exec, ProducerType.SINGLE, new BusySpinWaitStrategy() ); for ( int i = 0; i < numberOfConsumers; i++ ) { disruptor.handleEventsWith( new PathTrackingEntryEventHandler( i, numberOfConsumers ) ); } ringBuffer = disruptor.start(); }
@Inject ReplyProcessorImpl(MetricsRegistry metrics, Panicker panicker, ObjectPool<Batch> batchPool) { this.batchPool = batchPool; this.nextIDToHandle.set(0); this.replyRing = RingBuffer.createMultiProducer(ReplyBatchEvent.EVENT_FACTORY, 1 << 12, new BusySpinWaitStrategy()); SequenceBarrier replySequenceBarrier = replyRing.newBarrier(); BatchEventProcessor<ReplyBatchEvent> replyProcessor = new BatchEventProcessor<>(replyRing, replySequenceBarrier, this); replyProcessor.setExceptionHandler(new FatalExceptionHandler(panicker)); replyRing.addGatingSequences(replyProcessor.getSequence()); ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("reply-%d").build(); ExecutorService replyExec = Executors.newSingleThreadExecutor(threadFactory); replyExec.submit(replyProcessor); this.futureEvents = new PriorityQueue<>(10, new Comparator<ReplyBatchEvent>() { public int compare(ReplyBatchEvent replyBatchEvent1, ReplyBatchEvent replyBatchEvent2) { return Long.compare(replyBatchEvent1.getBatchSequence(), replyBatchEvent2.getBatchSequence()); } }); this.abortMeter = metrics.meter(name("tso", "aborts")); this.commitMeter = metrics.meter(name("tso", "commits")); this.timestampMeter = metrics.meter(name("tso", "timestampAllocation")); }
private WaitStrategy getWaitStrategy(String waitStrategyName, String configOptionName) { switch (waitStrategyName) { case "sleeping": return new SleepingWaitStrategy(); case "yielding": return new YieldingWaitStrategy(); case "blocking": return new BlockingWaitStrategy(); case "busy_spinning": return new BusySpinWaitStrategy(); default: LOG.warn("Invalid setting for [{}]:" + " Falling back to default: BlockingWaitStrategy.", configOptionName); return new BlockingWaitStrategy(); } }
protected WaitStrategy getWaitStrategy(String waitStrategyName, String configOptionName) { switch (waitStrategyName) { case "sleeping": return new SleepingWaitStrategy(); case "yielding": return new YieldingWaitStrategy(); case "blocking": return new BlockingWaitStrategy(); case "busy_spinning": return new BusySpinWaitStrategy(); default: log.warn("Invalid setting for [{}]:" + " Falling back to default: BlockingWaitStrategy.", configOptionName); return new BlockingWaitStrategy(); } }
private WaitStrategy getWaitStrategy() { logger.info("RPC server wait strategy: {}", waitStrategy); WaitStrategy strategy; switch (waitStrategy) { case "blocking": strategy = new BlockingWaitStrategy(); break; case "sleeping": strategy = new SleepingWaitStrategy(); break; case "yielding": strategy = new YieldingWaitStrategy(); break; case "busyspin": strategy = new BusySpinWaitStrategy(); break; default: strategy = new BlockingWaitStrategy(); break; } return strategy; }
@Setup public synchronized void setup() throws InterruptedException { for (int i = 0; i < MAX_THREAD_COUNT; i++) { responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY); } values = new int[burstLength]; for (int i = 0; i < burstLength; i++) { values[i] = -(burstLength - i); } handler = new Handler(responseQueues); disruptor = new Disruptor<>( Message::new, Configuration.SEND_QUEUE_CAPACITY, (ThreadFactory)Thread::new, ProducerType.MULTI, new BusySpinWaitStrategy()); disruptor.handleEventsWith(handler); disruptor.start(); handler.waitForStart(); }
@Inject PersistenceProcessorImpl(TSOServerConfig config, CommitTable commitTable, ObjectPool<Batch> batchPool, Panicker panicker, PersistenceProcessorHandler[] handlers, MetricsRegistry metrics) throws Exception { this.metrics = metrics; this.lowWatermarkWriter = commitTable.getWriter(); this.batchSequence = 0L; this.batchPool = batchPool; this.currentBatch = batchPool.borrowObject(); // Low Watermark writer ThreadFactoryBuilder lwmThreadFactory = new ThreadFactoryBuilder().setNameFormat("lwm-writer-%d"); lowWatermarkWriterExecutor = Executors.newSingleThreadExecutor(lwmThreadFactory.build()); // Disruptor configuration this.persistRing = RingBuffer.createSingleProducer(EVENT_FACTORY, 1 << 20, new BusySpinWaitStrategy()); ThreadFactoryBuilder threadFactory = new ThreadFactoryBuilder().setNameFormat("persist-%d"); ExecutorService requestExec = Executors.newFixedThreadPool(config.getNumConcurrentCTWriters(), threadFactory.build()); WorkerPool<PersistBatchEvent> persistProcessor = new WorkerPool<>(persistRing, persistRing.newBarrier(), new FatalExceptionHandler(panicker), handlers); this.persistRing.addGatingSequences(persistProcessor.getWorkerSequences()); persistProcessor.start(requestExec); // Metrics config this.lwmWriteTimer = metrics.timer(name("tso", "lwmWriter", "latency")); }
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); } }