Exemple #1
0
    public static void Main()
    {
        // Specify the size of the ring buffer, must be power of 2.
        const int bufferSize = 1024;

        // Construct the Disruptor
        var disruptor = new Dsl.Disruptor <SampleEvent>(() => new SampleEvent(), bufferSize);

        // Connect the handler
        disruptor.HandleEventsWith(new SampleEventHandler());

        // Start the Disruptor, starts all threads running
        disruptor.Start();

        // Get the ring buffer from the Disruptor to be used for publishing.
        var ringBuffer = disruptor.RingBuffer;

        var producer = new SampleEventProducer(ringBuffer);
        var memory   = new Memory <byte>(new byte[12]);

        for (var i = 0; ; i++)
        {
            MemoryMarshal.Write(memory.Span, ref i);

            producer.ProduceUsingRawApi(memory);

            Thread.Sleep(1000);
        }
    }
        public UniCast1P1CDisruptorPerfTest()
            : base(100 * Million)
        {
            _disruptor = new Dsl.Disruptor <ValueEvent>(() => new ValueEvent(),
                                                        new SingleThreadedClaimStrategy(BufferSize),
                                                        new YieldingWaitStrategy());

            _mru          = new ManualResetEvent(false);
            _eventHandler = new ValueAdditionEventHandler(Iterations, _mru);
            _disruptor.HandleEventsWith(_eventHandler);
            _ringBuffer = _disruptor.RingBuffer;
        }
        public UniCast1P1CDisruptorPerfTest()
            : base(100 * Million)
        {
            _disruptor = new Dsl.Disruptor<ValueEvent>(() => new ValueEvent(),
                                                          new SingleThreadedClaimStrategy(BufferSize),
                                                          new YieldingWaitStrategy());

            _mru = new ManualResetEvent(false);
            _eventHandler = new ValueAdditionEventHandler(Iterations, _mru);
            _disruptor.HandleEventsWith(_eventHandler);
            _ringBuffer = _disruptor.RingBuffer;
        }
Exemple #4
0
        public MultiCast1P3CDisruptorPerfTest()
            : base(100 * Million)
        {
            _disruptor = new Dsl.Disruptor <ValueEvent>(() => new ValueEvent(),
                                                        new SingleThreadedClaimStrategy(Size),
                                                        new YieldingWaitStrategy());

            _latch = new CountdownEvent(3);

            _handler1 = new ValueMutationEventHandler(Operation.Addition, Iterations, _latch);
            _handler2 = new ValueMutationEventHandler(Operation.Substraction, Iterations, _latch);
            _handler3 = new ValueMutationEventHandler(Operation.And, Iterations, _latch);

            _disruptor.HandleEventsWith(_handler1, _handler2, _handler3);
            _ringBuffer = _disruptor.RingBuffer;
        }
        public MultiCast1P3CDisruptorPerfTest()
            : base(100 * Million)
        {
            _disruptor = new Dsl.Disruptor<ValueEvent>(() => new ValueEvent(),
                                                      new SingleThreadedClaimStrategy(Size),
                                                      new YieldingWaitStrategy());

            _latch = new CountdownEvent(3);

            _handler1 = new ValueMutationEventHandler(Operation.Addition, Iterations, _latch);
            _handler2 = new ValueMutationEventHandler(Operation.Substraction, Iterations, _latch);
            _handler3 = new ValueMutationEventHandler(Operation.And, Iterations, _latch);

            _disruptor.HandleEventsWith(_handler1, _handler2, _handler3);
            _ringBuffer = _disruptor.RingBuffer;
        }
        public Pipeline3StepLatencyDisruptorPerfTest()
            : base(2 * Million)
        {
            _disruptor = new Dsl.Disruptor <ValueEvent>(() => new ValueEvent(),
                                                        new SingleThreadedClaimStrategy(Size),
                                                        new YieldingWaitStrategy());

            _mru = new ManualResetEvent(false);
            _stepOneFunctionEventHandler   = new LatencyStepEventHandler(FunctionStep.One, Histogram, StopwatchTimestampCostInNano, TicksToNanos, Iterations, _mru);
            _stepTwoFunctionEventHandler   = new LatencyStepEventHandler(FunctionStep.Two, Histogram, StopwatchTimestampCostInNano, TicksToNanos, Iterations, _mru);
            _stepThreeFunctionEventHandler = new LatencyStepEventHandler(FunctionStep.Three, Histogram, StopwatchTimestampCostInNano, TicksToNanos, Iterations, _mru);

            _disruptor.HandleEventsWith(_stepOneFunctionEventHandler)
            .Then(_stepTwoFunctionEventHandler)
            .Then(_stepThreeFunctionEventHandler);
            _ringBuffer = _disruptor.RingBuffer;
        }
        public Pipeline3StepLatencyDisruptorPerfTest()
            : base(2 * Million)
        {
            _disruptor = new Dsl.Disruptor<ValueEvent>(() => new ValueEvent(),
                                                   new SingleThreadedClaimStrategy(Size),
                                                   new YieldingWaitStrategy());

            _mru = new ManualResetEvent(false);
            _stepOneFunctionEventHandler = new LatencyStepEventHandler(FunctionStep.One, Histogram, StopwatchTimestampCostInNano, TicksToNanos, Iterations, _mru);
            _stepTwoFunctionEventHandler = new LatencyStepEventHandler(FunctionStep.Two, Histogram, StopwatchTimestampCostInNano, TicksToNanos, Iterations, _mru);
            _stepThreeFunctionEventHandler = new LatencyStepEventHandler(FunctionStep.Three, Histogram, StopwatchTimestampCostInNano, TicksToNanos, Iterations, _mru);

            _disruptor.HandleEventsWith(_stepOneFunctionEventHandler)
                .Then(_stepTwoFunctionEventHandler)
                .Then(_stepThreeFunctionEventHandler);
            _ringBuffer = _disruptor.RingBuffer;
        }