public long Run(ThroughputSessionContext sessionContext) { var latch = new ManualResetEvent(false); _fizzBuzzHandler.Reset(latch, _batchProcessorFizzBuzz.Sequence.Value + _iterations); var processorTask1 = Task.Run(() => _batchProcessorFizz.Run()); var processorTask2 = Task.Run(() => _batchProcessorBuzz.Run()); var processorTask3 = Task.Run(() => _batchProcessorFizzBuzz.Run()); _batchProcessorFizz.WaitUntilStarted(TimeSpan.FromSeconds(5)); _batchProcessorBuzz.WaitUntilStarted(TimeSpan.FromSeconds(5)); _batchProcessorFizzBuzz.WaitUntilStarted(TimeSpan.FromSeconds(5)); sessionContext.Start(); for (long i = 0; i < _iterations; i++) { var sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = i; _ringBuffer.Publish(sequence); } latch.WaitOne(); sessionContext.Stop(); _batchProcessorFizz.Halt(); _batchProcessorBuzz.Halt(); _batchProcessorFizzBuzz.Halt(); Task.WaitAll(processorTask1, processorTask2, processorTask3); PerfTestUtil.FailIfNot(_expectedResult, _fizzBuzzHandler.FizzBuzzCounter); return(_iterations); }
public long Run(ThroughputSessionContext sessionContext) { long expectedCount = _batchEventProcessor.Sequence.Value + _iterations; _eventHandler.Reset(expectedCount); var processorTask = _executor.Execute(() => _batchEventProcessor.Run()); _batchEventProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5)); sessionContext.Start(); var ringBuffer = _ringBuffer; for (long i = 0; i < _iterations; i++) { var s = ringBuffer.Next(); ringBuffer[s].Value = i; ringBuffer.Publish(s); } _eventHandler.WaitForSequence(); sessionContext.Stop(); PerfTestUtil.WaitForEventProcessorSequence(expectedCount, _batchEventProcessor); _batchEventProcessor.Halt(); processorTask.Wait(2000); sessionContext.SetBatchData(_eventHandler.BatchesProcessed, _iterations); PerfTestUtil.FailIfNot(_expectedResult, _eventHandler.Value, $"Handler should have processed {_expectedResult} events, but was: {_eventHandler.Value}"); return(_iterations); }
public long Run(ThroughputSessionContext sessionContext) { _cyclicBarrier.Reset(); _handler.Reset(_batchEventProcessor.Sequence.Value + ((_iterations / _numPublishers) * _numPublishers)); var futures = new Task[_numPublishers]; for (var i = 0; i < _numPublishers; i++) { var index = i; futures[i] = Task.Factory.StartNew(() => _valuePublishers[index](_cyclicBarrier, _ringBuffer, _iterations / _numPublishers), CancellationToken.None, TaskCreationOptions.None, _scheduler); } var processorTask = Task.Factory.StartNew(() => _batchEventProcessor.Run(), CancellationToken.None, TaskCreationOptions.None, _scheduler); _batchEventProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5)); sessionContext.Start(); _cyclicBarrier.Signal(); _cyclicBarrier.Wait(); for (var i = 0; i < _numPublishers; i++) { futures[i].Wait(); } _handler.WaitForSequence(); sessionContext.Stop(); _batchEventProcessor.Halt(); processorTask.Wait(2000); sessionContext.SetBatchData(_handler.BatchesProcessed, _iterations); return(_iterations); }
public void Run() { if (IsRunning) { return; } var sequenceBarrier = _ringBuffer.NewBarrier(); var orderEventHandler = new OrderEventHandler(); _orderBatchProcessor = BatchEventProcessorFactory.Create(_ringBuffer, sequenceBarrier, orderEventHandler); _orderBatchProcessor.WaitUntilStarted(TimeSpan.FromSeconds(3)); _tasks.Add(Task.Run(() => _orderBatchProcessor.Run())); IsRunning = true; _latch.WaitOne(); _orderBatchProcessor.Halt(); Task.WaitAll(_tasks.ToArray()); IsRunning = false; }