public void ShouldReportProgressByUpdatingSequenceViaCallback()
        {
            var ringBuffer          = new RingBuffer <StubEvent>(() => new StubEvent(0), 16);
            var sequenceBarrier     = ringBuffer.NewBarrier();
            var handler             = new TestSequenceReportingEventHandler(_callbackLatch);
            var batchEventProcessor = new BatchEventProcessor <StubEvent>(ringBuffer, sequenceBarrier, handler);

            ringBuffer.SetGatingSequences(batchEventProcessor.Sequence);

            var thread = new Thread(batchEventProcessor.Run)
            {
                IsBackground = true
            };

            thread.Start();

            Assert.AreEqual(-1L, batchEventProcessor.Sequence.Value);
            ringBuffer.Publish(ringBuffer.Next());

            _callbackLatch.WaitOne();
            Assert.AreEqual(0L, batchEventProcessor.Sequence.Value);

            _onEndOfBatchLatch.Set();
            Assert.AreEqual(0L, batchEventProcessor.Sequence.Value);

            batchEventProcessor.Halt();
            thread.Join();
        }
        public void ShouldThrowExceptionOnSettingNullExceptionHandler()
        {
            var eventHandler        = new ActionEventHandler <StubEvent>(x => throw new NullReferenceException());
            var batchEventProcessor = new BatchEventProcessor <StubEvent>(_ringBuffer, _sequenceBarrier, eventHandler);

            Assert.Throws <ArgumentNullException>(() => batchEventProcessor.SetExceptionHandler(null));
        }
Пример #3
0
        static void DemoNonDSLDisruptor()
        {
            var bufferSize = (int)Math.Pow(2, 4);
            var ringBuffer = RingBuffer <DataVO> .CreateSingleProducer(() => new DataVO(), bufferSize);

            var barrier        = ringBuffer.NewBarrier();
            var eventProcessor = new BatchEventProcessor <DataVO>(ringBuffer, barrier, new DataEventHandler("Handler1"));

            Task.Factory.StartNew(() => eventProcessor.Run());
            var task = Task.Run(() => eventProcessor.Run());

            var sequenceNo = ringBuffer.Next();

            Console.WriteLine($"Current SequenceNo:{sequenceNo.ToString()}");
            var data = ringBuffer[sequenceNo];

            data.Value = "Hello";
            ringBuffer.Publish(sequenceNo);

            sequenceNo = ringBuffer.Next();
            Console.WriteLine($"Current SequenceNo:{sequenceNo.ToString()}");
            data       = ringBuffer[sequenceNo];
            data.Value = "World";
            ringBuffer.Publish(sequenceNo);

            Thread.Sleep(3000);
            eventProcessor.Halt();
        }
        public OneToThreePipelineSequencedThroughputTest()
        {
            var stepOneFunctionHandler = new FunctionEventHandler(FunctionStep.One);
            var stepTwoFunctionHandler = new FunctionEventHandler(FunctionStep.Two);
            _stepThreeFunctionHandler = new FunctionEventHandler(FunctionStep.Three);

            var stepOneSequenceBarrier = _ringBuffer.NewBarrier();
            _stepOneBatchProcessor = new BatchEventProcessor<FunctionEvent>(_ringBuffer, stepOneSequenceBarrier, stepOneFunctionHandler);

            var stepTwoSequenceBarrier = _ringBuffer.NewBarrier(_stepOneBatchProcessor.Sequence);
            _stepTwoBatchProcessor = new BatchEventProcessor<FunctionEvent>(_ringBuffer, stepTwoSequenceBarrier, stepTwoFunctionHandler);

            var stepThreeSequenceBarrier = _ringBuffer.NewBarrier(_stepTwoBatchProcessor.Sequence);
            _stepThreeBatchProcessor = new BatchEventProcessor<FunctionEvent>(_ringBuffer, stepThreeSequenceBarrier, _stepThreeFunctionHandler);

            var temp = 0L;
            var operandTwo = _operandTwoInitialValue;

            for (long i = 0; i < _iterations; i++)
            {
                var stepOneResult = i + operandTwo--;
                var stepTwoResult = stepOneResult + 3;

                if ((stepTwoResult & 4L) == 4L)
                {
                    ++temp;
                }
            }
            _expectedResult = temp;

            _ringBuffer.AddGatingSequences(_stepThreeBatchProcessor.Sequence);
        }
Пример #5
0
        public OneToThreeDiamondSequencedThroughputTest()
        {
            var sequenceBarrier = _ringBuffer.NewBarrier();

            var fizzHandler = new FizzBuzzEventHandler(FizzBuzzStep.Fizz);

            _batchProcessorFizz = new BatchEventProcessor <FizzBuzzEvent>(_ringBuffer, sequenceBarrier, fizzHandler);

            var buzzHandler = new FizzBuzzEventHandler(FizzBuzzStep.Buzz);

            _batchProcessorBuzz = new BatchEventProcessor <FizzBuzzEvent>(_ringBuffer, sequenceBarrier, buzzHandler);

            var sequenceBarrierFizzBuzz = _ringBuffer.NewBarrier(_batchProcessorFizz.Sequence, _batchProcessorBuzz.Sequence);

            _fizzBuzzHandler        = new FizzBuzzEventHandler(FizzBuzzStep.FizzBuzz);
            _batchProcessorFizzBuzz = new BatchEventProcessor <FizzBuzzEvent>(_ringBuffer, sequenceBarrierFizzBuzz, _fizzBuzzHandler);

            var temp = 0L;

            for (long i = 0; i < _iterations; i++)
            {
                var fizz = 0 == (i % 3L);
                var buzz = 0 == (i % 5L);

                if (fizz && buzz)
                {
                    ++temp;
                }
            }
            _expectedResult = temp;

            _ringBuffer.AddGatingSequences(_batchProcessorFizzBuzz.Sequence);
        }
Пример #6
0
        private const int _ringSize = 16;  // Must be multiple of 2
        static void Main(string[] args)
        {
            var sw = new Stopwatch();

            sw.Start();

            var ringBuffer = RingBuffer <MyValueEntry> .CreateSingleProducer(() => new MyValueEntry(), _ringSize, new YieldingWaitStrategy());

            //Case A: 1 Producer - 1 Consumer (Unicast event)
            var sequenceBarrier        = ringBuffer.NewBarrier();
            var batchProcessorPrintVal = new BatchEventProcessor <MyValueEntry>(ringBuffer, sequenceBarrier, new MyValueAdditionHandler());

            var processorTask1 = Task.Run(() => batchProcessorPrintVal.Run());

            batchProcessorPrintVal.WaitUntilStarted(TimeSpan.FromSeconds(5));

            Simulator.SimulatePublishEvent(ringBuffer, 1000);

            batchProcessorPrintVal.Halt();
            Task.WaitAll(processorTask1);

            sw.Stop();

            Console.WriteLine($"elapsed {sw.ElapsedMilliseconds} ms");
            Console.Read();
        }
        private void doRun()
        {
            BatchEventProcessor <EventHolder> batchEventProcessor =
                new BatchEventProcessor <EventHolder>(ringBuffer,
                                                      ringBuffer.NewBarrier(),
                                                      eventHolderHandler);

            ringBuffer.AddGatingSequences(batchEventProcessor.Sequence);

            Thread t = new Thread(o => (o as BatchEventProcessor <EventHolder>).Run());

            t.Start(batchEventProcessor);

            long iterations = Constants.ITERATIONS;

            for (long l = 0; l < iterations; l++)
            {
                SimpleEvent e = new SimpleEvent(l, l, l, l);
                ringBuffer.PublishEvent(new EventTranslatorOneArg(), e);
            }

            while (batchEventProcessor.Sequence.Value != iterations - 1)
            {
                Thread.Sleep(0);
            }

            batchEventProcessor.Halt();
            t.Join();
        }
Пример #8
0
        public void ShouldAddEventProcessorsAfterPublishing()
        {
            var rb = _disruptor.GetRingBuffer();

            var b1 = new BatchEventProcessor <TestEvent>(rb, rb.NewBarrier(), new SleepingEventHandler());
            var b2 = new BatchEventProcessor <TestEvent>(rb, rb.NewBarrier(b1.GetSequence()), new SleepingEventHandler());
            var b3 = new BatchEventProcessor <TestEvent>(
                rb, rb.NewBarrier(b2.GetSequence()), new SleepingEventHandler());

            Assert.Equal(b1.GetSequence().GetValue(), -1L);
            Assert.Equal(b2.GetSequence().GetValue(), -1L);
            Assert.Equal(b3.GetSequence().GetValue(), -1L);

            rb.Publish(rb.Next());
            rb.Publish(rb.Next());
            rb.Publish(rb.Next());
            rb.Publish(rb.Next());
            rb.Publish(rb.Next());
            rb.Publish(rb.Next());

            _disruptor.HandleEventsWith(b1, b2, b3);

            Assert.Equal(5L, b1.GetSequence().GetValue());
            Assert.Equal(5L, b2.GetSequence().GetValue());
            Assert.Equal(5L, b3.GetSequence().GetValue());
        }
Пример #9
0
        internal EventHandlerGroup <T> CreateEventProcessors(ISequence[] barrierSequences, IEventHandler <T>[] eventHandlers)
        {
            CheckNotStarted();

            var processorSequences = new List <ISequence>(eventHandlers.Length);
            var barrier            = _ringBuffer.NewBarrier(barrierSequences);

            foreach (var eventHandler in eventHandlers)
            {
                var batchEventProcessor = new BatchEventProcessor <T>(_ringBuffer, barrier, eventHandler);
                if (_exceptionHandler != null)
                {
                    batchEventProcessor.SetExceptionHandler(_exceptionHandler);
                }

                _consumerRepository.Add(batchEventProcessor, eventHandler, barrier);
                processorSequences.Add(batchEventProcessor.Sequence);
            }

            if (processorSequences.Count > 0)
            {
                _consumerRepository.UnMarkEventProcessorsAsEndOfChain(barrierSequences);
            }

            return(new EventHandlerGroup <T>(this, _consumerRepository, processorSequences));
        }
Пример #10
0
        public static void Main(string[] args)
        {
            var executor   = new BasicExecutor(TaskScheduler.Current);
            var disruptor  = new Disruptor <StubEvent>(() => new StubEvent(-1), 1024, TaskScheduler.Current);
            var ringBuffer = disruptor.Start();

            // Construct 2 batch event processors.
            var handler1   = new DynamicHandler();
            var processor1 = new BatchEventProcessor <StubEvent>(ringBuffer, ringBuffer.NewBarrier(), handler1);

            var handler2   = new DynamicHandler();
            var processor2 = new BatchEventProcessor <StubEvent>(ringBuffer, ringBuffer.NewBarrier(processor1.Sequence), handler2);

            // Dynamically add both sequences to the ring buffer
            ringBuffer.AddGatingSequences(processor1.Sequence, processor2.Sequence);

            // Start the new batch processors.
            executor.Execute(processor1.Run);
            executor.Execute(processor2.Run);

            // Remove a processor.

            // Stop the processor
            processor2.Halt();
            // Wait for shutdown the complete
            handler2.WaitShutdown();
            // Remove the gating sequence from the ring buffer
            ringBuffer.RemoveGatingSequence(processor2.Sequence);
        }
Пример #11
0
        internal EventHandlerGroup <T> CreateEventProcessors(IEventProcessor[] barrierEventProcessors,
                                                             IEventHandler <T>[] eventHandlers, long startSequence = Sequencer.InitialCursorValue)
        {
            CheckNotStarted();

            var createdEventProcessors = new IEventProcessor[eventHandlers.Length];
            ISequenceBarrier barrier   = _ringBuffer.NewBarrier(Util.GetSequencesFor(barrierEventProcessors));

            for (int i = 0; i < eventHandlers.Length; i++)
            {
                var eventHandler = eventHandlers[i];

                var batchEventProcessor = new BatchEventProcessor <T>(_ringBuffer, barrier, eventHandler, startSequence);

                if (_exceptionHandler != null)
                {
                    batchEventProcessor.SetExceptionHandler(_exceptionHandler);
                }

                _eventProcessorRepository.Add(batchEventProcessor, eventHandler, barrier);
                createdEventProcessors[i] = batchEventProcessor;
            }

            if (createdEventProcessors.Length > 0)
            {
                _eventProcessorRepository.UnmarkEventProcessorsAsEndOfChain(barrierEventProcessors);
            }

            return(new EventHandlerGroup <T>(this, _eventProcessorRepository, createdEventProcessors));
        }
Пример #12
0
        public EventHandlerGroup <T> CreateEventProcessors(
            ISequence[] barrierSequences,
            IEventHandler <T>[] eventHandlers)
        {
            CheckNotStarted();

            var processorSequences = new ISequence[eventHandlers.Length];
            var barrier            = _ringBuffer.NewBarrier(barrierSequences);

            for (var i = 0; i < eventHandlers.Length; i++)
            {
                var eventHandler        = eventHandlers[i];
                var batchEventProcessor = new BatchEventProcessor <T>(_ringBuffer, barrier, eventHandler);

                if (_exceptionHandler != null)
                {
                    batchEventProcessor.SetExceptionHandler(_exceptionHandler);
                }

                _consumerRepository.Add(batchEventProcessor, eventHandler, barrier);
                processorSequences[i] = batchEventProcessor.GetSequence();
            }

            UpdateGatingSequencesForNextInChain(barrierSequences, processorSequences);
            return(new EventHandlerGroup <T>(this, _consumerRepository, processorSequences));
        }
        public OneToThreeSequencedThroughputTest()
            : base(Test_Disruptor, ITERATIONS, 7)
        {
            ThreadPool.SetMaxThreads(NUM_EVENT_PROCESSORS, NUM_EVENT_PROCESSORS);
            for (long i = 0; i < ITERATIONS; i++)
            {
                results[0] = Operation.Addition.Op(results[0], i);
                results[1] = Operation.Substraction.Op(results[1], i);
                results[2] = Operation.And.Op(results[2], i);
            }
            sequenceBarrier = ringBuffer.NewBarrier();

            handlers[0] = new ValueMutationEventHandler_v3(Operation.Addition);
            handlers[1] = new ValueMutationEventHandler_v3(Operation.Substraction);
            handlers[2] = new ValueMutationEventHandler_v3(Operation.And);

            batchEventProcessors[0] = new BatchEventProcessor <ValueEvent>(ringBuffer, sequenceBarrier, handlers[0]);
            batchEventProcessors[1] = new BatchEventProcessor <ValueEvent>(ringBuffer, sequenceBarrier, handlers[1]);
            batchEventProcessors[2] = new BatchEventProcessor <ValueEvent>(ringBuffer, sequenceBarrier, handlers[2]);

            ringBuffer.AddGatingSequences(
                batchEventProcessors[0].Sequence,
                batchEventProcessors[1].Sequence,
                batchEventProcessors[2].Sequence);
        }
        public EventHandlerGroup <T> CreateEventProcessors(Sequence[] barrierSequences,
                                                           IEventHandler <T>[] eventHandlers)
        {
            CheckNotStarted();

            var processorSequences = new Sequence[eventHandlers.Length];
            var barrier            = ringBuffer.NewBarrier(barrierSequences);

            for (int i = 0, eventHandlersLength = eventHandlers.Length; i < eventHandlersLength; i++)
            {
                IEventHandler <T> eventHandler = eventHandlers[i];

                BatchEventProcessor <T> batchEventProcessor = new BatchEventProcessor <T>(ringBuffer, barrier, eventHandler);

                if (exceptionHandler != null)
                {
                    batchEventProcessor.SetExceptionHandler(exceptionHandler);
                }

                consumerRepository.Add(batchEventProcessor, eventHandler, barrier);
                processorSequences[i] = batchEventProcessor.Sequence;
            }

            if (processorSequences.Length > 0)
            {
                consumerRepository.UnMarkEventProcessorsAsEndOfChain(barrierSequences);
            }

            return(new EventHandlerGroup <T>(this, consumerRepository, processorSequences));
        }
        public OneToThreeDiamondSequencedThroughputTest()
        {
            var sequenceBarrier = _ringBuffer.NewBarrier();

            var fizzHandler = new FizzBuzzEventHandler(FizzBuzzStep.Fizz);
            _batchProcessorFizz = new BatchEventProcessor<FizzBuzzEvent>(_ringBuffer, sequenceBarrier, fizzHandler);

            var buzzHandler = new FizzBuzzEventHandler(FizzBuzzStep.Buzz);
            _batchProcessorBuzz = new BatchEventProcessor<FizzBuzzEvent>(_ringBuffer, sequenceBarrier, buzzHandler);

            var sequenceBarrierFizzBuzz = _ringBuffer.NewBarrier(_batchProcessorFizz.Sequence, _batchProcessorBuzz.Sequence);

            _fizzBuzzHandler = new FizzBuzzEventHandler(FizzBuzzStep.FizzBuzz);
            _batchProcessorFizzBuzz = new BatchEventProcessor<FizzBuzzEvent>(_ringBuffer, sequenceBarrierFizzBuzz, _fizzBuzzHandler);

            var temp = 0L;
            for (long i = 0; i < _iterations; i++)
            {
                var fizz = 0 == (i % 3L);
                var buzz = 0 == (i % 5L);

                if (fizz && buzz)
                {
                    ++temp;
                }
            }
            _expectedResult = temp;

            _ringBuffer.AddGatingSequences(_batchProcessorFizzBuzz.Sequence);
        }
 public OneToOneSequencedBatchThroughputTest()
 {
     _ringBuffer = RingBuffer<ValueEvent>.CreateSingleProducer(ValueEvent.EventFactory, _bufferSize, new YieldingWaitStrategy());
     var sequenceBarrier = _ringBuffer.NewBarrier();
     _handler = new ValueAdditionEventHandler();
     _batchEventProcessor = new BatchEventProcessor<ValueEvent>(_ringBuffer, sequenceBarrier, _handler);
     _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
 }
 public OneToOneSequencedLongArrayThroughputTest()
     : base(Test_Disruptor, ITERATIONS,7)
 {
     ThreadPool.SetMaxThreads (1,1);
     sequenceBarrier = ringBuffer.NewBarrier();
     batchEventProcessor = new BatchEventProcessor<long[]>(ringBuffer, sequenceBarrier, handler);
     ringBuffer.AddGatingSequences(batchEventProcessor.Sequence);
 }
Пример #18
0
        public EventProcessorProps(BatchEventProcessor eventProcessor)
        {
            var fieldsInfo = Reflection.GetAllFields(eventProcessor.GetType());

            BatchSize       = Reflection.GetFieldValue <int, BatchEventProcessor>(eventProcessor, "BatchSize", fieldsInfo);
            FlushInterval   = Reflection.GetFieldValue <TimeSpan, BatchEventProcessor>(eventProcessor, "FlushInterval", fieldsInfo);
            TimeoutInterval = Reflection.GetFieldValue <TimeSpan, BatchEventProcessor>(eventProcessor, "TimeoutInterval", fieldsInfo);
        }
 public OneToOneSequencedBatchThroughputTest()
     : base(Test_Disruptor, ITERATIONS, 7)
 {
     ThreadPool.SetMaxThreads(4, 4);
     sequenceBarrier     = ringBuffer.NewBarrier();
     batchEventProcessor = new BatchEventProcessor <ValueEvent>(ringBuffer, sequenceBarrier, handler);
     ringBuffer.AddGatingSequences(batchEventProcessor.Sequence);
 }
 public OneToOneSequencedLongArrayThroughputTest()
 {
     _ringBuffer = RingBuffer<long[]>.CreateSingleProducer(() => new long[_arraySize], _bufferSize, new YieldingWaitStrategy());
     var sequenceBarrier = _ringBuffer.NewBarrier();
     _handler = new LongArrayEventHandler();
     _batchEventProcessor = new BatchEventProcessor<long[]>(_ringBuffer, sequenceBarrier, _handler);
     _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
 }
Пример #21
0
        public OnePublisherToOneProcessorUniCastThroughputTest()
            : base("Disruptor", ITERATIONS)
        {
            sequenceBarrier     = ringBuffer.NewBarrier();
            batchEventProcessor = new BatchEventProcessor <ValueEvent>(ringBuffer, sequenceBarrier, disruptorHandler);
            ringBuffer.AddGatingSequences(batchEventProcessor.Sequence);

            //queueHandler = new ValueAdditionQueueProcessor_V3(blockQueue, ITERATIONS - 1);
        }
Пример #22
0
 public void Setup()
 {
     _ringBuffer          = new RingBuffer <StubEvent>(() => new StubEvent(-1), 16);
     _sequenceBarrier     = _ringBuffer.NewBarrier();
     _batchHandlerMock    = new Mock <IEventHandler <StubEvent> >();
     _countDownEvent      = new CountdownEvent(1);
     _batchEventProcessor = new BatchEventProcessor <StubEvent>(_ringBuffer, _sequenceBarrier, _batchHandlerMock.Object);
     _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
 }
        public OnePublisherToOneProcessorUniCastThroughputTest()
            : base("Disruptor", ITERATIONS)
        {
            sequenceBarrier = ringBuffer.NewBarrier();
            batchEventProcessor = new BatchEventProcessor<ValueEvent>(ringBuffer, sequenceBarrier, disruptorHandler);
            ringBuffer.AddGatingSequences(batchEventProcessor.Sequence);

            //queueHandler = new ValueAdditionQueueProcessor_V3(blockQueue, ITERATIONS - 1);
        }
 public void Setup()
 {
     _ringBuffer = new RingBuffer<StubEvent>(()=>new StubEvent(-1), 16);
     _sequenceBarrier = _ringBuffer.NewBarrier();
     _batchHandlerMock = new Mock<IEventHandler<StubEvent>>();
     _countDownEvent = new CountdownEvent(1);
     _batchEventProcessor = new BatchEventProcessor<StubEvent>(_ringBuffer, _sequenceBarrier, _batchHandlerMock.Object);
     _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
 }
Пример #25
0
        public OneToOneSequencedLongArrayThroughputTest()
        {
            _ringBuffer = RingBuffer <long[]> .CreateSingleProducer(() => new long[_arraySize], _bufferSize, new YieldingWaitStrategy());

            var sequenceBarrier = _ringBuffer.NewBarrier();

            _handler             = new LongArrayEventHandler();
            _batchEventProcessor = new BatchEventProcessor <long[]>(_ringBuffer, sequenceBarrier, _handler);
            _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
        }
Пример #26
0
        public OneToOneSequencedBatchThroughputTest()
        {
            _ringBuffer = RingBuffer <ValueEvent> .CreateSingleProducer(ValueEvent.EventFactory, _bufferSize, new YieldingWaitStrategy());

            var sequenceBarrier = _ringBuffer.NewBarrier();

            _handler             = new ValueAdditionEventHandler();
            _batchEventProcessor = new BatchEventProcessor <ValueEvent>(_ringBuffer, sequenceBarrier, _handler);
            _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
        }
 public ThreeToOneSequencedThroughputTest()
 {
     _sequenceBarrier     = _ringBuffer.NewBarrier();
     _batchEventProcessor = new BatchEventProcessor <ValueEvent>(_ringBuffer, _sequenceBarrier, _handler);
     for (var i = 0; i < _numPublishers; i++)
     {
         _valuePublishers[i] = ValuePublisher;
     }
     _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
 }
 public ThreeToOneSequencedThroughputTest()
 {
     _sequenceBarrier = _ringBuffer.NewBarrier();
     _batchEventProcessor = new BatchEventProcessor<ValueEvent>(_ringBuffer, _sequenceBarrier, _handler);
     for (var i = 0; i < _numPublishers; i++)
     {
         _valuePublishers[i] = ValuePublisher;
     }
     _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
 }
Пример #29
0
        public BatchEventProcessor <IEventAccessor <T> > createHandler(IEventHandler <T> handler)
        {
            BatchEventProcessor <IEventAccessor <T> > processor =
                new BatchEventProcessor <IEventAccessor <T> >(this,
                                                              sequencer.NewBarrier(),
                                                              new AccessorEventHandler <T>(handler));

            sequencer.AddGatingSequences(processor.Sequence);

            return(processor);
        }
        public ThreeToOneSequencedBatchThroughputTest()
        {
            var sequenceBarrier = _ringBuffer.NewBarrier();
            for (var i = 0; i < _numPublishers; i++)
            {
                _valuePublishers[i] = new ValueBatchPublisher(_cyclicBarrier, _ringBuffer, _iterations / _numPublishers, 10);
            }

            _batchEventProcessor = new BatchEventProcessor<ValueEvent>(_ringBuffer, sequenceBarrier, _handler);
            _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
        }
        public ThreeToOneSequencedBatchThroughputTest()
        {
            var sequenceBarrier = _ringBuffer.NewBarrier();

            for (var i = 0; i < _numPublishers; i++)
            {
                _valuePublishers[i] = new ValueBatchPublisher(_cyclicBarrier, _ringBuffer, _iterations / _numPublishers, 10);
            }

            _batchEventProcessor = new BatchEventProcessor <ValueEvent>(_ringBuffer, sequenceBarrier, _handler);
            _ringBuffer.AddGatingSequences(_batchEventProcessor.Sequence);
        }
Пример #32
0
 private void SetEventProcessor(IEventDispatcher eventDispatcher)
 {
     EventProcessor = new BatchEventProcessor.Builder()
                      .WithEventQueue(eventQueue)
                      .WithEventDispatcher(eventDispatcher)
                      .WithMaxBatchSize(MAX_BATCH_SIZE)
                      .WithFlushInterval(TimeSpan.FromMilliseconds(MAX_DURATION_MS))
                      .WithTimeoutInterval(TimeSpan.FromMilliseconds(TIMEOUT_INTERVAL_MS))
                      .WithLogger(LoggerMock.Object)
                      .WithNotificationCenter(NotificationCenter)
                      .Build();
 }
        public ThreeToOneSequencedBatchThroughputTest()
            : base(Test_Disruptor, ITERATIONS,7)
        {
            ThreadPool.SetMaxThreads (4,4);
            sequenceBarrier = ringBuffer.NewBarrier();
            batchEventProcessor = new BatchEventProcessor<ValueEvent>(ringBuffer, sequenceBarrier, handler);

            for (int i = 0; i < NUM_PUBLISHERS; i++)
            {
                valuePublishers[i] = new ValueBatchPublisher(cyclicBarrier, ringBuffer, ITERATIONS / NUM_PUBLISHERS, 10);
            }
            ringBuffer.AddGatingSequences(batchEventProcessor.Sequence);
        }
Пример #34
0
        public async Task Should()
        {
            var rb = _disruptor.GetRingBuffer();
            var p1 = new BatchEventProcessor <TestEvent>(
                rb, rb.NewBarrier(), new SleepingEventHandler());
            var p2 = new EventProcessorFactory();

            _disruptor
            .HandleEventsWith(p1)
            .Then(p2);

            await _disruptor.StartAsync();
        }
Пример #35
0
        public ThreeToOneSequencedBatchThroughputTest()
            : base(Test_Disruptor, ITERATIONS, 7)
        {
            ThreadPool.SetMaxThreads(4, 4);
            sequenceBarrier     = ringBuffer.NewBarrier();
            batchEventProcessor = new BatchEventProcessor <ValueEvent>(ringBuffer, sequenceBarrier, handler);

            for (int i = 0; i < NUM_PUBLISHERS; i++)
            {
                valuePublishers[i] = new ValueBatchPublisher(cyclicBarrier, ringBuffer, ITERATIONS / NUM_PUBLISHERS, 10);
            }
            ringBuffer.AddGatingSequences(batchEventProcessor.Sequence);
        }
        public PingPongLatencyTest()
        {
            InitHistogram();
            pongBarrier   = pongBuffer.NewBarrier();
            pinger        = new Pinger(pingBuffer, ITERATIONS, PAUSE_NANOS);
            pingProcessor = new BatchEventProcessor <ValueEvent>(pongBuffer, pongBarrier, pinger);

            pingBarrier   = pingBuffer.NewBarrier();
            ponger        = new Ponger(pongBuffer);
            pongProcessor = new BatchEventProcessor <ValueEvent>(pingBuffer, pingBarrier, ponger);

            pingBuffer.AddGatingSequences(pongProcessor.Sequence);
            pongBuffer.AddGatingSequences(pingProcessor.Sequence);
        }
Пример #37
0
        public OneToThreePipelineSequencedThroughputTest()
            : base(Test_Disruptor, ITERATIONS, 7)
        {
            ThreadPool.SetMaxThreads(NUM_EVENT_PROCESSORS, NUM_EVENT_PROCESSORS);
            stepOneSequenceBarrier = ringBuffer.NewBarrier();
            stepOneBatchProcessor  = new BatchEventProcessor <FunctionEvent>(ringBuffer, stepOneSequenceBarrier, stepOneFunctionHandler);
            stepTwoSequenceBarrier = ringBuffer.NewBarrier(stepOneBatchProcessor.Sequence);

            stepTwoBatchProcessor    = new BatchEventProcessor <FunctionEvent>(ringBuffer, stepTwoSequenceBarrier, stepTwoFunctionHandler);
            stepThreeSequenceBarrier = ringBuffer.NewBarrier(stepTwoBatchProcessor.Sequence);
            stepThreeBatchProcessor  = new BatchEventProcessor <FunctionEvent>(ringBuffer, stepThreeSequenceBarrier, stepThreeFunctionHandler);

            ringBuffer.AddGatingSequences(stepThreeBatchProcessor.Sequence);
        }
Пример #38
0
        public void ShouldSupportCustomProcessorsAsDependencies()
        {
            var ringBuffer = _disruptor.RingBuffer;

            var delayedEventHandler = CreateDelayedEventHandler();

            var countDownLatch = new CountdownEvent(2);
            IEventHandler <TestEvent> handlerWithBarrier = new EventHandlerStub <TestEvent>(countDownLatch);

            var processor = new BatchEventProcessor <TestEvent>(ringBuffer, ringBuffer.NewBarrier(), delayedEventHandler);

            _disruptor.HandleEventsWith(processor).Then(handlerWithBarrier);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
        }
Пример #39
0
        public OnePublisherToThreeProcessorDiamondThroughputTest()
            : base(TestName, 1000L * 1000L * 100L)
        {
            ringBuffer = RingBuffer <FizzBuzzEvent> .CreateSingleProducer(() => new FizzBuzzEvent(), 1024 * 8, new YieldingWaitStrategy());

            sequenceBarrier = ringBuffer.NewBarrier();

            batchProcessorFizz = new BatchEventProcessor <FizzBuzzEvent>(ringBuffer, sequenceBarrier, fizzHandler);

            batchProcessorBuzz      = new BatchEventProcessor <FizzBuzzEvent>(ringBuffer, sequenceBarrier, buzzHandler);
            sequenceBarrierFizzBuzz = ringBuffer.NewBarrier(batchProcessorFizz.Sequence, batchProcessorBuzz.Sequence);

            batchProcessorFizzBuzz = new BatchEventProcessor <FizzBuzzEvent>(ringBuffer, sequenceBarrierFizzBuzz, fizzBuzzHandler);
            ringBuffer.AddGatingSequences(batchProcessorFizzBuzz.Sequence);
        }
        public OnePublisherToThreeProcessorPipelineThroughputTest()
            : base(TestName, ITERATIONS)
        {
            InitResult();

            stepOneSequenceBarrier = ringBuffer.NewBarrier();
            stepOneBatchProcessor  = new BatchEventProcessor <FunctionEvent>(ringBuffer, stepOneSequenceBarrier, stepOneFunctionHandler);

            stepTwoSequenceBarrier = ringBuffer.NewBarrier(stepOneBatchProcessor.Sequence);
            stepTwoBatchProcessor  = new BatchEventProcessor <FunctionEvent>(ringBuffer, stepTwoSequenceBarrier, stepTwoFunctionHandler);

            stepThreeSequenceBarrier = ringBuffer.NewBarrier(stepTwoBatchProcessor.Sequence);
            stepThreeBatchProcessor  = new BatchEventProcessor <FunctionEvent>(ringBuffer, stepThreeSequenceBarrier, stepThreeFunctionHandler);

            ringBuffer.AddGatingSequences(stepThreeBatchProcessor.Sequence);
        }
        public OneToThreeSequencedThroughputTest()
        {
            for (long i = 0; i < _iterations; i++)
            {
                _results[0] = Operation.Addition.Op(_results[0], i);
                _results[1] = Operation.Subtraction.Op(_results[1], i);
                _results[2] = Operation.And.Op(_results[2], i);
            }

            _ringBuffer = RingBuffer<ValueEvent>.CreateSingleProducer(ValueEvent.EventFactory, _bufferSize, new YieldingWaitStrategy());
            var sequenceBarrier = _ringBuffer.NewBarrier();

            _handlers[0] = new ValueMutationEventHandler(Operation.Addition);
            _handlers[1] = new ValueMutationEventHandler(Operation.Subtraction);
            _handlers[2] = new ValueMutationEventHandler(Operation.And);

            for (var i = 0; i < _numEventProcessors; i++)
            {
                _batchEventProcessors[i] = new BatchEventProcessor<ValueEvent>(_ringBuffer, sequenceBarrier, _handlers[i]);
            }
            _ringBuffer.AddGatingSequences(_batchEventProcessors.Select(x => x.Sequence).ToArray());
        }
        public OneToThreeDiamondSequencedThroughputTest()
            : base(Test_Disruptor, ITERATIONS,7)
        {
            ThreadPool.SetMaxThreads(NUM_EVENT_PROCESSORS, NUM_EVENT_PROCESSORS);
            sequenceBarrier = ringBuffer.NewBarrier();
            fizzHandler = new FizzBuzzEventHandler2(FizzBuzzStep.Fizz);

            batchProcessorFizz =
            new BatchEventProcessor<FizzBuzzEvent>(ringBuffer, sequenceBarrier, fizzHandler);

            buzzHandler = new FizzBuzzEventHandler2(FizzBuzzStep.Buzz);
            batchProcessorBuzz =
        new BatchEventProcessor<FizzBuzzEvent>(ringBuffer, sequenceBarrier, buzzHandler);

            sequenceBarrierFizzBuzz =
       ringBuffer.NewBarrier(batchProcessorFizz.Sequence, batchProcessorBuzz.Sequence);

            fizzBuzzHandler = new FizzBuzzEventHandler2(FizzBuzzStep.FizzBuzz);
            batchProcessorFizzBuzz = new BatchEventProcessor<FizzBuzzEvent>(ringBuffer, sequenceBarrier, fizzBuzzHandler);

            ringBuffer.AddGatingSequences(batchProcessorFizzBuzz.Sequence);
        }
        public OnePublisherToThreeProcessorDiamondThroughputTest()
            : base(TestName, 1000L * 1000L * 100L)
        {
            ringBuffer = RingBuffer<FizzBuzzEvent>.CreateSingleProducer(() => new FizzBuzzEvent(), 1024 * 8, new YieldingWaitStrategy());
            sequenceBarrier = ringBuffer.NewBarrier();

            batchProcessorFizz = new BatchEventProcessor<FizzBuzzEvent>(ringBuffer, sequenceBarrier, fizzHandler);

            batchProcessorBuzz = new BatchEventProcessor<FizzBuzzEvent>(ringBuffer, sequenceBarrier, buzzHandler);
            sequenceBarrierFizzBuzz = ringBuffer.NewBarrier(batchProcessorFizz.Sequence, batchProcessorBuzz.Sequence);

            batchProcessorFizzBuzz = new BatchEventProcessor<FizzBuzzEvent>(ringBuffer, sequenceBarrierFizzBuzz, fizzBuzzHandler);
            ringBuffer.AddGatingSequences(batchProcessorFizzBuzz.Sequence);

        }
        public PingPongLatencyTest()
        {
            InitHistogram();
            pongBarrier = pongBuffer.NewBarrier();
            pinger = new Pinger(pingBuffer, ITERATIONS, PAUSE_NANOS);
            pingProcessor = new BatchEventProcessor<ValueEvent>(pongBuffer, pongBarrier, pinger);

            pingBarrier = pingBuffer.NewBarrier();
            ponger = new Ponger(pongBuffer);
            pongProcessor = new BatchEventProcessor<ValueEvent>(pingBuffer, pingBarrier, ponger);

            pingBuffer.AddGatingSequences(pongProcessor.Sequence);
            pongBuffer.AddGatingSequences(pingProcessor.Sequence);
        }
        public OneToThreeSequencedThroughputTest()
            : base(Test_Disruptor, ITERATIONS,7)
        {
            ThreadPool.SetMaxThreads(NUM_EVENT_PROCESSORS,NUM_EVENT_PROCESSORS);
            for (long i = 0; i < ITERATIONS; i++)
            {
                results[0] = Operation.Addition.Op(results[0], i);
                results[1] = Operation.Substraction.Op(results[1], i);
                results[2] = Operation.And.Op(results[2], i);
            }
            sequenceBarrier = ringBuffer.NewBarrier();

            handlers[0] = new ValueMutationEventHandler_v3(Operation.Addition);
            handlers[1] = new ValueMutationEventHandler_v3(Operation.Substraction);
            handlers[2] = new ValueMutationEventHandler_v3(Operation.And);

            batchEventProcessors[0] = new BatchEventProcessor<ValueEvent>(ringBuffer, sequenceBarrier, handlers[0]);
            batchEventProcessors[1] = new BatchEventProcessor<ValueEvent>(ringBuffer, sequenceBarrier, handlers[1]);
            batchEventProcessors[2] = new BatchEventProcessor<ValueEvent>(ringBuffer, sequenceBarrier, handlers[2]);

            ringBuffer.AddGatingSequences(
                                     batchEventProcessors[0].Sequence,
                                     batchEventProcessors[1].Sequence,
                                     batchEventProcessors[2].Sequence);
        }
        public OnePublisherToThreeProcessorPipelineThroughputTest()
            : base(TestName, ITERATIONS)
        {
            InitResult();

            stepOneSequenceBarrier = ringBuffer.NewBarrier();
            stepOneBatchProcessor = new BatchEventProcessor<FunctionEvent>(ringBuffer, stepOneSequenceBarrier, stepOneFunctionHandler);

            stepTwoSequenceBarrier = ringBuffer.NewBarrier(stepOneBatchProcessor.Sequence);
            stepTwoBatchProcessor = new BatchEventProcessor<FunctionEvent>(ringBuffer, stepTwoSequenceBarrier, stepTwoFunctionHandler);

            stepThreeSequenceBarrier = ringBuffer.NewBarrier(stepTwoBatchProcessor.Sequence);
            stepThreeBatchProcessor = new BatchEventProcessor<FunctionEvent>(ringBuffer, stepThreeSequenceBarrier, stepThreeFunctionHandler);

            ringBuffer.AddGatingSequences(stepThreeBatchProcessor.Sequence);
        }
        public ThrottledOnePublisherToThreeProcessorPipelineLatencyTest()
        //: base(TestName, ITERATIONS)
        {
            InitHistogram();

            stepOneSequenceBarrier = ringBuffer.NewBarrier();
            stepOneFunctionHandler = new LatencyStepEventHandler_V3(FunctionStep.One, _histogram, TicksToNanos);
            stepOneBatchProcessor = new BatchEventProcessor<ValueEvent>(ringBuffer, stepOneSequenceBarrier, stepOneFunctionHandler);

            stepTwoSequenceBarrier = ringBuffer.NewBarrier(stepOneBatchProcessor.Sequence);
            stepTwoFunctionHandler = new LatencyStepEventHandler_V3(FunctionStep.Two, _histogram, TicksToNanos);
            stepTwoBatchProcessor = new BatchEventProcessor<ValueEvent>(ringBuffer, stepTwoSequenceBarrier, stepTwoFunctionHandler);

            stepThreeSequenceBarrier = ringBuffer.NewBarrier(stepTwoBatchProcessor.Sequence);
            stepThreeFunctionHandler = new LatencyStepEventHandler_V3(FunctionStep.Three, _histogram, TicksToNanos);
            stepThreeBatchProcessor = new BatchEventProcessor<ValueEvent>(ringBuffer, stepThreeSequenceBarrier, stepThreeFunctionHandler);

            ringBuffer.AddGatingSequences(stepThreeBatchProcessor.Sequence);
        }
        public OneToThreePipelineSequencedThroughputTest()
            : base(Test_Disruptor, ITERATIONS,7)
        {
            ThreadPool.SetMaxThreads(NUM_EVENT_PROCESSORS, NUM_EVENT_PROCESSORS);
            stepOneSequenceBarrier = ringBuffer.NewBarrier();
            stepOneBatchProcessor = new BatchEventProcessor<FunctionEvent>(ringBuffer, stepOneSequenceBarrier, stepOneFunctionHandler);
            stepTwoSequenceBarrier = ringBuffer.NewBarrier(stepOneBatchProcessor.Sequence);

            stepTwoBatchProcessor = new BatchEventProcessor<FunctionEvent>(ringBuffer, stepTwoSequenceBarrier, stepTwoFunctionHandler);
            stepThreeSequenceBarrier = ringBuffer.NewBarrier(stepTwoBatchProcessor.Sequence);
            stepThreeBatchProcessor = new BatchEventProcessor<FunctionEvent>(ringBuffer, stepThreeSequenceBarrier, stepThreeFunctionHandler);

            ringBuffer.AddGatingSequences(stepThreeBatchProcessor.Sequence);

        }