public void Run()
        {
            running.Data = true;
            while (running.Data)
            {
                try
                {
                    switch (functionStep)
                    {
                    case FunctionStep.ONE:
                    case FunctionStep.TWO:
                    {
                        outputQueue.Add(inputQueue.Take());
                        break;
                    }

                    case FunctionStep.THREE:
                    {
                        long value    = inputQueue.Take();
                        long duration = stopwatch.GetElapsedNanoSeconds() - value;
                        duration /= 3;
                        duration -= nanoTimeCost;
                        histogram.AddObservation(duration);
                        break;
                    }
                    }

                    sequence.Data++;
                }
                catch (ThreadInterruptedException)
                {
                    break;
                }
            }
        }
Example #2
0
        private void InitStopwatchTimeCostNs()
        {
            long iterations = 10000000;
            var  stopwatch  = new Stopwatch();

            stopwatch.Start();

            //the stopwatch does the elapsed time so we don't need to maintain a start/finish
            //set to do the math ourselves.  We do however need a variable to assign to in order
            //make sure the runtime invokes stopwatch.ElapsedTicks in our loop
            long dummy = stopwatch.GetElapsedNanoSeconds();

            for (int i = 0; i < iterations; i++)
            {
                dummy = stopwatch.GetElapsedNanoSeconds();
            }

            dummy = stopwatch.GetElapsedNanoSeconds();
            stopwatch.Stop();
            _stopwatchTimeCostNs = stopwatch.GetElapsedNanoSeconds() / iterations;
        }
Example #3
0
        public void OnAvailable(ValueEntry entry)
        {
            switch (functionStep)
            {
            case FunctionStep.ONE:
            case FunctionStep.TWO:
                break;

            case FunctionStep.THREE:
                long duration = stopwatch.GetElapsedNanoSeconds() - entry.Value;
                duration /= 3;
                duration -= stopwatchTimeCostNs;
                histogram.AddObservation(duration);
                break;
            }
        }
Example #4
0
        private void RunDisruptorPass()
        {
            var thread1 = new Thread(stepOneBatchConsumer.Run);
            var thread2 = new Thread(stepTwoBatchConsumer.Run);
            var thread3 = new Thread(stepThreeBatchConsumer.Run);

            thread1.Start();
            thread2.Start();
            thread3.Start();

            for (long i = 0; i < ITERATIONS; i++)
            {
                ValueEntry entry = producerBarrier.NextEntry();
                entry.Value = _stopwatch.GetElapsedNanoSeconds();
                producerBarrier.Commit(entry);

                long pauseStart = _stopwatch.GetElapsedNanoSeconds();
                while (PAUSE_NANOS > (_stopwatch.GetElapsedNanoSeconds() - pauseStart))
                {
                    //Busy Spin
                }
            }

            long expectedSequence = ringBuffer.Cursor;

            while (stepThreeBatchConsumer.Sequence < expectedSequence)
            {
                //Busy Spin
            }

            stepOneBatchConsumer.Halt();
            stepTwoBatchConsumer.Halt();
            stepThreeBatchConsumer.Halt();
            thread3.Join();
            thread2.Join();
            thread1.Join();
        }
		private void InitStopwatchTimeCostNs()
		{
            long iterations = 10000000;
			var stopwatch = new Stopwatch();
			stopwatch.Start();
			
			//the stopwatch does the elapsed time so we don't need to maintain a start/finish
			//set to do the math ourselves.  We do however need a variable to assign to in order
			//make sure the runtime invokes stopwatch.ElapsedTicks in our loop
			long dummy = stopwatch.GetElapsedNanoSeconds();
			
			for (int i = 0; i < iterations; i++)
			{
				dummy = stopwatch.GetElapsedNanoSeconds();
			}
			
			dummy = stopwatch.GetElapsedNanoSeconds();
			stopwatch.Stop();
			_stopwatchTimeCostNs = stopwatch.GetElapsedNanoSeconds() / iterations;
		}