com.lmax.disruptor.YieldingWaitStrategy Java Examples
The following examples show how to use
com.lmax.disruptor.YieldingWaitStrategy.
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: FastEventServiceImpl.java From redtorch with MIT License | 6 votes |
@Override public void afterPropertiesSet() throws Exception { if ("BusySpinWaitStrategy".equals(waitStrategy)) { disruptor = new Disruptor<FastEvent>(new FastEventFactory(), 65536, DaemonThreadFactory.INSTANCE, ProducerType.MULTI, new BusySpinWaitStrategy()); } else if ("SleepingWaitStrategy".equals(waitStrategy)) { disruptor = new Disruptor<FastEvent>(new FastEventFactory(), 65536, DaemonThreadFactory.INSTANCE, ProducerType.MULTI, new SleepingWaitStrategy()); } else if ("BlockingWaitStrategy".equals(waitStrategy)) { disruptor = new Disruptor<FastEvent>(new FastEventFactory(), 65536, DaemonThreadFactory.INSTANCE, ProducerType.MULTI, new BlockingWaitStrategy()); } else { disruptor = new Disruptor<FastEvent>(new FastEventFactory(), 65536, DaemonThreadFactory.INSTANCE, ProducerType.MULTI, new YieldingWaitStrategy()); } ringBuffer = disruptor.start(); }
Example #2
Source File: TestRetryProcessor.java From phoenix-omid with Apache License 2.0 | 6 votes |
@Test(timeOut = 10_000) public void testRetriedRequestForAnExistingTxReturnsCommit() throws Exception { ObjectPool<Batch> batchPool = new BatchPoolModule(new TSOServerConfig()).getBatchPool(); // The element to test RetryProcessor retryProc = new RetryProcessorImpl(new YieldingWaitStrategy(), metrics, commitTable, replyProc, panicker, batchPool); // Test we'll reply with a commit for a retry request when the start timestamp IS in the commit table commitTable.getWriter().addCommittedTransaction(ST_TX_1, CT_TX_1); retryProc.disambiguateRetryRequestHeuristically(ST_TX_1, channel, new MonitoringContextImpl(metrics)); ArgumentCaptor<Long> firstTSCapture = ArgumentCaptor.forClass(Long.class); ArgumentCaptor<Long> secondTSCapture = ArgumentCaptor.forClass(Long.class); verify(replyProc, timeout(100).times(1)).sendCommitResponse(firstTSCapture.capture(), secondTSCapture.capture(), any(Channel.class), any(MonitoringContextImpl.class), any(Optional.class)); long startTS = firstTSCapture.getValue(); long commitTS = secondTSCapture.getValue(); assertEquals(startTS, ST_TX_1, "Captured timestamp should be the same as ST_TX_1"); assertEquals(commitTS, CT_TX_1, "Captured timestamp should be the same as CT_TX_1"); }
Example #3
Source File: TestRetryProcessor.java From phoenix-omid with Apache License 2.0 | 6 votes |
@Test(timeOut = 10_000) public void testRetriedRequestForInvalidatedTransactionReturnsAnAbort() throws Exception { // Invalidate the transaction commitTable.getClient().tryInvalidateTransaction(ST_TX_1); // Pre-start verification: Validate that the transaction is invalidated // NOTE: This test should be in the a test class for InMemoryCommitTable Optional<CommitTimestamp> invalidTxMarker = commitTable.getClient().getCommitTimestamp(ST_TX_1).get(); Assert.assertTrue(invalidTxMarker.isPresent()); Assert.assertEquals(invalidTxMarker.get().getValue(), InMemoryCommitTable.INVALID_TRANSACTION_MARKER); ObjectPool<Batch> batchPool = new BatchPoolModule(new TSOServerConfig()).getBatchPool(); // The element to test RetryProcessor retryProc = new RetryProcessorImpl(new YieldingWaitStrategy(), metrics, commitTable, replyProc, panicker, batchPool); // Test we return an Abort to a retry request when the transaction id IS in the commit table BUT invalidated retryProc.disambiguateRetryRequestHeuristically(ST_TX_1, channel, new MonitoringContextImpl(metrics)); ArgumentCaptor<Long> startTSCapture = ArgumentCaptor.forClass(Long.class); verify(replyProc, timeout(100).times(1)).sendAbortResponse(startTSCapture.capture(), any(Channel.class), any(MonitoringContextImpl.class)); long startTS = startTSCapture.getValue(); Assert.assertEquals(startTS, ST_TX_1, "Captured timestamp should be the same as NON_EXISTING_ST_TX"); }
Example #4
Source File: DisruptorUtil.java From logging-log4j2 with Apache License 2.0 | 6 votes |
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 #5
Source File: DisruptorConfig.java From match-trade with Apache License 2.0 | 5 votes |
@Bean public RingBuffer<MatchOrder> ringBuffer() { EventFactory<MatchOrder> factory = new OrderFactory(); int ringBufferSize = 1024 * 1024; ThreadFactory disruptorThreadPool = new ThreadFactoryBuilder().setNameFormat("DisruptorThreadPool").build(); Disruptor<MatchOrder> disruptor = new Disruptor<MatchOrder>(factory, ringBufferSize, disruptorThreadPool, ProducerType.MULTI, new YieldingWaitStrategy()); disruptor.setDefaultExceptionHandler(new MyHandlerException());// Disruptor异常统计 // 单线处理撮合, 并行处理盘口和订单薄 disruptor.handleEventsWithWorkerPool(new MatchHandler(),new MatchHandler()).then(new InputDepthHandler(),new OutDepthHandler()); disruptor.start(); return disruptor.getRingBuffer(); }
Example #6
Source File: DisruptorQueue.java From NetDiscovery with Apache License 2.0 | 5 votes |
/** * * @param consumerNum * @param threadNum * @param ringBufferSize RingBuffer 大小,必须是 2 的 N 次方 */ public DisruptorQueue(int consumerNum,int threadNum,int ringBufferSize) { Consumer[] consumers = new Consumer[consumerNum]; //创建ringBuffer ringBuffer = RingBuffer.create(ProducerType.MULTI, new EventFactory<RequestEvent>() { @Override public RequestEvent newInstance() { return new RequestEvent(); } }, ringBufferSize , new YieldingWaitStrategy()); SequenceBarrier barriers = ringBuffer.newBarrier(); for (int i = 0; i < consumers.length; i++) { consumers[i] = new Consumer(); } WorkerPool<RequestEvent> workerPool = new WorkerPool<RequestEvent>(ringBuffer, barriers, new EventExceptionHandler(), consumers); ringBuffer.addGatingSequences(workerPool.getWorkerSequences()); workerPool.start(Executors.newFixedThreadPool(threadNum)); producer = new Producer(ringBuffer); }
Example #7
Source File: DisruptorModule.java From phoenix-omid with Apache License 2.0 | 5 votes |
@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 #8
Source File: TestRetryProcessor.java From phoenix-omid with Apache License 2.0 | 5 votes |
@Test(timeOut = 10_000) public void testRetriedRequestForANonExistingTxReturnsAbort() throws Exception { ObjectPool<Batch> batchPool = new BatchPoolModule(new TSOServerConfig()).getBatchPool(); // The element to test RetryProcessor retryProc = new RetryProcessorImpl(new YieldingWaitStrategy(), metrics, commitTable, replyProc, panicker, batchPool); // Test we'll reply with an abort for a retry request when the start timestamp IS NOT in the commit table retryProc.disambiguateRetryRequestHeuristically(NON_EXISTING_ST_TX, channel, monCtx); ArgumentCaptor<Long> firstTSCapture = ArgumentCaptor.forClass(Long.class); verify(replyProc, timeout(100).times(1)).sendAbortResponse(firstTSCapture.capture(), any(Channel.class), any(MonitoringContextImpl.class)); long startTS = firstTSCapture.getValue(); assertEquals(startTS, NON_EXISTING_ST_TX, "Captured timestamp should be the same as NON_EXISTING_ST_TX"); }
Example #9
Source File: WaitStrategyTypeTest.java From disruptor-spring-manager with MIT License | 5 votes |
@Test public void test_All_WaitStrategies() { assertTrue(WaitStrategyType.BLOCKING.instance() instanceof BlockingWaitStrategy); assertTrue(WaitStrategyType.BUSY_SPIN.instance() instanceof BusySpinWaitStrategy); assertTrue(WaitStrategyType.LITE_BLOCKING.instance() instanceof LiteBlockingWaitStrategy); assertTrue(WaitStrategyType.SLEEPING_WAIT.instance() instanceof SleepingWaitStrategy); assertTrue(WaitStrategyType.YIELDING.instance() instanceof YieldingWaitStrategy); }
Example #10
Source File: AgileWaitingStrategy.java From camunda-bpm-reactor with Apache License 2.0 | 4 votes |
public AgileWaitingStrategy() { this(new BlockingWaitStrategy(), new YieldingWaitStrategy()); }