예제 #1
0
        public void Test1()
        {
            var testBuffer = new RingBuffer <TestClass>(new TestClassFactory(), 1000, new SingleThreadedStrategy(),
                                                        new BusySpinStrategy <TestClass>());
            IConsumerBarrier <TestClass> consumerBarrier = testBuffer.CreateConsumerBarrier();
            var batchConsumer = new BatchConsumer <TestClass>(consumerBarrier, new TestBatchHandler <TestClass>());
            IProducerBarrier <TestClass> producerBarrier = testBuffer.CreateProducerBarrier(batchConsumer);

            var thread = new Thread(batchConsumer.Run);

            thread.Start();

            for (int i = 0; i < 1000; i++)
            {
                TestClass test = producerBarrier.NextEntry();
                test.Value = i;
                test.Stuff = "FirstTest" + i;

                producerBarrier.Commit(test);
            }

            Thread.Sleep(100);
            batchConsumer.Halt();
            thread.Join();
        }
        public void ShouldReportProgressByUpdatingSequenceViaCallback()
        {
            IRingBuffer <StubEntry>              ringBuffer      = new RingBuffer <StubEntry>(new StubFactory(), 16);
            IConsumerBarrier <StubEntry>         consumerBarrier = ringBuffer.CreateConsumerBarrier();
            ISequenceTrackingHandler <StubEntry> handler         = new TestSequenceTrackingHandler();
            var batchConsumer = new BatchConsumer <StubEntry>(consumerBarrier, handler);
            IProducerBarrier <StubEntry> producerBarrier = ringBuffer.CreateProducerBarrier(batchConsumer);

            var thread = new Thread(batchConsumer.Run);

            thread.Start();

            Assert.AreEqual(-1L, batchConsumer.Sequence);
            producerBarrier.Commit(producerBarrier.NextEntry());
            producerBarrier.Commit(producerBarrier.NextEntry());
            Assert.IsTrue(onAvailableLatch.WaitOne(1000));
            Assert.AreEqual(-1L, batchConsumer.Sequence);

            producerBarrier.Commit(producerBarrier.NextEntry());
            Assert.IsTrue(readyToCallbackLatch.WaitOne(1000));
            Assert.AreEqual(2L, batchConsumer.Sequence);

            batchConsumer.Halt();
            thread.Join();
        }
예제 #3
0
        public Pipeline3StepLatencyPerfTest()
        {
            InitHistogram();
            InitStopwatchTimeCostNs();

            ringBuffer =
                new RingBuffer <ValueEntry>(new ValueEntryFactory(), SIZE,
                                            new SingleThreadedStrategy(),
                                            new BusySpinStrategy <ValueEntry>());
            stepOneConsumerBarrier = ringBuffer.CreateConsumerBarrier();
            stepOneFunctionHandler = new LatencyStepHandler(FunctionStep.ONE, _histogram, _stopwatchTimeCostNs, _stopwatch);
            stepOneBatchConsumer   = new BatchConsumer <ValueEntry>(stepOneConsumerBarrier, stepOneFunctionHandler);

            stepTwoConsumerBarrier = ringBuffer.CreateConsumerBarrier(stepOneBatchConsumer);
            stepTwoFunctionHandler = new LatencyStepHandler(FunctionStep.TWO, _histogram, _stopwatchTimeCostNs, _stopwatch);
            stepTwoBatchConsumer   = new BatchConsumer <ValueEntry>(stepTwoConsumerBarrier, stepTwoFunctionHandler);

            stepThreeConsumerBarrier = ringBuffer.CreateConsumerBarrier(stepTwoBatchConsumer);
            stepThreeFunctionHandler = new LatencyStepHandler(FunctionStep.THREE, _histogram, _stopwatchTimeCostNs, _stopwatch);
            stepThreeBatchConsumer   = new BatchConsumer <ValueEntry>(stepThreeConsumerBarrier, stepThreeFunctionHandler);

            producerBarrier = ringBuffer.CreateProducerBarrier(stepThreeBatchConsumer);

            stepOneQueue   = new BlockingCollection <long>(SIZE);
            stepTwoQueue   = new BlockingCollection <long>(SIZE);
            stepThreeQueue = new BlockingCollection <long>(SIZE);

            stepOneQueueConsumer = new LatencyStepQueueConsumer(
                FunctionStep.ONE, stepOneQueue, stepTwoQueue, _histogram, _stopwatchTimeCostNs, _stopwatch);
            stepTwoQueueConsumer = new LatencyStepQueueConsumer(
                FunctionStep.TWO, stepTwoQueue, stepThreeQueue, _histogram, _stopwatchTimeCostNs, _stopwatch);
            stepThreeQueueConsumer = new LatencyStepQueueConsumer(
                FunctionStep.THREE, stepThreeQueue, null, _histogram, _stopwatchTimeCostNs, _stopwatch);
        }
		public void SetUp()
		{
			_mocks = new MockRepository();
			_latch = new AutoResetEvent(false);
			
			ringBuffer = new RingBuffer<StubEntry>(new StubFactory(), 16);
			consumerBarrier = ringBuffer.CreateConsumerBarrier();
			batchHandler = _mocks.DynamicMock<IBatchHandler<StubEntry>>();
			batchConsumer = new BatchConsumer<StubEntry>(consumerBarrier, batchHandler);
			producerBarrier = ringBuffer.CreateProducerBarrier(batchConsumer);
		}
예제 #5
0
        public void SetUp()
        {
            _mocks = new MockRepository();
            _latch = new AutoResetEvent(false);

            ringBuffer      = new RingBuffer <StubEntry>(new StubFactory(), 16);
            consumerBarrier = ringBuffer.CreateConsumerBarrier();
            batchHandler    = _mocks.DynamicMock <IBatchHandler <StubEntry> >();
            batchConsumer   = new BatchConsumer <StubEntry>(consumerBarrier, batchHandler);
            producerBarrier = ringBuffer.CreateProducerBarrier(batchConsumer);
        }
예제 #6
0
        static void batchTest()
        {
            IConsumer                   consumer = new BatchConsumer("http://newsdktest.datasink.sensorsdata.cn/sa?project=zhangwei&token=5a394d2405c147ca");
            SensorsAnalytics            sa       = new SensorsAnalytics(consumer, true);
            Dictionary <string, Object> dic      = new Dictionary <string, object>();

            dic.Add("productName", "iPhone 11");
            dic.Add("productPrice", "20000");
            sa.Track("112131", "ViewProduct", dic);
            sa.Flush();
            Thread.Sleep(15 * 1000);
            sa.Shutdown();
        }
예제 #7
0
        private void InitDisruptorObjects()
        {
            ringBuffer = new RingBuffer <FunctionEntry>(new FunctionEntryFactory(), SIZE,
                                                        new SingleThreadedStrategy(),
                                                        new YieldingStrategy <FunctionEntry>());

            stepOneConsumerBarrier = ringBuffer.CreateConsumerBarrier();
            stepOneFunctionHandler = new FunctionHandler(FunctionStep.ONE);
            stepOneBatchConsumer   = new BatchConsumer <FunctionEntry>(stepOneConsumerBarrier, stepOneFunctionHandler);

            stepTwoConsumerBarrier = ringBuffer.CreateConsumerBarrier(stepOneBatchConsumer);
            stepTwoFunctionHandler = new FunctionHandler(FunctionStep.TWO);
            stepTwoBatchConsumer   = new BatchConsumer <FunctionEntry>(stepTwoConsumerBarrier, stepTwoFunctionHandler);

            stepThreeConsumerBarrier = ringBuffer.CreateConsumerBarrier(stepTwoBatchConsumer);
            stepThreeFunctionHandler = new FunctionHandler(FunctionStep.THREE);
            stepThreeBatchConsumer   = new BatchConsumer <FunctionEntry>(stepThreeConsumerBarrier, stepThreeFunctionHandler);

            producerBarrier = ringBuffer.CreateProducerBarrier(stepThreeBatchConsumer);
        }
		public Pipeline3StepLatencyPerfTest()
		{
            InitHistogram();
            InitStopwatchTimeCostNs();

			ringBuffer =
				new RingBuffer<ValueEntry>(new ValueEntryFactory(), SIZE,
			                              new SingleThreadedStrategy(),
			                              new BusySpinStrategy<ValueEntry>());
			stepOneConsumerBarrier = ringBuffer.CreateConsumerBarrier();
			stepOneFunctionHandler = new LatencyStepHandler(FunctionStep.ONE, _histogram, _stopwatchTimeCostNs, _stopwatch);
			stepOneBatchConsumer = new BatchConsumer<ValueEntry>(stepOneConsumerBarrier, stepOneFunctionHandler);

			stepTwoConsumerBarrier = ringBuffer.CreateConsumerBarrier(stepOneBatchConsumer);
			stepTwoFunctionHandler = new LatencyStepHandler(FunctionStep.TWO, _histogram, _stopwatchTimeCostNs, _stopwatch);
			stepTwoBatchConsumer = new BatchConsumer<ValueEntry>(stepTwoConsumerBarrier, stepTwoFunctionHandler);

			stepThreeConsumerBarrier = ringBuffer.CreateConsumerBarrier(stepTwoBatchConsumer);
			stepThreeFunctionHandler = new LatencyStepHandler(FunctionStep.THREE, _histogram, _stopwatchTimeCostNs, _stopwatch);
			stepThreeBatchConsumer = new BatchConsumer<ValueEntry>(stepThreeConsumerBarrier, stepThreeFunctionHandler);

			producerBarrier = ringBuffer.CreateProducerBarrier(stepThreeBatchConsumer);
			
			stepOneQueue = new BlockingCollection<long>(SIZE);
			stepTwoQueue = new BlockingCollection<long>(SIZE);
			stepThreeQueue = new BlockingCollection<long>(SIZE);
		
			stepOneQueueConsumer = new LatencyStepQueueConsumer(
				FunctionStep.ONE, stepOneQueue, stepTwoQueue, _histogram, _stopwatchTimeCostNs, _stopwatch);
			stepTwoQueueConsumer = new LatencyStepQueueConsumer(
				FunctionStep.TWO, stepTwoQueue, stepThreeQueue, _histogram, _stopwatchTimeCostNs, _stopwatch);
			stepThreeQueueConsumer = new LatencyStepQueueConsumer(
				FunctionStep.THREE, stepThreeQueue, null, _histogram, _stopwatchTimeCostNs, _stopwatch);
		}
	    private void InitDisruptorObjects()
	    {
	    	ringBuffer = new RingBuffer<FunctionEntry>(new FunctionEntryFactory(), SIZE,
	    	                                           new SingleThreadedStrategy(),
	    	                                           new YieldingStrategy<FunctionEntry>());
		
		    stepOneConsumerBarrier = ringBuffer.CreateConsumerBarrier();
		    stepOneFunctionHandler = new FunctionHandler(FunctionStep.ONE);
		    stepOneBatchConsumer = new BatchConsumer<FunctionEntry>(stepOneConsumerBarrier, stepOneFunctionHandler);
		
		    stepTwoConsumerBarrier = ringBuffer.CreateConsumerBarrier(stepOneBatchConsumer);
		    stepTwoFunctionHandler = new FunctionHandler(FunctionStep.TWO);
		    stepTwoBatchConsumer = new BatchConsumer<FunctionEntry>(stepTwoConsumerBarrier, stepTwoFunctionHandler);
		
		    stepThreeConsumerBarrier = ringBuffer.CreateConsumerBarrier(stepTwoBatchConsumer);
		    stepThreeFunctionHandler = new FunctionHandler(FunctionStep.THREE);
		    stepThreeBatchConsumer = new BatchConsumer<FunctionEntry>(stepThreeConsumerBarrier, stepThreeFunctionHandler);
		
		    producerBarrier = ringBuffer.CreateProducerBarrier(stepThreeBatchConsumer);	    	
	    }
 public void SetSequenceTrackerCallback(
     BatchConsumer <StubEntry> .SequenceTrackerCallback sequenceTrackerCallback)
 {
     this.sequenceTrackerCallback = sequenceTrackerCallback;
 }