예제 #1
0
        public void Run()
        {
            _ring            = new RingBuffer <ValueEvent>(() => new ValueEvent(), new MultiThreadedClaimStrategy(2048), new YieldingWaitStrategy());
            _sequenceBarrier = _ring.NewBarrier();
            _sequence        = new Sequence(Sequencer.InitialCursorValue);
            _ring.SetGatingSequences(_sequence);
            var manager = new EventStoreManager();

            //manager.CompressionStrategy = new NoCompressionStrategy();
            using (var stream = new FileStream("0.event", FileMode.Create, FileAccess.ReadWrite, FileShare.None, 1))
            {
                var file = new StreamEventFileStorage(stream);
                _writeStore = manager.AppendToStore(file);
                var consumerTask = Task.Factory.StartNew(EventConsumer,
                                                         TaskCreationOptions.LongRunning |
                                                         TaskCreationOptions.HideScheduler);
                _sw.Start();
                var tasks = new Task[ParallelTasks];
                Parallel.For(0, tasks.Length, i =>
                {
                    tasks[i] = PublishSampleEvents(RepetitionCount);
                });
                Task.WaitAll(tasks);
                _sequenceBarrier.Alert();
                consumerTask.Wait();
                _sw.Stop();
                Console.WriteLine("Write {0}ms events per second:{1:f0} total len:{2}", _sw.ElapsedMilliseconds,
                                  tasks.Length * RepetitionCount / _sw.Elapsed.TotalSeconds, stream.Length);
                _sw.Restart();
                var allObserverCounter = new AllObserverCounter();
                manager.OpenReadOnlyStore(file).ReadFromStartToEnd(allObserverCounter);
                _sw.Stop();
                Console.WriteLine("Read {0}ms events per second:{1:f0} events:{2}", _sw.ElapsedMilliseconds,
                                  allObserverCounter.Count / _sw.Elapsed.TotalSeconds, allObserverCounter.Count);
            }
        }
예제 #2
0
 /// <summary>
 /// Signal that this <see cref="IEventProcessor"/> should stop when it has finished consuming at the next clean break.
 /// It will call <see cref="ISequenceBarrier.Alert"/> to notify the thread to check status.
 /// </summary>
 public void Halt()
 {
     _running = 0;
     _sequenceBarrier.Alert();
 }
 public void Run()
 {
     _ring = new RingBuffer<ValueEvent>(() => new ValueEvent(), new MultiThreadedClaimStrategy(2048), new YieldingWaitStrategy());
     _sequenceBarrier = _ring.NewBarrier();
     _sequence = new Sequence(Sequencer.InitialCursorValue);
     _ring.SetGatingSequences(_sequence);
     var manager = new EventStoreManager();
     //manager.CompressionStrategy = new NoCompressionStrategy();
     using (var stream = new FileStream("0.event", FileMode.Create, FileAccess.ReadWrite, FileShare.None, 1))
     {
         var file = new StreamEventFileStorage(stream);
         _writeStore = manager.AppendToStore(file);
         var consumerTask = Task.Factory.StartNew(EventConsumer,
                                                  TaskCreationOptions.LongRunning |
                                                  TaskCreationOptions.HideScheduler);
         _sw.Start();
         var tasks = new Task[ParallelTasks];
         Parallel.For(0, tasks.Length, i =>
             {
                 tasks[i] = PublishSampleEvents(RepetitionCount);
             });
         Task.WaitAll(tasks);
         _sequenceBarrier.Alert();
         consumerTask.Wait();
         _sw.Stop();
         Console.WriteLine("Write {0}ms events per second:{1:f0} total len:{2}", _sw.ElapsedMilliseconds,
                           tasks.Length * RepetitionCount / _sw.Elapsed.TotalSeconds, stream.Length);
         _sw.Restart();
         var allObserverCounter = new AllObserverCounter();
         manager.OpenReadOnlyStore(file).ReadFromStartToEnd(allObserverCounter);
         _sw.Stop();
         Console.WriteLine("Read {0}ms events per second:{1:f0} events:{2}", _sw.ElapsedMilliseconds,
                           allObserverCounter.Count / _sw.Elapsed.TotalSeconds, allObserverCounter.Count);
     }
 }
예제 #4
0
 /// <summary>
 /// Signal that this <see cref="IEventProcessor"/> should stop when it has finished consuming at the next clean break.
 /// It will call <see cref="ISequenceBarrier.Alert"/> to notify the thread to check status.
 /// </summary>
 public void Halt()
 {
     _running.WriteFullFence(Stopped);
     _sequenceBarrier.Alert();
 }
예제 #5
0
 public void Alert()
 {
     _target.Alert();
 }
예제 #6
0
 /// <summary>
 /// Signal that this <see cref="IEventProcessor"/> should stop when it has finished consuming at the next clean break.
 /// It will call <see cref="ISequenceBarrier.Alert"/> to notify the thread to check status.
 /// </summary>
 public void Halt()
 {
     _running.Value = false;
     _sequenceBarrier.Alert();
 }
 public void Halt()
 {
     running.WriteFullFence(false);
     sequenceBarrier.Alert();
 }
예제 #8
0
 public void Halt()
 {
     Interlocked.Exchange(ref _running, Halted);
     _sequenceBarrier.Alert();
 }