Original: http://blog.csdn.net/kirayuan/article/details/6321967
We can find the number of processor in cat, where the processor can be understood as a logical CPU.
Here excerpt of a blog to illustrate:
What is the impedance matching principle for thread pool size?
I refer to the "impedance matching principle" in the "common model", which is roughly speaking.
If the thread in the pool is performing a task, the time-intensive calculation takes the proportion of P (0 < P <= 1), and the system has a total of C CPUs, in order for this C CPU to run full without overloading, the thread pool size of the empirical formula T = c/p. (T is a hint, considering that the P-value estimate is not very accurate, the best value of T can float up and down 50%.) )
I'll tell you how this empirical formula came in the future, and verify the correctness of the boundary conditions first.
Assuming C = 8, P = 1.0, the task of the thread pool is fully computationally intensive, then T = 8. As long as 8 active threads will be able to saturate 8 CPUs, no matter how much, because the CPU resources have been consumed.
Assuming C = 8, P = 0.5, the thread pool has half the task of computing, half of it on IO, then T = 16. Considering that the operating system can flexibly and reasonably dispatch sleeping/writing/running threads, then about 16 "50% busy threads" can keep 8 CPUs busy. Starting more threads does not increase throughput, but degrades performance by increasing the overhead of context switching.
If P < 0.2, this formula does not apply, T can take a fixed value, such as 5*c.
In addition, the formula C is not necessarily the total number of CPUs, can be "allocated to the task of the number of CPUs", such as on the 8-core machine to separate 4 cores to do a task, then c=4.
[Go] How to determine the number of concurrent threads for a program based on the number of processor of the CPU