[Go] How to determine the number of concurrent threads for a program based on the number of processor of the CPU

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.