Giter Site home page Giter Site logo

farukerat / mediators-benchmark Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 12 KB

Performance comparison of the mediator patterns implemented with MassTransit and MediatR in C#

License: MIT License

C# 100.00%
dotnet masstransit mediator mediatr benchmark

mediators-benchmark's Introduction

Benchmarking Mediator Performance: MassTransit vs. MediatR

This repository contains benchmarking code and results comparing the performance of the mediator patterns implemented with MassTransit and MediatR in C#.

Introduction

Mediator patterns are widely used in software development to decouple components and facilitate communication between them. MassTransit and MediatR are two popular libraries in the .NET ecosystem that provide implementations of mediator patterns, each with its own strengths and trade-offs.

While MediatR is specifically designed as a mediator library, it's important to note that MassTransit is primarily focused on message queue systems, such as RabbitMQ. Despite this, MassTransit can still be used to implement mediator patterns, although it may not be as optimized for this purpose as MediatR.

This benchmark aims to compare the performance of using MassTransit and MediatR as mediators in a simple scenario.

Benchmark Results

The benchmark results below showcase the performance comparison between MassTransit and MediatR in terms of execution time:

Method Mean Error StdDev Gen0 Allocated
MassTransit 46,194.26 ns 1,287.700 ns 3,796.813 ns 2.8687 11975 B
MediatR 189.63 ns 4.725 ns 13.172 ns 0.0861 360 B
DirectResponse 12.45 ns 0.479 ns 1.366 ns 0.0115 48 B

Legends:

  • Mean : Arithmetic mean of all measurements
  • Error : Half of 99.9% confidence interval
  • StdDev : Standard deviation of all measurements
  • Gen0 : GC Generation 0 collects per 1000 operations
  • Allocated : Allocated memory per single operation (managed only, inclusive, 1KB = 1024B)
  • 1 ns : 1 Nanosecond (0.000000001 sec)

Methodology

The benchmark was conducted using BenchmarkDotNet, a powerful .NET library for benchmarking. The benchmarking code simulates a simple mediator pattern scenario, where a message is passed to the mediator, which in turn dispatches it to the appropriate handler.

Getting Started

To reproduce the benchmark or explore the code, follow these steps:

  1. Clone this repository to your local machine:

    git clone https://github.com/FarukErat/Mediators-Benchmark.git
  2. Open the solution in your preferred IDE or text editor.

  3. Build the solution.

  4. Run the benchmark project to execute the performance tests.

Code Overview

The benchmarking code consists of two implementations of mediators using MassTransit and MediatR libraries. Key components include:

  • MassTransitMediator: Implementation of mediator using MassTransit.
  • MediatRMediator: Implementation of mediator using MediatR.
  • BenchmarkRunner: Entry point for running the benchmarks.

Conclusion

Based on the benchmark results, MediatR demonstrates significantly better performance compared to MassTransit in this particular scenario. However, it's important to consider that MassTransit is primarily designed for message queue systems like RabbitMQ and may not be as optimized for mediator patterns as MediatR.

When choosing between MassTransit and MediatR for mediator pattern implementations, consider factors such as performance requirements, feature sets, ease of use, and compatibility with your existing infrastructure.

Feel free to explore the code and modify it according to your needs. Contributions and feedback are welcome!

License

This project is licensed under the MIT License - see the LICENSE file for details.


Note: The benchmark results may vary depending on factors such as hardware, environment, and workload. Interpret the results with consideration to your specific use case.

mediators-benchmark's People

Contributors

farukerat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.