Reputation: 568
Would it make any benefit if I call QueueClient.SendMessageAsync (Azure.Storage.Queues) in parallel? At the moment I call it like that:
var client = new QueueClient(
Options.CurrentValue.ConnectionString,
Options.CurrentValue.ItemRecalculateQueueName);
foreach (var item in items)
{
var message = CreateItemRecalculationMessage(item);
try
{
await client.SendMessageAsync(message, ct);
}
catch (Exception e)
{
Log.Error(e, "Failed to recalculate item {item}", item);
}
}
If so, is there any limit of reasonable parallelization? At the moment messages are added in a sequential fashion.
Thanks, Radek
Upvotes: 0
Views: 482
Reputation: 136236
Would it make any benefit if I call QueueClient.SendMessageAsync (Azure.Storage.Queues) in parallel?
Most certainly. You will definitely benefit from sending messages in parallel using something like Task.WaitAll()
as you will be able to send more messages in the same amount of time.
If so, is there any limit of reasonable parallelization?
In my experience, limiting the maximum number of parallel tasks to the number of virtual CPUs gives the best results. I believe this has something to do with context switching at the CPU level.
Upvotes: 3