Async / Await vs Parellel.For, which is better in this case?

So, I have 1000 elements to check how relevant they are. Each of these elements requires reading thousands of files (some of which may be the same file for different elements).

This currently implements the use of TPL (async / await), one for each file that it should read, and one for each element that it should check. This works great, except that when I look at it, about the 3rd most expensive feature is TrySteal in the thread pool.

Using the concurrency visual studio viewer, I see that 99% of the time spent in threads spent in concurrently connected items and only 1% in execution. That is what makes me think that I might just create too many tasks (note: I don't use Task.Run anywhere, just waiting).

Will Parellel.For be less overhead than reading a bunch of files using async / wait? How much overhead is expected with a task library?

+4
source share
1 answer

, , . , , , , , . , , . , , , , , . ( ).

: , , . , , , . Parallel.ForEach(). , Parallel.Foreach() , async, .

+2

Source: https://habr.com/ru/post/1691002/


All Articles