I am trying to improve throughput on a windows service using Azure Service Bus. What I have noticed is that if I have code like like this.
client.OnMessageAsync(async message =>
{
var timer = new Stopwatch();
timer.Start();
bool shouldAbandon = false;
try
{
// asynchronouse processing of messages
await messageProcessor.ProcessAsync(message);
Interlocked.Increment(ref SimpleCounter);
// complete if successful processing
await message.CompleteAsync();
}
catch (Exception ex)
{
shouldAbandon = true;
Console.WriteLine(ex);
}
if (shouldAbandon)
{
await message.AbandonAsync();
}
timer.Stop();
messageTimes.Add(timer.ElapsedMilliseconds);
},
options);
Where options is
OnMessageOptions options = new OnMessageOptions
{
MaxConcurrentCalls = maxConcurrent,
AutoComplete = false
};
Increasing MaxConcurrentCalls has little effect after a certain number (12-16 usually for what I am doing).
But creating multiple clients (QueueClient) with the same MaxConcurrentCalls does increase performance (Almost linearly).
So what I have been doing is making #queueclient and maxconcurrentcalls configurable but I am wondering if having multiple queueclients is the best approach.
So my question is: Is having multiple queueclients with messagepumps running a bad or good practice for a windows service and azure service bus?