コード例 #1
0
        public long Run(ThroughputSessionContext sessionContext)
        {
            var value = _value;

            var latch         = new ManualResetEvent(false);
            var expectedCount = _ringBuffer.GetMinimumGatingSequence() + _iterations;

            _handler.Reset(latch, expectedCount);
            sessionContext.Start();

            var rb = _ringBuffer;

            for (long l = 0; l < _iterations; l++)
            {
                value.Value = l;
                rb.PublishEvent(Translator.Instance, value);
            }

            latch.WaitOne();
            sessionContext.Stop();
            WaitForEventProcessorSequence(expectedCount);

            PerfTestUtil.FailIfNot(_expectedResult, _handler.Value);

            sessionContext.SetBatchData(_handler.BatchesProcessedCount.Value, _iterations);

            return(_iterations);
        }
        protected override long RunQueuePass()
        {
            CountdownEvent latch = new CountdownEvent(1);

            stepThreeQueueProcessor.reset(latch);

            CancellationTokenSource cance = new CancellationTokenSource();
            var t1    = Task.Factory.StartNew(() => stepOneQueueProcessor.run(), cance.Token, TaskCreationOptions.None, TaskScheduler.Default);
            var t2    = Task.Factory.StartNew(() => stepTwoQueueProcessor.run(), cance.Token, TaskCreationOptions.None, TaskScheduler.Default);
            var t3    = Task.Factory.StartNew(() => stepThreeQueueProcessor.run(), cance.Token, TaskCreationOptions.None, TaskScheduler.Default);
            var start = Stopwatch.StartNew();

            long operandTwo = OPERAND_TWO_INITIAL_VALUE;

            for (long i = 0; i < ITERATIONS; i++)
            {
                long[] values = new long[2];
                values[0] = i;
                values[1] = operandTwo--;
                stepOneQueue.Enqueue(values);
            }
            latch.Wait();
            long opsPerSecond = (ITERATIONS * 1000L) / (start.ElapsedMilliseconds);

            stepOneQueueProcessor.halt();
            stepTwoQueueProcessor.halt();
            stepThreeQueueProcessor.halt();

            cance.Cancel();

            PerfTestUtil.failIf(expectedResult, 0);

            return(opsPerSecond);
        }
    public long Run(ThroughputSessionContext sessionContext)
    {
        _eventHandler.Reset(_iterations - 1);
        _consumer.Start();

        sessionContext.Start();

        var spinWait = new SpinWait();

        for (long i = 0; i < _iterations; i++)
        {
            var data = new PerfEvent {
                Value = i
            };
            while (_queue.Count == _bufferSize)
            {
                spinWait.SpinOnce();
            }
            _queue.Enqueue(data);
            spinWait.Reset();
        }

        _eventHandler.WaitForSequence();
        sessionContext.Stop();
        _consumer.Stop();

        sessionContext.SetBatchData(_eventHandler.BatchesProcessed, _iterations);

        PerfTestUtil.FailIfNot(_expectedResult, _eventHandler.Value, $"Handler should have processed {_expectedResult} events, but was: {_eventHandler.Value}");

        return(_iterations);
    }
コード例 #4
0
    public long Run(ThroughputSessionContext sessionContext)
    {
        long expectedCount = _eventProcessor.Sequence.Value + _iterations;

        _eventHandler.Reset(expectedCount);
        var processorTask = _eventProcessor.Start();

        _eventProcessor.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, _eventProcessor);
        _eventProcessor.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);
    }
        protected override long RunDisruptorPass()
        {
            CountdownEvent latch         = new CountdownEvent(1);
            long           expectedCount = batchEventProcessor.Sequence.Value + ITERATIONS;

            handler.Reset(latch, ITERATIONS);
            Task.Factory.StartNew(() => batchEventProcessor.Run());
            Stopwatch start = Stopwatch.StartNew();

            RingBuffer <long[]> rb = ringBuffer;

            for (long i = 0; i < ITERATIONS; i++)
            {
                long   next   = rb.Next();
                long[] @event = rb.Get(next);
                for (int j = 0; j < @event.Length; j++)
                {
                    @event[j] = i;
                }
                rb.Publish(next);
            }

            latch.Wait();
            long opsPerSecond = (ITERATIONS * ARRAY_SIZE * 1000L) / (start.ElapsedMilliseconds);

            waitForEventProcessorSequence(expectedCount);
            batchEventProcessor.Halt();

            PerfTestUtil.failIf(0, handler.Value);

            return(opsPerSecond);
        }
コード例 #6
0
        public long Run(Stopwatch stopwatch)
        {
            var latch         = new ManualResetEvent(false);
            var expectedCount = _poller.Sequence.Value + _iterations;

            _pollRunnable.Reset(latch, expectedCount);
            var processorTask = _executor.Execute(_pollRunnable.Run);

            stopwatch.Start();

            var rb = _ringBuffer;

            for (var i = 0; i < _iterations; i++)
            {
                var next = rb.Next();
                rb[next].Value = i;
                rb.Publish(next);
            }

            latch.WaitOne();
            stopwatch.Stop();
            WaitForEventProcessorSequence(expectedCount);
            _pollRunnable.Halt();
            processorTask.Wait(2000);

            PerfTestUtil.FailIfNot(_expectedResult, _pollRunnable.Value, $"Poll runnable should have processed {_expectedResult} but was {_pollRunnable.Value}");

            return(_iterations);
        }
コード例 #7
0
        public long Run(ThroughputSessionContext sessionContext)
        {
            var latch         = new ManualResetEvent(false);
            var expectedCount = _poller.Sequence.Value + _iterations;

            _pollRunnable.Reset(latch, expectedCount);
            var processorTask = _pollRunnable.Start();

            sessionContext.Start();

            var ringBuffer = _ringBuffer;

            for (var i = 0; i < _iterations; i++)
            {
                var next = ringBuffer.Next();
                ringBuffer[next].Value = i;
                ringBuffer.Publish(next);
            }

            latch.WaitOne();
            sessionContext.Stop();
            WaitForEventProcessorSequence(expectedCount);
            _pollRunnable.Halt();
            processorTask.Wait(2000);

            sessionContext.SetBatchData(_pollRunnable.BatchesProcessedCount.Value, _iterations);

            PerfTestUtil.FailIfNot(_expectedResult, _pollRunnable.Value, $"Poll runnable should have processed {_expectedResult} but was {_pollRunnable.Value}");

            return(_iterations);
        }
コード例 #8
0
        protected override long RunDisruptorPass()
        {
            CountdownEvent latch         = new CountdownEvent(1);
            long           expectedCount = batchEventProcessor.Sequence.Value + ITERATIONS;

            handler.reset(latch, expectedCount);
            //executor.submit(batchEventProcessor);
            //Task.Factory.StartNew(() => batchEventProcessor.Run()
            //                    , CancellationToken.None
            //                    , TaskCreationOptions.LongRunning
            //                    , new LimitedConcurrencyLevelTaskScheduler(4));

            ThreadPool.UnsafeQueueUserWorkItem(o => batchEventProcessor.Run(), null);
            Stopwatch start = Stopwatch.StartNew();

            RingBuffer <ValueEvent> rb = ringBuffer;

            for (long i = 0; i < ITERATIONS; i++)
            {
                long next = rb.Next();
                rb[next].Value = i;
                rb.Publish(next);
            }

            latch.Wait();
            long opsPerSecond = (ITERATIONS * 1000L) / (start.ElapsedMilliseconds);

            waitForEventProcessorSequence(expectedCount);
            batchEventProcessor.Halt();

            PerfTestUtil.failIfNot(expectedResult, handler.Value);

            return(opsPerSecond);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        public long Run(ThroughputSessionContext sessionContext)
        {
            _eventHandler.Reset(_iterations - 1);
            _consumer.Start();

            sessionContext.Start();

            var spinWait = new SpinWait();

            for (long i = 0; i < _iterations; i++)
            {
                var data = new PerfEvent {
                    Value = i
                };
                while (!_channel.Writer.TryWrite(data))
                {
                    spinWait.SpinOnce();
                }
                spinWait.Reset();
            }

            _eventHandler.Latch.WaitOne();
            sessionContext.Stop();
            _consumer.Stop();

            sessionContext.SetBatchData(_eventHandler.BatchesProcessedCount.Value, _iterations);

            PerfTestUtil.FailIfNot(_expectedResult, _eventHandler.Value, $"Handler should have processed {_expectedResult} events, but was: {_eventHandler.Value}");

            return(_iterations);
        }
コード例 #11
0
        protected override long RunDisruptorPass()
        {
            CountdownEvent latch = new CountdownEvent(1);

            fizzBuzzHandler.rset(latch, batchProcessorFizzBuzz.Sequence.Value + ITERATIONS);
            Task.Run(() => batchProcessorFizz.Run());
            Task.Run(() => batchProcessorBuzz.Run());
            Task.Run(() => batchProcessorFizzBuzz.Run());


            Stopwatch start = Stopwatch.StartNew();

            for (long i = 0; i < ITERATIONS; i++)
            {
                long sequence = ringBuffer.Next();
                ringBuffer[sequence].Value = i;
                ringBuffer.Publish(sequence);
            }

            //mr.WaitOne ();
            latch.Wait();
            long opsPerSecond = (ITERATIONS * 1000L) / (start.ElapsedMilliseconds);

            batchProcessorFizz.Halt();
            batchProcessorBuzz.Halt();
            batchProcessorFizzBuzz.Halt();

            PerfTestUtil.failIfNot(expectedResult, fizzBuzzHandler.FizzBuzzCounter);

            return(opsPerSecond);
        }
コード例 #12
0
        protected override long RunQueuePass()
        {
            CountdownEvent latch = new CountdownEvent(1);

            fizzBuzzQueueProcessor.Reset(latch);

            CancellationTokenSource cance = new CancellationTokenSource();
            var t1 = Task.Factory.StartNew(() => fizzQueueProcessor.Run(), cance.Token, TaskCreationOptions.None, TaskScheduler.Default);
            var t2 = Task.Factory.StartNew(() => buzzQueueProcessor.Run(), cance.Token, TaskCreationOptions.None, TaskScheduler.Default);
            var t3 = Task.Factory.StartNew(() => fizzBuzzQueueProcessor.Run(), cance.Token, TaskCreationOptions.None, TaskScheduler.Default);

            var run = Stopwatch.StartNew();

            for (long i = 0; i < ITERATIONS; i++)
            {
                fizzInputQueue.Enqueue(i);
                buzzInputQueue.Enqueue(i);
            }

            latch.Wait();
            long opsPerSecond = (ITERATIONS * 1000L) / run.ElapsedMilliseconds;

            fizzQueueProcessor.Halt();
            buzzQueueProcessor.Halt();
            fizzBuzzQueueProcessor.Halt();

            cance.Cancel();

            PerfTestUtil.failIf(ExpectedResult, 0);

            return(opsPerSecond);
        }
        protected override long RunDisruptorPass()
        {
            CountdownEvent latch         = new CountdownEvent(1);
            long           expectedCount = poller.GetSequence().Value + ITERATIONS;

            pollRunnable.reset(latch, expectedCount);
            Task.Factory.StartNew(() => pollRunnable.Run());
            Stopwatch watch = Stopwatch.StartNew();

            RingBuffer <ValueEvent> rb = ringBuffer;

            for (long i = 0; i < ITERATIONS; i++)
            {
                long next = rb.Next();
                rb[next].Value = i;
                rb.Publish(next);
            }

            latch.Wait();
            long opsPerSecond = (ITERATIONS * 1000L) / (watch.ElapsedMilliseconds);

            waitForEventProcessorSequence(expectedCount);
            pollRunnable.Halt();

            PerfTestUtil.failIfNot(expectedResult, pollRunnable.getValue());

            return(opsPerSecond);
        }
コード例 #14
0
    public long Run(ThroughputSessionContext sessionContext)
    {
        var completedSignal = new ManualResetEvent(false);

        _streamProcessor.Reset(completedSignal);

        var processorTask = _streamProcessor.Start();

        sessionContext.Start();

        var ringBuffer = _ringBuffer;

        for (var i = 0; i < _iterations; i++)
        {
            var next = ringBuffer.Next();
            ringBuffer[next].Value = i;
            ringBuffer.Publish(next);
        }

        completedSignal.WaitOne();

        sessionContext.Stop();

        _streamProcessor.Halt();
        processorTask.Wait();

        sessionContext.SetBatchData(_streamProcessor.BatchesProcessedCount, _iterations);

        PerfTestUtil.FailIfNot(_expectedResult, _streamProcessor.Value, $"Poll runnable should have processed {_expectedResult} but was {_streamProcessor.Value}");

        return(_iterations);
    }
        protected override long RunDisruptorPass()
        {
            MutableLong value = this.value;

            CountdownEvent latch         = new CountdownEvent(1);
            long           expectedCount = ringBuffer.GetMinimumGatingSequence() + ITERATIONS;

            handler.reset(latch, expectedCount);
            var start = Stopwatch.StartNew();
            RingBuffer <ValueEvent> rb = ringBuffer;

            for (long l = 0; l < ITERATIONS; l++)
            {
                value.Value = l;
                rb.PublishEvent(Translator.INSTANCE, value);
            }
            latch.Wait();
            long opsPerSecond = (ITERATIONS * 1000L) / (start.ElapsedMilliseconds);

            waitForEventProcessorSequence(expectedCount);

            PerfTestUtil.failIfNot(expectedResult, handler.Value);

            return(opsPerSecond);
        }
コード例 #16
0
        protected override long RunQueuePass()
        {
            CountdownEvent latch = new CountdownEvent(1);

            queueProcessor.Reset(latch);
            CancellationTokenSource canncel = new CancellationTokenSource();

            Task.Factory.StartNew(() => queueProcessor.Run(), canncel.Token);

            var start = Stopwatch.StartNew();

            for (long i = 0; i < ITERATIONS; i++)
            {
                blockingQueue.Add(i);
            }

            latch.Wait();
            long opsPerSecond = (ITERATIONS * 1000L) / (start.ElapsedMilliseconds);

            queueProcessor.Halt();
            canncel.Cancel(true);

            PerfTestUtil.failIf(expectedResult, 0);

            return(opsPerSecond);
        }
コード例 #17
0
        protected override long RunDisruptorPass()
        {
            CountdownEvent latch = new CountdownEvent(1);

            stepThreeFunctionHandler.reset(latch, stepThreeBatchProcessor.Sequence.Value + ITERATIONS);

            Task.Run(() => stepOneBatchProcessor.Run());
            Task.Run(() => stepTwoBatchProcessor.Run());
            Task.Run(() => stepThreeBatchProcessor.Run());
            Stopwatch start = Stopwatch.StartNew();

            long operandTwo = OPERAND_TWO_INITIAL_VALUE;

            for (long i = 0; i < ITERATIONS; i++)
            {
                long          sequence = ringBuffer.Next();
                FunctionEvent @event   = ringBuffer[sequence];
                @event.OperandOne = i;
                @event.OperandTwo = operandTwo--;
                ringBuffer.Publish(sequence);
            }

            latch.Wait();
            long opsPerSecond = (ITERATIONS * 1000L) / (start.ElapsedMilliseconds);

            stepOneBatchProcessor.Halt();
            stepTwoBatchProcessor.Halt();
            stepThreeBatchProcessor.Halt();

            PerfTestUtil.failIfNot(expectedResult, stepThreeFunctionHandler.StepThreeCounter);

            return(opsPerSecond);
        }
コード例 #18
0
        public long Run(Stopwatch stopwatch)
        {
            var signal        = new ManualResetEvent(false);
            var expectedCount = _batchEventProcessor.Sequence.Value + _iterations;

            _handler.Reset(signal, _iterations);
            var processorTask = _executor.Execute(_batchEventProcessor.Run);

            stopwatch.Start();

            var rb = _ringBuffer;

            for (var i = 0; i < _iterations; i++)
            {
                var next   = rb.Next();
                var @event = rb[next];
                for (var j = 0; j < @event.Length; j++)
                {
                    @event[j] = i;
                }
                rb.Publish(next);
            }

            signal.WaitOne();
            stopwatch.Stop();
            WaitForEventProcessorSequence(expectedCount);
            _batchEventProcessor.Halt();
            processorTask.Wait(2000);

            PerfTestUtil.FailIf(0, _handler.Value, "Handler has not processed any event");

            return(_iterations * _arraySize);
        }
コード例 #19
0
        public long Run(Stopwatch stopwatch)
        {
            var signal        = new ManualResetEvent(false);
            var expectedCount = _batchEventProcessor.Sequence.Value + _iterations * _batchSize;

            _handler.Reset(signal, expectedCount);
            var processorTask = _executor.Execute(_batchEventProcessor.Run);

            stopwatch.Start();

            var rb = _ringBuffer;

            for (var i = 0; i < _iterations; i++)
            {
                var hi = rb.Next(_batchSize);
                var lo = hi - (_batchSize - 1);
                for (var l = lo; l <= hi; l++)
                {
                    rb[l].Value = (i);
                }
                rb.Publish(lo, hi);
            }

            signal.WaitOne();
            stopwatch.Stop();
            PerfTestUtil.WaitForEventProcessorSequence(expectedCount, _batchEventProcessor);
            _batchEventProcessor.Halt();
            processorTask.Wait(2000);

            PerfTestUtil.FailIfNot(_expectedResult, _handler.Value, $"Handler should have processed {_expectedResult} events, but was: {_handler.Value}");

            return(_batchSize * _iterations);
        }
コード例 #20
0
        public long Run(Stopwatch stopwatch)
        {
            var latch = new Barrier(_numEventProcessors + 1);

            var processorTasks = new List <Task>();

            for (var i = 0; i < _numEventProcessors; i++)
            {
                _handlers[i].Reset(latch, _batchEventProcessors[i].Sequence.Value + _iterations);
                processorTasks.Add(_executor.Execute(_batchEventProcessors[i].Run));
            }

            stopwatch.Start();

            for (long i = 0; i < _iterations; i++)
            {
                var sequence = _ringBuffer.Next();
                _ringBuffer[sequence].Value = i;
                _ringBuffer.Publish(sequence);
            }

            latch.SignalAndWait();
            stopwatch.Stop();

            for (var i = 0; i < _numEventProcessors; i++)
            {
                _batchEventProcessors[i].Halt();
                PerfTestUtil.FailIfNot(_results[i], _handlers[i].Value, $"Result {_results[i]} != {_handlers[i].Value}");
            }
            Task.WaitAll(processorTasks.ToArray());

            return(_numEventProcessors * _iterations);
        }
コード例 #21
0
        public long Run(ThroughputSessionContext sessionContext)
        {
            var signal = new ManualResetEvent(false);

            _fizzBuzzQueueProcessor.Reset(signal);
            var tasks = new Task[_eventProcessorCount];

            tasks[0] = _executor.Execute(_fizzQueueProcessor.Run);
            tasks[1] = _executor.Execute(_buzzQueueProcessor.Run);
            tasks[2] = _executor.Execute(_fizzBuzzQueueProcessor.Run);

            sessionContext.Start();

            for (var i = 0; i < _iterations; i++)
            {
                _fizzInputQueue.Enqueue(i);
                _buzzInputQueue.Enqueue(i);
            }

            signal.WaitOne();
            sessionContext.Stop();

            _fizzQueueProcessor.Halt();
            _buzzQueueProcessor.Halt();
            _fizzBuzzQueueProcessor.Halt();

            Task.WaitAll(tasks);

            PerfTestUtil.FailIf(_expectedResult, 0);

            return(_iterations);
        }
        public long Run(ThroughputSessionContext sessionContext)
        {
            ResetCounters();

            _workerPool.Start();

            sessionContext.Start();

            var ringBuffer = _ringBuffer;

            for (long i = 0; i < _iterations; i++)
            {
                var sequence = ringBuffer.Next();
                ringBuffer[sequence].Value = i;
                ringBuffer.Publish(sequence);
            }

            _workerPool.DrainAndHalt();

            // Workaround to ensure that the last worker(s) have completed after releasing their events
            Thread.Sleep(1);
            sessionContext.Stop();

            PerfTestUtil.FailIfNot(_iterations, SumCounters());

            return(_iterations);
        }
コード例 #23
0
        public long Run(Stopwatch stopwatch)
        {
            long expectedCount = _batchEventProcessor.Sequence.Value + _iterations;

            _latch.Reset();
            _eventHandler.Reset(_latch, expectedCount);
            var processorTask = _executor.Execute(_batchEventProcessor.Run);

            stopwatch.Start();

            for (long i = 0; i < _iterations; i++)
            {
                long sequence = _ringBuffer.Next();
                _ringBuffer[sequence].Value = i;
                _ringBuffer.Publish(sequence);
            }

            _latch.WaitOne();
            stopwatch.Stop();
            PerfTestUtil.WaitForEventProcessorSequence(expectedCount, _batchEventProcessor);
            _batchEventProcessor.Halt();
            processorTask.Wait(2000);

            PerfTestUtil.FailIfNot(_expectedResult, _eventHandler.Value, $"Handler should have processed {_expectedResult} events, but was: {_eventHandler.Value}");

            return(_iterations);
        }
コード例 #24
0
        public long Run(ThroughputSessionContext sessionContext)
        {
            long expectedCount = _batchEventProcessor.Sequence.Value + _iterations;

            _eventHandler.Reset(expectedCount);
            var processorTask = _executor.Execute(() =>
            {
                using var _ = ThreadAffinityUtil.SetThreadAffinity(0);

                Thread.CurrentThread.Priority = ThreadPriority.Highest;

                _batchEventProcessor.Run();
            });

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

            using var _ = ThreadAffinityUtil.SetThreadAffinity(1);

            Thread.CurrentThread.Priority = ThreadPriority.Highest;

            sessionContext.Start();

            var ringBuffer = _ringBuffer;

            for (long i = 0; i < _iterations; i++)
            {
                var s = ringBuffer.Next();
                ringBuffer[s].Value = i;
                // ExtraWork(1);
                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)
    {
        var latch = new ManualResetEvent(false);

        _stepThreeFunctionHandler.Reset(latch, _stepThreeEventProcessor.Sequence.Value + _iterations);

        var processorTask1 = _stepOneEventProcessor.Start();
        var processorTask2 = _stepTwoEventProcessor.Start();
        var processorTask3 = _stepThreeEventProcessor.Start();

        _stepOneEventProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5));
        _stepTwoEventProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5));
        _stepThreeEventProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5));

        sessionContext.Start();

        var ringBuffer = _ringBuffer;

        var operandTwo = _operandTwoInitialValue;

        for (long i = 0; i < _iterations; i++)
        {
            var sequence = ringBuffer.Next();
            var @event   =
                ringBuffer[sequence];
            @event.OperandOne = i;
            @event.OperandTwo = operandTwo--;
            ringBuffer.Publish(sequence);
        }

        latch.WaitOne();
        sessionContext.Stop();

        _stepOneEventProcessor.Halt();
        _stepTwoEventProcessor.Halt();
        _stepThreeEventProcessor.Halt();
        Task.WaitAll(processorTask1, processorTask2, processorTask3);

        PerfTestUtil.FailIfNot(_expectedResult, _stepThreeFunctionHandler.StepThreeCounter);

        return(_iterations);
    }
        protected override long RunDisruptorPass()
        {
            resetCounters();
            RingBuffer <ValueEvent> ringBuffer = workerPool.start(TaskScheduler.Default);
            var start = Stopwatch.StartNew();

            for (long i = 0; i < ITERATIONS; i++)
            {
                long sequence = ringBuffer.Next();
                ringBuffer.Get(sequence).Value = i;
                ringBuffer.Publish(sequence);
            }

            workerPool.drainAndHalt();
            long opsPerSecond = (ITERATIONS * 1000L) / start.ElapsedMilliseconds;

            PerfTestUtil.failIfNot(ITERATIONS, sumCounters());

            return(opsPerSecond);
        }
        protected override long RunDisruptorPass()
        {
            CountdownEvent latch = new CountdownEvent(NUM_EVENT_PROCESSORS);

            Enumerable.Range(0, NUM_EVENT_PROCESSORS).Select(i =>
            {
                //return Task.Run(() => batchEventProcessors[i].Run());
                return(ThreadPool.UnsafeQueueUserWorkItem(o =>
                {
                    handlers[Convert.ToInt32(o)].reset(latch, batchEventProcessors[i].Sequence.Value + ITERATIONS);
                    batchEventProcessors[Convert.ToInt32(o)].Run();
                }, i));
                //return 1;
            }).ToList();
            //handlers[0].reset(latch, batchEventProcessors[0].Sequence.Value + ITERATIONS);
            //Task.Run(() => batchEventProcessors[0].Run());
            //handlers[1].reset(latch, batchEventProcessors[1].Sequence.Value + ITERATIONS);
            //Task.Run(() => batchEventProcessors[1].Run());
            //handlers[2].reset(latch, batchEventProcessors[2].Sequence.Value + ITERATIONS);
            //Task.Run(() => batchEventProcessors[2].Run());

            Stopwatch start = Stopwatch.StartNew();

            for (long i = 0; i < ITERATIONS; i++)
            {
                long sequence = ringBuffer.Next();
                ringBuffer[sequence].Value = i;
                ringBuffer.Publish(sequence);
            }

            latch.Wait();
            long opsPerSecond = (ITERATIONS * 1000L) / (start.ElapsedMilliseconds);

            for (int i = 0; i < NUM_EVENT_PROCESSORS; i++)
            {
                batchEventProcessors[i].Halt();
                PerfTestUtil.failIfNot(results[i], handlers[i].Value);
            }

            return(opsPerSecond);
        }
        protected override long RunDisruptorPass()
        {
            CountdownEvent latch = new CountdownEvent(1);
            //ManualResetEvent latch = new ManualResetEvent(false);
            long expectedCount = batchEventProcessor.Sequence.Value + ITERATIONS * BATCH_SIZE;

            handler.reset(latch, expectedCount);
            Task.Factory.StartNew(() => batchEventProcessor.Run()
                                  , CancellationToken.None
                                  , TaskCreationOptions.LongRunning
                                  , new LimitedConcurrencyLevelTaskScheduler(4));
            //ThreadPool.QueueUserWorkItem(o=>batchEventProcessor.Run());
            Stopwatch start = Stopwatch.StartNew();

            RingBuffer <ValueEvent> rb = ringBuffer;

            for (long i = 0; i < ITERATIONS; i++)
            {
                long hi = rb.Next(BATCH_SIZE);
                long lo = hi - (BATCH_SIZE - 1);
                for (long l = lo; l <= hi; l++)
                {
                    rb.Get(l).Value = i;
                }
                rb.Publish(lo, hi);
            }

            latch.Wait();
            long opsPerSecond = (BATCH_SIZE * ITERATIONS * 1000L) / (start.ElapsedMilliseconds);

            waitForEventProcessorSequence(expectedCount);
            batchEventProcessor.Halt();

            Console.WriteLine("expectedResult={0:###,###,###},realValue={1:###,###,###}", expectedResult, handler.Value);
            PerfTestUtil.failIfNot(expectedResult, handler.Value);

            return(opsPerSecond);
        }
コード例 #29
0
        public long Run(ThroughputSessionContext sessionContext)
        {
            _channel = Channel.CreateBounded <PerfEvent>(new BoundedChannelOptions(_bufferSize)
            {
                FullMode     = BoundedChannelFullMode.Wait,
                SingleReader = true,
                SingleWriter = true,
            });
            _consumer = new Consumer(_channel.Reader, _eventHandler);

            _eventHandler.Reset(_iterations - 1);
            _consumer.Start();

            var producerSignal = new ManualResetEventSlim();
            var producer       = Task.Run(async() =>
            {
                producerSignal.Wait();
                await PublishOneByOne();
                //await PublishBatched();
            });

            sessionContext.Start();

            producerSignal.Set();
            _eventHandler.Latch.WaitOne();

            sessionContext.Stop();

            _channel.Writer.Complete();
            producer.Wait();
            _consumer.Stop();

            sessionContext.SetBatchData(_eventHandler.BatchesProcessedCount.Value, _iterations);

            PerfTestUtil.FailIfNot(_expectedResult, _eventHandler.Value, $"Handler should have processed {_expectedResult} events, but was: {_eventHandler.Value}");

            return(_iterations);
        }
コード例 #30
0
    public long Run(ThroughputSessionContext sessionContext)
    {
        var latch = new Barrier(_numEventProcessors + 1);

        var processorTasks = new List <Task>();

        for (var i = 0; i < _numEventProcessors; i++)
        {
            _handlers[i].Reset(latch, _eventProcessors[i].Sequence.Value + _iterations);
            processorTasks.Add(_eventProcessors[i].Start());
            _eventProcessors[i].WaitUntilStarted(TimeSpan.FromSeconds(5));
        }

        sessionContext.Start();

        var ringBuffer = _ringBuffer;

        for (long i = 0; i < _iterations; i++)
        {
            var sequence = ringBuffer.Next();
            ringBuffer[sequence].Value = i;
            ringBuffer.Publish(sequence);
        }

        latch.SignalAndWait();
        sessionContext.Stop();

        for (var i = 0; i < _numEventProcessors; i++)
        {
            _eventProcessors[i].Halt();
            PerfTestUtil.FailIfNot(_results[i], _handlers[i].Value, $"Result {_results[i]} != {_handlers[i].Value}");
        }
        Task.WaitAll(processorTasks.ToArray());

        sessionContext.SetBatchData(_handlers.Sum(x => x.BatchesProcessedCount.Value), _numEventProcessors * _iterations);

        return(_numEventProcessors * _iterations);
    }