parallelizing async calls #94245
Replies: 2 comments
-
To an extent, neither. This is in effect creating a task scheduler without extending the actual abstract After that, the primary consideration is going to be how much work is occurring for each item. If it's relatively long, generally queueing a task per each would be preferrable for cleanliness reasons. If it's really short, then potentially consider batching the individual elements (but recall you'll lose information about individual elements in the batch). |
Beta Was this translation helpful? Give feedback.
-
Issues in your implementations:
A hypothetic solution can be: foreach (var chunk in items.Chunk(amountOfParallelism))
{
await Task.WhenAll(chunk.Select(item => funcAsync(item)));
} Preserves your (non-best) behavior and is much simpler. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
Assuming funcAsync is some IO bound operations -
which of the following implementations of BatchExecuteAsync would be preferrable for better throughput / efficiency etc. ?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions