Beispiel #1
0
        public long Run(Stopwatch stopwatch)
        {
            _cyclicBarrier.Reset();

            var latch = new ManualResetEvent(false);

            _handler.Reset(latch, _iterations);

            var futures = new Task[_numPublishers];

            for (var i = 0; i < _numPublishers; i++)
            {
                var index = i;
                futures[i] = Task.Run(() => _valuePublishers[index](_cyclicBarrier, _buffers[index], _iterations / _numPublishers, _arraySize));
            }
            var processorTask = Task.Run(() => _batchEventProcessor.Run());

            stopwatch.Start();
            _cyclicBarrier.Signal();
            _cyclicBarrier.Wait();

            for (var i = 0; i < _numPublishers; i++)
            {
                futures[i].Wait();
            }

            latch.WaitOne();

            stopwatch.Stop();
            _batchEventProcessor.Halt();
            processorTask.Wait(2000);

            return(_iterations * _arraySize);
        }
        protected override long RunDisruptorPass()
        {
            CountdownEvent latch = new CountdownEvent(1);

            handler.Reset(latch, ITERATIONS);
            Task[] task = new Task[NUM_PUBLISHERS];
            //for (int i = 0; i < NUM_PUBLISHERS; i++)
            //{
            //    task[i] = Task.Run(() => valuePublishers[i].run());
            //}
            task[0] = Task.Factory.StartNew(() => valuePublishers[0].run());
            task[1] = Task.Factory.StartNew(() => valuePublishers[1].run());
            task[2] = Task.Factory.StartNew(() => valuePublishers[2].run());

            ThreadPool.QueueUserWorkItem(o =>
            {
                batchEventProcessor.Run();
            });
            var stopWatch = Stopwatch.StartNew();

            cyclicBarrier.SignalAndWait();

            Task.WaitAll(task);
            latch.Wait();

            long opsPerSecond = (ITERATIONS * 1000L) / (stopWatch.ElapsedMilliseconds);

            batchEventProcessor.Halt();
            return(opsPerSecond);
        }