Category: AccidentalFish.Commanding

AzureFromTheTrenches.Commanding 6.1.0 – 10x Performance Improvement

I spent some time today look at the performance of my commanding / mediator framework. Although I did a little performance work early on I’ve made a lot of changes since then and been very focused on getting the feature set and API where I want it.

As a target I wanted to get near to the performance of Mediatr – an excellent framework that describes itself as a “simple, unambitious mediator implementation”. When I began work on my framework I had flexibility as a key goal: I wanted it to support persistent event based models (event sourcing) and an evolutionary approach to architecture and development enabling the seamless movement between command handlers that run locally and remotely. There’s usually a performance price to pay for flexibility and features and so although I’d used some performance focused techniques in the code it seemed unlikely I’d be able to equal the performance of a smaller simpler framework. I decided getting within 20% the performance of Mediatr would be a reasonable price to pay for the additional functionality and flexibility.

Despite starting off in a pretty dismal place – nearly 10x slower than Mediatr – I’ve improved the performance of the framework so it is now about 10% faster than Mediatr as can be seen below (the numbers are from running large numbers of commands through both frameworks):

Commands Time Taken (ms) Per Command (ms)
AzureFromTheTrenches.Commanding 6.1.0 10000000 11695 0.0011695
Mediatr 4.0.1 10000000 12818 0.0012818
AzureFromTheTrenches.Commanding 6.0.0 10000000 127709 0.0127709

 

I’m really pleased by that but I would suggest the numbers are sufficiently close that unless you have an extreme scenario you would be better choosing between the two frameworks based on other factors – predominantly how well they address your specific domain.

For those interested in how I improved the performance of the framework I’ll be documenting my process in an upcoming post (as well as highlighting a blooper that illustrates the need to always test performance in code where it is important).

Open Source Commanding Framework

I’ve been making use of a lightweight configuration based commanding framework in a recent project that proved to be really useful and so I’ve spun it out into an open source project on GitHub, documented it, and released the packages on NuGet.

What I’ve found most useful about it is that commands and actors are registered and configured using an IoC type syntax that also defines how dispatch and execution behave – by changing the configuration you can update your commands to run in memory, over HTTP or via Azure Storage queues without changing your actual application code.

It’s a set of .NET Standard assemblies and runs well with both ASP.Net and ASP.Net Core (along with WebJobs and other Azure type goodness). It’s designed specifically for dependency inversion and IoC containers and works with Unity, Autofac, Ninject and the out the box ASP.Net Core service container.

I’ve released it under the permissive MIT license and I hope it’s useful to you. If you get stuck or have any questions I’m best contacted on Twitter as @azuretrenches.

Contact

  • If you're looking for help with C#, .NET, Azure, Architecture, or would simply value an independent opinion then please get in touch here or over on Twitter.

Recent Posts

Recent Tweets

Recent Comments

Archives

Categories

Meta

GiottoPress by Enrique Chavez