I am using Azure.Messaging.ServiceBus SDK and I am unable to understand the below statement.
My Subscription has 200 messages. My understanding is that if I execute the below statement it must return me 5 counts of messages or if I give the value as 200, it must return me 200 but it returns me only one all the time whatever I do. I tried setting the TimeSpan to very high values too. Basically, I am trying to increase the throughput on the receiving. I am quite happy with the send throughput using batching but I guess I am not understanding the SDK well to leverage max receive throughput.
var messages = await receiver.ReceiveMessagesAsync(5, TimeSpan.FromDays(1));
I am open to inputs on improving using "processorClient.CreateProcessor" too. In this case I dont see any other way other than increasing "PrefetchCount"
My understanding is that if I execute the below statement it must return me 5 counts of messages or if I give the value as 200, it must return me 200
This is incorrect. The parameter is called maxMessages
and represents the maximum number of messages that will be received, not a guarantee. There is no minimum batch size when receiving messages.
The receiver lets the service know the maximum number of messages that it would like and then gives your application the set returned from that operation. The client does not attempt to build a batch of the requested size across multiple operations.
There are two main reasons for this approach. First, the lock associated with the message is held only for a limited time after which it expires if not renewed. Were the client to hold onto messages across multiple operations to try and build a batch, the time that your application has to process messages would be sporadic and, in the worst case, you would receive messages with expired locks that could not be completed. Second, the client prioritizes providing data to your application as quickly as possible to help maximize throughput.
I am open to inputs on improving using "processorClient.CreateProcessor" too. In this case I dont see any other way other than increasing "PrefetchCount"
Throughput is impacted by a number of factors from the network, host, workload, message size/composition, and service tier. It is very difficult to generalize advice.
A few things that would normally help:
Ensure that your application is running in the same Azure region as your Service Bus namespace.
Consider increasing concurrency. This may involve using multiple receivers and/or tuning the concurrency settings on the processor.
Consider using prefetch
to eagerly stream messages from the service.
(Note: messages held in prefetch are locked and those locks cannot be renewed. Tune accordingly and test thoroughly)
I'd recommend reading through Best Practices for performance improvements using Service Bus Messaging as it goes into quite a bit more depth.