c# - 使用相同库 api 的 Rabbitmq 的性能非常不同(python3 与 dotnet)
问题描述
我一直在尝试找出使用 rabbitmq python 库(pika/aiopika)的最佳方法,而我注意到当我使用 dotnet 库(RabbitMQ.客户)。
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)
这让我得到了11K msgs/s 和 100% CPU 使用率的结果
对于 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);
}
}
此代码产生100K msgs/s 的结果,CPU 使用率为 30%
我究竟做错了什么?
解决方案
推荐阅读
- excel - VBA excel更改具有不同值的单元格
- java - 如何为 Kafka 寻找带有 Spring 的时间戳偏移量
- image - 选择多个图像并以表格形式显示它们
- eclipse - 限制 eclipse 只从 Project Explorer 打开一个文件
- java - 从 JAVA setAutoCommit(false) 迁移到 nodejs knex (SQL Server)
- python - PyCharm 不显示绘图并且速度很慢
- xml - 如何读取机器人框架中的 XML 响应元素?
- amcharts - amCharts 4 Geo Heat Map - 如何向工具提示添加逻辑?
- javascript - Javascript - 带有 PDF.js 的总页数 pdf?
- android - 程序类型已存在:12 月 3 日 Firebase 更新后的 com.google.android.gms.internal.measurement.zzsa