2

I've been trying to figure out what is the best way to use rabbitmq python library (pika/aiopika) while I've noticed I'm getting very different results when I'm doing the same thing using the dotnet library (RabbitMQ.Client).

python:

import pika
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
exchange_name = "test-load"
channel.exchange_declare(exchange_name, exchange_type="topic", durable=True)
msg = 'WhySoSLow?'
while True:
    channel.basic_publish(exchange=exchange_name,routing_key="random", body=msg)

This got me the results of 11K msgs/s with 100% CPU usage

And for the dotnet:

using RabbitMQ.Client;

var factory = new ConnectionFactory() { HostName = "localhost" };
using(var connection = factory.CreateConnection())
using(var channel = connection.CreateModel())
{
    channel.ExchangeDeclare(exchange: "test-load", durable: true, type: "topic");

    var routingKey = "random";
    var message = "WhySoSLow?";

    var body = Encoding.UTF8.GetBytes(message);
    while(true) 
    {
        channel.BasicPublish(   exchange: "test-load", 
                                routingKey: routingKey,
                                basicProperties: null,
                                body: body);

    }
}

This code produces the results of 100K msgs/s with 30% CPU usage

What am I doing wrong?

  • https://stackoverflow.com/questions/29903320/why-is-my-computation-so-much-faster-in-c-sharp-than-python – Pavel Oganesyan Feb 16 '20 at 12:31
  • I am a maintainer for Pika. The library isn't (at this time) developed for performance but more for correctness. If you have time to do some profiling and figure out why these performance differences exist, that would be great. Please follow up on the mailing list - https://groups.google.com/forum/#!forum/pika-python – Luke Bakken Feb 19 '20 at 18:46

1 Answers1

1

Performance differs between languages. C++ would be even faster.

C# has more optimization at both compile- and runtime, while pyton have to deal with boxing and unboxing all the time.

Maybe you can gain some optimization ideas from one of the comment above but with the library you use I doubt.

Alb
  • 412
  • 5
  • 12