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?