There is no answer for every OS. This will depend on the specific set of tasks your code performs. You should compare your application with different configurations to find out which one is most effective.
Some general threading tips:
You cannot speed up tasks with lots of threads; the exception is that if you have several processors, you can parallelize computational tasks in one thread per processor, provided that this logic can be divided so that it does not have to be executed in series. A good example for this would be a divide and win problem, such as mergesort, where the two halves can be sorted in any order.
You can achieve some acceleration by parallelizing tasks that do not use the same part of the machine. So, given that you say that you have βequal valueβ in the I / O and computation operations, you will want to separate them into different threads - again, this assumes that the ordering does not matter.
If this is the case (as in many applications), the threads perform some computational logic, followed by some I / O operations (for example, writing data to a disk or database server), then it will be very difficult to come up with some formula to determine the exact amount streams that you should have, as this will greatly depend on the data you process, on how you process it, and what you do with it when processing. This is why it is best to have a custom thread pool that can be easily adjusted for size β then do some load tests of different sizes and see which one is best done.
danben
source share