コード例 #1
0
        public SharedBuffer()
        {
            disruptor = new Disruptor.Dsl.Disruptor <SharedBufferValue>(() => new SharedBufferValue(), _ringSize, TaskScheduler.Default);

            sbh = new SharedBufferHandler();
            this.Setup();
        }
コード例 #2
0
        public async Task DisruptorTest()
        {
            var disruptor =
                new Disruptor.Dsl.Disruptor <ValueEntry>(() => new ValueEntry(), RingBufferAndCapacitySize, TaskScheduler.Default,
                                                         producerCount > 1 ? ProducerType.Multi : ProducerType.Single, new BlockingWaitStrategy());

            disruptor.HandleEventsWith(new MyHandler());
            var       _ringBuffer = disruptor.Start();
            Stopwatch sw          = Stopwatch.StartNew();

            sw.Start();
            var tasks = new Task[producerCount];

            for (int t = 0; t < producerCount; t++)
            {
                tasks[t] = Task.Run(() =>
                {
                    for (int i = 0; i < runCount; i++)
                    {
                        long sequenceNo            = _ringBuffer.Next();
                        _ringBuffer[sequenceNo].Id = 0;
                        _ringBuffer.Publish(sequenceNo);
                    }
                });
            }
            await Task.WhenAll(tasks);

            disruptor.Shutdown();
            sw.Stop();
            Console.WriteLine($"DisruptorTest Time:{sw.ElapsedMilliseconds/1000d}s");
        }
コード例 #3
0
        private static readonly int _ringSize  = 1024;     // Must be multiple of 2

        static void Main(string[] args)
        {
            sw = Stopwatch.StartNew();

            var disruptor  = new Disruptor.Dsl.Disruptor <ValueEntry>(() => new ValueEntry(), _ringSize, TaskScheduler.Default);
            var ringBuffer = disruptor.Start();

            for (int i = 0; i < length; i++)
            {
                var  valueToSet = i;
                long sequenceNo = ringBuffer.Next();

                ValueEntry entry = ringBuffer[sequenceNo];

                entry.Value = valueToSet;

                ringBuffer.Publish(sequenceNo);

                //Console.WriteLine("Published entry {0}, value {1}", sequenceNo, entry.Value);

                //Thread.Sleep(1000);
            }

            var elapsed = sw.Elapsed.Miliseconds();

            // wait until all events are delivered
            Thread.Sleep(10000);

            double average = / (double)length;

            Console.WriteLine("average = " + average);
        }
コード例 #4
0
        public DisruptorRingBuffer()
        {
            disruptor = new Disruptor.Dsl.Disruptor <ValueEntry>(() => new ValueEntry(), _ringSize, TaskScheduler.Default);

            dch          = new DataCommunicationHandler();
            dch.avgLayer = new MovingAverageFilter();
            disruptor.HandleEventsWith(dch);
            ringBuffer = disruptor.Start();
        }
コード例 #5
0
        public SharedBuffer()
        {
            disruptor = new Disruptor.Dsl.Disruptor <SharedBufferValue>(() => new SharedBufferValue(), _ringSize, TaskScheduler.Default);

            SharedBufferHandler dch = new SharedBufferHandler();

            //dch.avgLayer = new MovingAverageFilter();
            disruptor.HandleEventsWith(dch);
            ringBuffer = disruptor.Start();
        }
コード例 #6
0
        static void Main()
        {
            var disruptor = new Disruptor.Dsl.Disruptor <ValueEntry>(() => new ValueEntry(), SIZE, TaskScheduler.Default);

            for (int i = 0; i < WORKERS; i++)
            {
                disruptor.HandleEventsWith(new MyHandler());
            }
            var ringBuffer = disruptor.Start();

            while (true)
            {
                long sequenceNo = ringBuffer.Next();
                ringBuffer[sequenceNo].Value = _random.Next();;
                ringBuffer.Publish(sequenceNo);
                Console.WriteLine("Published entry {0}, value {1}", sequenceNo, ringBuffer[sequenceNo].Value);
                Console.ReadKey();
            }
        }
コード例 #7
0
        public void DisruptorTest()
        {
            var disruptor =
                new Disruptor.Dsl.Disruptor <ValueEntry>(() => new ValueEntry(), RingSize, TaskScheduler.Default,
                                                         ProducerType.Single, new BlockingWaitStrategy());

            disruptor.HandleEventsWith(new MyHandler());
            var       _ringBuffer = disruptor.Start();
            Stopwatch sw          = Stopwatch.StartNew();

            sw.Start();
            for (int i = 0; i < runCount; i++)
            {
                long sequenceNo = _ringBuffer.Next();
                _ringBuffer[sequenceNo].Id = 0;
                _ringBuffer.Publish(sequenceNo);
            }
            disruptor.Shutdown();
            sw.Stop();
            Console.WriteLine($"DisruptorTest Time:{sw.ElapsedMilliseconds}");
        }
コード例 #8
0
        private static readonly int _ringSize  = 16;     // Must be multiple of 2

        static void Main(string[] args)
        {
            var disruptor = new Disruptor.Dsl.Disruptor <ValueEntry>(() => new ValueEntry(), _ringSize, TaskScheduler.Default);

            disruptor.HandleEventsWith(new ValueAdditionHandler());

            var ringBuffer = disruptor.Start();

            while (true)
            {
                long sequenceNo = ringBuffer.Next();

                ValueEntry entry = ringBuffer[sequenceNo];

                entry.Value = _random.Next();

                ringBuffer.Publish(sequenceNo);

                Console.WriteLine("Published entry {0}, value {1}", sequenceNo, entry.Value);

                Thread.Sleep(250);
            }
        }