.NET Event aggregators that are optimized for applications that send lots of events?

469 Views Asked by At

We are having an issue with lots of events firing greatly slowing down our application. Our application is firing events very often, sometimes over 100 events in a second. Currently, we use Prism as our event aggregator but we are finding that the performance is not really meeting our demands, it is causing very high CPU usage and memory issues as well. I am wondering if anyone knows of any .Net event aggregator libraries that are designed for applications which fire lots of events very frequently?

1

There are 1 best solutions below

0
Theodor Zoulias On

You could consider using the Reactive Extensions (Rx) library. Assuming that you have an observable sequence of events:

IObservable<MyEventArgs> source;

You can buffer them with the Buffer operator:

IObservable<IList<MyEventArgs>> buffered = source.Buffer(TimeSpan.FromSeconds(1));

And then subscribe to the buffered sequence to get a notification every time a batch of events has been formed:

buffered.Subscribe((IList<MyEventArgs> batch) =>
{
    try
    {
        ProcessBatch(batch);
    }
    catch (Exception ex)
    {
        _logger.LogError(ex);
    }
});

You can read here how you can create the source observable from an event. In case you find it difficult, you could also use as source an intermediate Subject<MyEventArgs>, and send messages to it with the OnNext method.