Sjaak
Sjaak

Reputation: 65

What is the overhead of Masstransit when running on RabbitMQ?

When using Masstransit with RabbitMQ I see a disappointing performance. Deliver/get drops to 0.20/sec. I started to investigate this problem with a simple test application. This application runs in parallel a thread sending messages to RabbitMQ using the RabbitMQ client library and a thread using the Masstransit library sending the same message to RabbitMQ. The RabbitMQ client library can send 10 times more message than the Masstransit library.

RabbitMQ is running in a Docker container in a HyperV machine. The PublishConfirm flag of Masstransit has some effect but not that much. In order to get a fair comparison a defined the same topology for the RabbitMQ case as is used in the Masstransit case.

Masstransit code:

        public MasstransitMessageSender(string user, string password, string rabbitMqHost)
        {
            this.user = user;
            this.password = password;
            this.rabbitMqHost = rabbitMqHost;
        }

        public RabbitMqMessageSender(string user, string password, string rabbitMqHost)
        {
            var myUri = new Uri(rabbitMqHost);

            this.factory = new ConnectionFactory
            {
                HostName = myUri.Host,
                UserName = user,
                Password = password,
                VirtualHost = myUri.LocalPath,
                Port = (myUri.Port > 0 ? myUri.Port : -1),
                AutomaticRecoveryEnabled = true
            };
        }

        public Task SendCommands(int numberOfMessages)
        {
            return Task.Run(() =>
            {
                var busControl = global::MassTransit.Bus.Factory.CreateUsingRabbitMq(
                    sbc =>
                    {
                        // Host control
                        var host =
                            sbc.Host(
                                new Uri(this.rabbitMqHost),
                                h =>
                                {
                                    h.Username(this.user);
                                    h.Password(this.password);
                                    h.Heartbeat(60);
                                    h.PublisherConfirmation = false;
                                });
                    });

                busControl.StartAsync().Wait();
                var task = busControl.GetSendEndpoint(new Uri(this.rabbitMqHost + "/MasstransitService"));
                var tasks = new List<Task>();

                task.Wait();
                var endpoint = task.Result;
                for (var i = 0; i < numberOfMessages; i++)
                {
                    tasks.Add(endpoint.Send<IMyMessage>(new
                    {
                        Number = i,
                        Description = "MyMessage"
                    }));
                }

                Task.WaitAll(tasks.ToArray());
            });
        }

RabbitMQ code:

        public RabbitMqMessageSender(string user, string password, string rabbitMqHost)
        {
            var myUri = new Uri(rabbitMqHost);

            this.factory = new ConnectionFactory
            {
                HostName = myUri.Host,
                UserName = user,
                Password = password,
                VirtualHost = myUri.LocalPath,
                Port = (myUri.Port > 0 ? myUri.Port : -1),
                AutomaticRecoveryEnabled = true
            };
        }

        public Task SendCommands(int numberOfMessages)
        {
            return Task.Run(() =>
            {
                using (var connection = this.factory.CreateConnection())
                {
                    using (var channel = connection.CreateModel())
                    {
                        var messageProperties = channel.CreateBasicProperties();
                        channel.ExchangeDeclare("PerformanceConsole:ShowRabbitMqMessage", "fanout", true, false, null);
                        channel.ExchangeDeclare("RabbitMqService", "fanout", true, false, null);
                        channel.QueueDeclare("RabbitMqService", true, false, false, null);
                        channel.ExchangeBind("RabbitMqService", "PerformanceConsole:ShowRabbitMqMessage", "", null);
                        channel.QueueBind("RabbitMqService", "RabbitMqService", "", null);
                        for (var i = 0; i < numberOfMessages; i++)
                        {
                            var bericht = new
                            {
                                Volgnummer = 1,
                                Tekst = "Bericht"
                            };
                            var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(bericht));
                                channel.BasicPublish("RabbitMqService", "", messageProperties, body);
                        }
                    }
                }
            });
        }

The RabbitMQ dashboard shows the following rates:

Masstransit incoming 664 msg/s RabbitMQ incoming 6764 msg/s

I expected to incoming rates to be in the same range.

Maybe I made a mistake in the configuration, suggestions are welcome.

Upvotes: 3

Views: 1899

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33457

Using the MassTransit-Benchmark I get the following performance on my MacBook Pro 2015, using netcoreapp2.2 on OS X.

PhatBoyG-Pro15:MassTransit-Benchmark Chris$ dotnet run -f netcoreapp2.2 -- --clients=50 --count=50000 --prefetch=100
MassTransit Benchmark

Transport: RabbitMQ
Host: localhost
Virtual Host: /
Username: guest
Password: *****
Heartbeat: 0
Publisher Confirmation: False
Running Message Latency Benchmark
Message Count: 50000
Clients: 50
Durable: False
Payload Length: 0
Prefetch Count: 100
Concurrency Limit: 0
Total send duration: 0:00:05.2250045
Send message rate: 9569.37 (msg/s)
Total consume duration: 0:00:07.2385114
Consume message rate: 6907.50 (msg/s)
Concurrent Consumer Count: 8
Avg Ack Time: 4ms
Min Ack Time: 0ms
Max Ack Time: 251ms
Med Ack Time: 4ms
95t Ack Time: 6ms
Avg Consume Time: 1431ms
Min Consume Time: 268ms
Max Consume Time: 2075ms
Med Consume Time: 1639ms
95t Consume Time: 2070ms

You can download the benchmark and run it yourself: https://github.com/MassTransit/MassTransit-Benchmark

Upvotes: 1

Related Questions