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);
        }
        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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
        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);
        }