I have a React page that shows a list of Azure resources. The data is retrieved by calling a C# controller. For each resource it takes around 30s to get all the related data. So if there are 10 resources on the page it takes 5min to load, which is too much.
Instead of using a foreach look I changed the code to use Task.WhenAll (with the hope that the data can be retrieved in parallel, taking 30s independent of the number of resources shown), but it still takes 5min.
var frontends = await frontendManager.GetForCustomer(customerId).ToArrayAsync(cancellationToken);
var tasks = frontends.Select(frontend => frontendManager.PopulateExtaInformation(customerId, frontend, cancellationToken));
await Task.WhenAll(tasks);
return this.Ok(frontends);
It is the stuff inside PopulateExtaInformation that takes a lot of time and it’s all async calls to different Azure C# SDK methods, all are awaited.
Cara Wilderman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.