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);
        }
Beispiel #2
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()
        {
            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);
        }