Let’s make a few guesses here, since I haven’t yet had feedback with a comment on your question.
I assume that a large number of workflows occur here as actions (an action, which is a unit of work performed on a parallel foreach), takes longer than a certain amount of time, so the main ThreadPool increases the number of threads. This will happen because ThreadPool follows the pool growth algorithm so that new tasks are not blocked by existing long-term tasks, for example. if all my current threads are busy for half a second, I will start adding more threads to the pool. However, you will have problems if all the tasks are lengthy, and the new tasks that you add will make existing tasks work even longer. This is why you probably see a large number of worker threads - possibly due to disk overclocking or slow network I / O (if network drives are involved).
I also assume that files are copied from one drive to another, or copied from one place to another on one drive. In this case, adding threads to the problem will not help much. Source and target disks have only one set of heads, so an attempt to get them to perform several actions at the same time will most likely slow down their work:
- Disc heads will crack everywhere.
- The cache on your \ OS drive can often be invalid.
This may not be a big problem for parallelization.
Update
In response to your comment, if you get acceleration using multiple threads on smaller data sets, you can experiment with decreasing the maximum number of threads used in your parallel foreach, for example.
ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = 2 }; Parallel.ForEach(Directory.GetFiles(Src), options, file => {
But please keep in mind that a disk failure may negate any benefits of parallelization in the general case. Play with it and evaluate your results.
source share