@Override public void start(Executor executor) { workerPool.start(executor); }
@SuppressWarnings("unchecked") @Test public void shouldProcessOnlyOnceItHasBeenPublished() throws Exception { Executor executor = Executors.newCachedThreadPool(DaemonThreadFactory.INSTANCE); WorkerPool<AtomicLong> pool = new WorkerPool<AtomicLong>( new AtomicLongEventFactory(), new FatalExceptionHandler(), new AtomicLongWorkHandler(), new AtomicLongWorkHandler()); RingBuffer<AtomicLong> ringBuffer = pool.start(executor); ringBuffer.next(); ringBuffer.next(); Thread.sleep(1000); assertThat(ringBuffer.get(0).get(), is(0L)); assertThat(ringBuffer.get(1).get(), is(0L)); }
@Override public void start(Executor executor) { workerPool.start(executor); }
@SuppressWarnings("unchecked") @Test public void shouldProcessEachMessageByOnlyOneWorker() throws Exception { Executor executor = Executors.newCachedThreadPool(DaemonThreadFactory.INSTANCE); WorkerPool<AtomicLong> pool = new WorkerPool<AtomicLong>( new AtomicLongEventFactory(), new FatalExceptionHandler(), new AtomicLongWorkHandler(), new AtomicLongWorkHandler()); RingBuffer<AtomicLong> ringBuffer = pool.start(executor); ringBuffer.next(); ringBuffer.next(); ringBuffer.publish(0); ringBuffer.publish(1); Thread.sleep(500); assertThat(ringBuffer.get(0).get(), is(1L)); assertThat(ringBuffer.get(1).get(), is(1L)); }
workerPool.start(parserExecutor);
@Override public void start(Executor executor) { workerPool.start(executor); }
@Override public void start(final Executor executor) { workerPool.start(executor); }
@Override public void start(final Executor executor) { workerPool.start(executor); }
@Override public void startup() { EventBus eventBus = disruptorDispatchThread.getEventBus(); executorService = new NonOrderedQueuePoolExecutor(poolName, excutorSize); cycleEventHandler = new CycleEventHandler[excutorSize]; for(int i = 0; i < excutorSize; i++){ cycleEventHandler[i] = new CycleEventHandler(eventBus); } RingBuffer ringBuffer = disruptorDispatchThread.getRingBuffer(); workerPool = new WorkerPool(ringBuffer, ringBuffer.newBarrier(), new FatalExceptionHandler(), cycleEventHandler); ringBuffer.addGatingSequences(workerPool.getWorkerSequences()); workerPool.start(executorService); // BatchEventProcessor<CycleEvent>[] batchEventProcessors = new BatchEventProcessor[excutorSize]; // for(int i = 0; i < excutorSize; i++){ // batchEventProcessors[i] = new BatchEventProcessor<>(ringBuffer, sequenceBarrier, cycleEventHandler[i]); // ringBuffer.addGatingSequences(batchEventProcessors[i].getSequence()); //// executorService.submit(batchEventProcessors[i]); // } }
@Override public void start() { final ExecutorService execService = Executors.newFixedThreadPool(workerThreads); RingBuffer<ServerEvent> ringBuffer = workerPool.start(execService); logger.info("LMAX Disruptor started. Buffer size: {}", ringBuffer.getBufferSize()); requestConsumer.startConsumers(ringBuffer); }
@Bean public NotificationHandler notificationHandler(Gson gson, WorkerPool<ServerEvent> workerPool) { final ExecutorService execService = Executors.newFixedThreadPool(proxyConfig.getWorkerThreads()); RingBuffer<ServerEvent> ringBuffer = workerPool.start(execService); return new ProxyRequestHandler(gson, ringBuffer); }
@Bean public RpcClient rpcClient(NotificationHandler notificationHandler, WebSocketKafkaProxyConfig proxyConfig, RequestResponseMatcher requestResponseMatcher, Gson gson, WorkerPool<ServerEvent> workerPool) { final ExecutorService execService = Executors.newFixedThreadPool(proxyConfig.getWorkerThreads()); RingBuffer<ServerEvent> ringBuffer = workerPool.start(execService); RpcClient client = new FrontendProxyClient(REQUEST_TOPIC, RESPONSE_TOPIC, proxyConfig, notificationHandler, requestResponseMatcher, gson, ringBuffer); client.start(); return client; }
private void setUpWorkerPool() { // Executor that will be used to construct new threads for consumers final ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() .setNameFormat("NewtsWriter-Consumer-%d").build(); final Executor executor = Executors.newCachedThreadPool(namedThreadFactory); @SuppressWarnings("unchecked") final WorkHandler<SampleBatchEvent> handlers[] = new WorkHandler[m_numWriterThreads]; for (int i = 0; i < m_numWriterThreads; i++) { handlers[i] = this; } m_ringBuffer = RingBuffer.createMultiProducer(SampleBatchEvent::new, m_ringBufferSize); m_workerPool = new WorkerPool<SampleBatchEvent>( m_ringBuffer, m_ringBuffer.newBarrier(), new FatalExceptionHandler(), handlers); m_ringBuffer.addGatingSequences(m_workerPool.getWorkerSequences()); m_workerPool.start(executor); }
private void setUpWorkerPool() { // Executor that will be used to construct new threads for consumers final ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() .setNameFormat("NewtsWriter-Consumer-%d").build(); final Executor executor = Executors.newCachedThreadPool(namedThreadFactory); @SuppressWarnings("unchecked") final WorkHandler<SampleBatchEvent> handlers[] = new WorkHandler[m_numWriterThreads]; for (int i = 0; i < m_numWriterThreads; i++) { handlers[i] = this; } m_ringBuffer = RingBuffer.createMultiProducer(SampleBatchEvent::new, m_ringBufferSize); m_workerPool = new WorkerPool<SampleBatchEvent>( m_ringBuffer, m_ringBuffer.newBarrier(), new FatalExceptionHandler(), handlers); m_ringBuffer.addGatingSequences(m_workerPool.getWorkerSequences()); m_workerPool.start(executor); }
@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")); }
/** * Set up the thread that will handle the non-blocking reads, and writes. */ public SelectorThread(String name, int ringSize, ThreadPoolExecutor invoker, int numHandlers, boolean isSharedInvoker) throws IOException { super(name); this.newConnections = new ConcurrentLinkedQueue<>(); InvocationHandler handlers[] = new InvocationHandler[numHandlers]; for (int i = 0; i < handlers.length; i++) handlers[i] = new InvocationHandler(); this.invoker = invoker; this.isSharedInvoker = isSharedInvoker; /** * YieldingWaitStrategy claims to be better compromise between throughput/latency and CPU usage comparing to * BlockingWaitStrategy, but actual tests show quite the opposite, where YieldingWaitStrategy just constantly * burns CPU cycles with no performance benefit when coupled with networking. */ ringBuffer = RingBuffer.createSingleProducer(Message.Invocation.FACTORY, ringSize, new BlockingWaitStrategy()); workerPool = new WorkerPool<>(ringBuffer, ringBuffer.newBarrier(), new FatalExceptionHandler(), handlers); workerPool.start(invoker); }
/** * @param maxQueueSz * @param numThreads * @param name */ public RequestQueueProcessor(int maxQueueSz, int numThreads, String name) { m_name = name; m_maxQueueSz = maxQueueSz; m_ringBuffer = RingBuffer.createMultiProducer(m_eventFactory, normalizeBufferSize(m_maxQueueSz), new BlockingWaitStrategy()); m_barrier = m_ringBuffer.newBarrier(); m_numThreads = numThreads; QueueProcessorWorkHandler[] handlers = new QueueProcessorWorkHandler[m_numThreads]; for (int i = 0; i < m_numThreads; i++) { handlers[i] = new QueueProcessorWorkHandler(); } m_worker = new WorkerPool(m_ringBuffer, m_barrier, new QueueProcessorExceptionHandler(m_dropCounter, name), handlers); m_ringBuffer.addGatingSequences(m_worker.getWorkerSequences()); m_executor = Executors.newFixedThreadPool(m_numThreads, new NameableThreadFactory(name)); m_ringBuffer = m_worker.start(m_executor); }