Radek Strugalski
Radek Strugalski

Reputation: 568

Azure.Storage.Queues: calling QueueClient.SendMessageAsync in parallel

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

Answers (1)

Gaurav Mantri
Gaurav Mantri

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

Related Questions