0

I have a C# program that process a long batch of files. The processing is done with a varying number of Task.Run threads. While this is very efficient and expected under Windows 10, strange stuff happens on Windows 2016 or Windows 2019 Dual core servers:

  • The CPU% isn't maxing even if many tasks are run in parallel
  • The total file processing speed remains pretty much the same with 10 20 or 30 tasks in parallel.
  • The only way to get more throughput is to run several instances of the same application.

Is this a normal server behavior? Can it be configured to "work harder on each instance" like Windows10?

user3104076
  • 41
  • 1
  • 5
  • 1
    file handling is IO bound and not CPU bound, so reading/writing shouldn't need threads or cpu. https://stackoverflow.com/questions/868568/what-do-the-terms-cpu-bound-and-i-o-bound-mean – Rand Random Feb 21 '22 at 10:39
  • Its not about file IO Its about processing data. Reading is not near limit and writing is not involved. – user3104076 Feb 21 '22 at 12:25
  • IMHO than you would need to show your code, your question is to broad to answer I don't believe that the thread scheduler could make a difference – Rand Random Feb 21 '22 at 13:48
  • Don't conflate the idea of Task and Threads. There may be a different thread with a task, but there also may not be. – Enigmativity Feb 21 '22 at 22:37
  • Thx Enigmativity, can you please explain more? How can one force a Task.Run to a different thread? – user3104076 Feb 22 '22 at 17:16
  • @user3104076 - To start with, read this: https://blog.stephencleary.com/2013/11/there-is-no-thread.html – Enigmativity Feb 22 '22 at 20:32
  • Tasks are an abstraction for the process of a future result. They are not a promise that there is a thread nor, in the case where there is a thread, that it's a different thread to the one you're on. Let's say you've got code running in a task that's using a thread pool thread, and you `Task.Run` a thousand tasks that all will use a thread form the thread pool. The task scheduler can't run all thousand tasks simultaneously, so it queues them up. It could queue up some of the tasks to run on the thread that created the tasks themselves. – Enigmativity Feb 22 '22 at 20:36
  • The point is that tasks are abstractions and you should generally not consider that there is a thread. – Enigmativity Feb 22 '22 at 20:36

0 Answers0