public override long RunPass() { _disruptor.Start(); var sw = Stopwatch.StartNew(); for (long i = 0; i < Iterations; i++) { var sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = i; _ringBuffer.Publish(sequence); } _latch.Wait(); var opsPerSecond = (Iterations * 1000L) / sw.ElapsedMilliseconds; _disruptor.Shutdown(); Assert.AreEqual(ExpectedResults[0], _handler1.Value, "Addition"); Assert.AreEqual(ExpectedResults[1], _handler2.Value, "Sub"); Assert.AreEqual(ExpectedResults[2], _handler3.Value, "And"); return(opsPerSecond); }
public override void RunPass() { _disruptor.Start(); Task.Factory.StartNew( () => { for (long i = 0; i < Iterations; i++) { var sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = Stopwatch.GetTimestamp(); _ringBuffer.Publish(sequence); var pauseStart = Stopwatch.GetTimestamp(); while (PauseNanos > (Stopwatch.GetTimestamp() - pauseStart) * TicksToNanos) { // busy spin } } }, CancellationToken.None, TaskCreationOptions.None, _scheduler); _mru.WaitOne(); _disruptor.Shutdown(); _scheduler.Dispose(); }
public override long RunPass() { _disruptor.Start(); var sw = Stopwatch.StartNew(); Task.Factory.StartNew( () => { for (long i = 0; i < Iterations; i++) { var sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = i; _ringBuffer.Publish(sequence); } }, CancellationToken.None, TaskCreationOptions.None, _scheduler); _latch.Wait(); var opsPerSecond = (Iterations * 1000L) / sw.ElapsedMilliseconds; _disruptor.Shutdown(); _scheduler.Dispose(); Assert.AreEqual(ExpectedResults[0], _handler1.Value, "Addition"); Assert.AreEqual(ExpectedResults[1], _handler2.Value, "Sub"); Assert.AreEqual(ExpectedResults[2], _handler3.Value, "And"); return(opsPerSecond); }
public override void RunPass() { _disruptor.Start(); for (long i = 0; i < Iterations; i++) { var sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = Stopwatch.GetTimestamp(); _ringBuffer.Publish(sequence); var pauseStart = Stopwatch.GetTimestamp(); while (PauseNanos > (Stopwatch.GetTimestamp() - pauseStart) * TicksToNanos) { // busy spin } } _mru.WaitOne(); _disruptor.Shutdown(); }
public override long RunPass() { _disruptor.Start(); var sw = Stopwatch.StartNew(); for (long i = 0; i < Iterations; i++) { long sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = i; _ringBuffer.Publish(sequence); } _mru.WaitOne(); var opsPerSecond = (Iterations * 1000L) / sw.ElapsedMilliseconds; _disruptor.Shutdown(); Assert.AreEqual(ExpectedResult, _eventHandler.Value, "RunDisruptorPass"); return(opsPerSecond); }
public long RunPass(int PassNumber) { InitRingQueue(); var sw = Stopwatch.StartNew(); Thread.MemoryBarrier(); /* * for (int i = 0; i < MAX_MSG_COUNT; i++) * { * var sequence = _ringBuffer.Next(); * _ringBuffer[sequence].Value = i; * _ringBuffer.Publish(sequence); * //Console.WriteLine("RunPass(): sequence = {0}, {1}, {2}.", MAX_MSG_COUNT, i, sequence); * } * //*/ for (int i = 0; i < PUSH_CNT; i++) { _producerThreads[i].Join(); } //Thread.MemoryBarrier(); //Thread.Sleep(100); Thread.MemoryBarrier(); /* * for (int i = 0; i < POP_CNT; i++) * { * for (int j = 0; j < POP_CNT; j++) * { * try * { * _latchs[i].Signal(); * } * catch (Exception ex) { } * } * } * Thread.MemoryBarrier();* * //*/ for (int i = 0; i < POP_CNT; i++) { //_latchs.Wait(); } //Thread.MemoryBarrier(); /* * _workerPool.DrainAndHalt(); * * Thread.MemoryBarrier(); * * for (int i = 0; i < POP_CNT; i++) * { * var lifecycleAware = _workHandlers[i] as ILifecycleAware; * if (lifecycleAware != null) * lifecycleAware.OnShutdown(); * } * //*/ /* * while (!_remainCount.AtomicCompareExchange(-1, 0)) * { * // Do nothing! * Thread.Yield(); * } * //*/ Thread.MemoryBarrier(); _disruptor.Shutdown(); //Thread.Sleep(200); long opsPerSecond; if (sw.ElapsedMilliseconds != 0) { opsPerSecond = (MAX_MSG_COUNT * 1000L) / sw.ElapsedMilliseconds; } else { opsPerSecond = 0L; } Console.WriteLine("Run = {0}, Time = {1} ms, Disruptor = {2:###,###,###,###} ops/sec.\n", PassNumber, sw.ElapsedMilliseconds, (long)opsPerSecond); /* * try * { * for (int i = 0; i < POP_CNT; i++) * { * if (i == 0) * Assert.AreEqual(ExpectedResults[0], _eventHandlers[0].Value, "Addition"); * else if (i == 1) * Assert.AreEqual(ExpectedResults[1], _eventHandlers[1].Value, "Sub"); * else if (i == 2) * Assert.AreEqual(ExpectedResults[2], _eventHandlers[2].Value, "And"); * else * Assert.AreEqual(ExpectedResults[i], _eventHandlers[i].Value, "And"); * } * } * catch (Exception ex) * { * //Console.WriteLine(ex.Message.ToString()); * Console.WriteLine(ex.ToString()); * //Console.ReadKey(); * } * finally * { * // * } * //*/ long totals = 0; for (int i = 0; i < POP_CNT; i++) { Console.WriteLine("counters({0}) = {1}", i, _counters[i].ReadUnfenced()); totals += _counters[i].ReadUnfenced(); } Console.WriteLine("\ntotals = {0} messages.\n", totals); _workerPool.Halt(); for (int i = 0; i < POP_CNT; i++) { _workHandlers[i] = null; } _workerPool = null; if (_disruptor != null) { _disruptor.Shutdown(); _disruptor = null; } _ringBuffer = null; System.GC.Collect(); return(opsPerSecond); }