gpt4 book ai didi

c# - 如何确定 Azure ServiceBus PrefetchCount 和 ReceiveBatch 大小

转载 作者:行者123 更新时间:2023-11-30 23:05:38 26 4
gpt4 key购买 nike

我有一个队列处理器,它从 ServiceBus 队列中检索所有消息。我想知道如何确定 MessageReceiver PrefetchCount和 ReceiveBatch messageCount以优化性能。我目前将它们设置为任意数字 500,如下所示:

var receiverFactory = MessagingFactory.CreateFromConnectionString("ConnectionString");
var receiver = await receiverFactory.CreateMessageReceiverAsync("QueueName", ReceiveMode.PeekLock);
receiver.PrefetchCount = 500;

bool loopBatch = true;
while (loopBatch)
{
var tempMessages = await receiver.ReceiveBatchAsync(500, TimeSpan.FromSeconds(1));
// Do some message processing...
loopBatch = tempMessages.Any();
}

运行时,我发现我的批处理通常需要时间“预热”,检索诸如“1, 1, 1, 1, 1, 1, 1, 1, 125, 125, 125, 125.. .”,批量检索数突然跳得更高。

来自Prefetching optimization文档:

When using the default lock expiration of 60 seconds, a good value for SubscriptionClient.PrefetchCount is 20 times the maximum processing rates of all receivers of the factory. For example, a factory creates 3 receivers, and each receiver can process up to 10 messages per second. The prefetch count should not exceed 20 X 3 X 10 = 600. By default, QueueClient.PrefetchCount is set to 0, which means that no additional messages are fetched from the service.

当批量检索似乎一次检索的消息数量差异很大时,我真的不明白如何确定接收者的“每秒消息数”。任何帮助将不胜感激。

最佳答案

I don't really understand how to determine the receiver's "messages per second" when the batch retrieval seems to retrieve widely-varying numbers of messages at a time.

预取在使用 OnMessage API 的场景中更有意义。在这种情况下,会注册一个回调,该回调接受一条消息进行处理,您可以估计该消息的平均处理时间。 OnMessage API 允许定义将运行多少并发回调。如果知道有源源不断的传入消息流,那么逐一检索消息的效率将极其低下。因此,PrefetchCount 用于指定客户端应在后台“批量”检索多少条消息,以将往返保存回服务器。

关于c# - 如何确定 Azure ServiceBus PrefetchCount 和 ReceiveBatch 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48694668/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com