Skip to content

Latest commit

 

History

History
63 lines (48 loc) · 2.06 KB

README.md

File metadata and controls

63 lines (48 loc) · 2.06 KB

Disruptor-net.Metrics

Easy performance montoring of your disruptor ringbuffers.

It will:

  • Tell you how many items has been processed.
  • Min, max and average time (milliseconds) each item spent in the queue.
  • How much (percentage) of your ringbuffer is available.
  • Dump this data in your favorite logging framework via sinks (yes I stole the sink concept from serilog).

It will have a small impact on the overall performance of your ringbuffer. You need to choose carefully how you use it - If you log too much too often you will ruin performance. Play around with the settings to find your sweet spot.

Also available on nuget

https://www.nuget.org/packages/Disruptor-net.Metrics/

Usage - 3 easy steps

This example will output metrics every second to the console.

What ever you put in your ringbuffer, make it implement IRingBufferItem.

public class QueueItem : IRingBufferItem
    {
        public DateTimeOffset FirstTouchTime { get; set; }
        
        // All your other stuff here
        
        public void Update(QueueItem other)
        {
          ...
        }
    }

When you enqueue a new item, set FirstTouchTime to UtcNow

  public void Enqueue(QueueItem item)
        {
            var next = ringBuffer.Next();
            var entry = ringBuffer[next];
            entry.Update(item);
            entry.FirstTouchTime = DateTimeOffset.UtcNow;
            ringBuffer.Publish(next);
        }

Add the metrics eventhandler to your disruptor.

    var metricsEventHandler = new FixedSecondCountReporter<QueueItem>(new ColoredConsoleSink(), 1);    
    disruptor = Disruptor<QueueItem>(() => new QueueItem(), ringbufferSize, TaskScheduler.Default);

    disruptor.HandleEventsWith(eventHandler1, eventHandler2).Then(metricsEventHandler);
    
    ringBuffer = disruptor.Start();
    metricsEventHandler.Setup(ringBuffer); // Important: Do this AFTER disruptor.Start() has been run.

#License See the LICENSE file for license rights and limitations (MIT).