Improving publish rates for MassTransit...

161 views
Skip to first unread message

Ben Kyrlach

unread,
Jan 20, 2015, 11:55:31 AM1/20/15
to masstrans...@googlegroups.com
I'm working on a big data application utilizing MassTransit (on top of RabbitMQ). Using a dedicated thread to publish messages from a ConcurrentQueue, it appears to only be able to publish around 75 messages a second. Increasing the number of threads only improves performance slightly. This is in stark contrast to using the underlying RabbitMQ APIs, which allow me to publish the same message using the same setup (single, dedicated thread pulling from a ConcurrentQueue) at a rate of ~4500 messages per second. Here is the code being used for each...

Thread...

new Thread(PublishMessages).Start();

Using MassTransit...

            var serviceBus = ServiceBusFactory.New(configurator =>
            {
                configurator.DisablePerformanceCounters();
                configurator.UseRabbitMq();
                configurator.ReceiveFrom(nontransactionalQueueFormat.FormatWith(machineName, assemblyName, "TrafficAnaylyzer"));                
                configurator.SetConcurrentConsumerLimit(5);
                configurator.Subscribe(subscriptionConfigurator => subscriptionConfigurator.Consumer(() => Kernel.Get<OptInConsumer>()).Transient());
                configurator.UseLog4Net();
            });

        private void PublishMessages()
        {
            var serviceBus = _kernel.Get<IServiceBus>();
            while (!_shouldStop)
            {
                TrafficAnalyzerMessage msg;
                if (_messageQueue.TryDequeue(out msg))
                {
                    serviceBus.Publish(msg);
                }                
            }
        }

Using RabbitMQ...

        private void PublishMessages()
        {
            var factory = new ConnectionFactory
            {
                HostName = "localhost"
            };
            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare("RulesEngine", true, false, false, null);
                    while (!_shouldStop)
                    {
                        TrafficAnalyzerMessage msg;
                        if (_messageQueue.TryDequeue(out msg))
                        {
                            var msgString = JsonConvert.SerializeObject(msg);
                            var msgBytes = Encoding.UTF8.GetBytes(msgString);
                            channel.BasicPublish("", "RulesEngine", null, msgBytes);
                        }
                    }
                }
            }
        }


Any help would be greatly appreciated.

Chris Patterson

unread,
Jan 21, 2015, 12:09:31 AM1/21/15
to masstrans...@googlegroups.com
The only thing I can imagine is that your system is slow? :)

I get between 3,000 and 4,000 messages a second through RabbitMQ locally on my VM. On our production HA cluster with MT 2.9.9, I get usually 1200-1500 per second.

With MT3, it's faster, because you can wait the Publish() Task (MT3 is fully async TPL powered) which makes publishes even faster. With your channel.BasicPublish() it doesn't wait for the message to be committed by the broker. So that's why you're seeing faster publish rates.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/dcfdca4f-faba-444c-bd07-a58d4b8258eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Kyrlach

unread,
Jan 22, 2015, 9:06:04 AM1/22/15
to masstrans...@googlegroups.com
I appreciate your help, but the answer isn't completely satisfactory. Here I've enabled message confirmation by the broker, and the BasicPublish still is orders of magnitude faster than publishing with MT. I was hoping that perhaps you might have some insight into properties of the message that might cause such a poor publish rate (it's not a large message, but it is being published in JSON format). I'm not a RabbitMQ expert, so perhaps my changes also don't mean what I think they mean. Here's the updated code.

        private void PublishMessages()
        {
            var factory = new ConnectionFactory
            {
                HostName = "localhost"
            };
            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare("RulesEngine", true, false, false, null);
                    channel.ConfirmSelect();
                    while (!_shouldStop)
                    {
                        TrafficAnalyzerMessage msg;
                        if (_messageQueue.TryDequeue(out msg))
                        {
                            var msgString = JsonConvert.SerializeObject(msg);
                            var msgBytes = Encoding.UTF8.GetBytes(msgString);
                            channel.BasicPublish("", "RulesEngine", null, msgBytes);
                            channel.WaitForConfirms();
                        }
                    }
                }
            }
        }

Henry wu

unread,
Sep 10, 2017, 5:59:43 AM9/10/17
to masstransit-discuss
I would agree with you. the mt  publish is slow.

在 2015年1月21日星期三 UTC+8上午12:55:31,Ben Kyrlach写道:

Дмитрий Ушенко

unread,
Sep 12, 2017, 5:58:50 AM9/12/17
to masstransit-discuss
I would disagree with you. On my single noded dockerized rabbitmq instace i have around 3k publications per second.

Ben Kyrlach

unread,
Sep 12, 2017, 10:34:58 AM9/12/17
to masstrans...@googlegroups.com
3k pubs/sec is actually slow though. Using the raw RabbitMQ client, I can easily hit 10k on a laptop. The point of this thread is that MassTransit is significantly slower than the base RabbitMQ library.

On Tue, Sep 12, 2017 at 5:58 AM, Дмитрий Ушенко <ushenko...@gmail.com> wrote:
I would disagree with you. On my single noded dockerized rabbitmq instace i have around 3k publications per second.

--
You received this message because you are subscribed to a topic in the Google Groups "masstransit-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/masstransit-discuss/vUOYgqnVyL8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/0138bf4a-5326-42e4-8cab-7f38dc22c2ed%40googlegroups.com.

Дмитрий Ушенко

unread,
Sep 12, 2017, 11:59:45 AM9/12/17
to masstrans...@googlegroups.com
You are right. MT is slower then the raw rmq client. Just becouse it adds another layer on top of it. Just like EF on top of raw ADO.Net. And i disagree with you in the second part of your post. The real point of this topic is that you have only 75 messages/sec in your environment. Just don't waste your time trying to find the reason of this in MT. 

вт, 12 сент. 2017 г. в 17:34, Ben Kyrlach <bkyr...@gmail.com>:
3k pubs/sec is actually slow though. Using the raw RabbitMQ client, I can easily hit 10k on a laptop. The point of this thread is that MassTransit is significantly slower than the base RabbitMQ library.
On Tue, Sep 12, 2017 at 5:58 AM, Дмитрий Ушенко <ushenko...@gmail.com> wrote:
I would disagree with you. On my single noded dockerized rabbitmq instace i have around 3k publications per second.

--
You received this message because you are subscribed to a topic in the Google Groups "masstransit-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/masstransit-discuss/vUOYgqnVyL8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "masstransit-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/masstransit-discuss/vUOYgqnVyL8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/CANEQmhUU0yRbenSjQie%3DmTZek7WC4199C9ad78XNTXGJdx%3DHtQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages