The key points of the thread pool are: 1, minimizing the cost of thread switching and management, and 2. Maximizing CPU utilization.
For 1, the minimum number of threads is required to reduce the cost of thread switching and management;
For 2, require as many threads as possible to ensure maximum utilization of CPU resources.
Therefore, for the task time-consuming situation, requires fewer threads, if there are too many threads, there is a possibility of thread switching and management time, greater than the time of the task execution, that efficiency is low;
For tasks that take a long time, whether it's a CPU task or an IO type of task. If it is a CPU-type task, the number of threads should not be too many, but if it is an IO-type task, the thread is better, and the CPU can be more fully utilized.
So:
High concurrency, low consumption: it is recommended that fewer threads are available, as long as concurrency is met, such as concurrency 100, the thread pool may be set to 10
Low concurrency, high time-consuming scenarios: Multi-Threading is recommended, guaranteed to have idle threads, accepting new tasks, such as concurrency 10, the thread pool may be set to 20;
High Concurrency High time: 1 to analyze the task type, 2 increase the queue, 3, increase the number of threads
In the case of high concurrency time-consuming, I think the idea is to resolve a problem that is difficult to solve by turning it into a solution that we already know.
Therefore, high concurrency and time-consuming, can be converted into
1, high concurrency, time-consuming problems –> asynchronous processing + callbacks, and Case 1 matches
2, low concurrency, time-consuming problem –> front-end plus load balance, high concurrency is apportioned into a number of low concurrency, and the case 2 matches
In fact, when it comes to the core, if you really encounter high concurrency time-consuming scenarios, only add machines, plus compute units (whether asynchronous plus callback or load balance)
Perhaps there is a better idea, welcome to the discussion, once again thank the first floor of the answer. Thank you!
High concurrency, time-consuming tasks, low concurrency, long-time tasks, and what kind of thread pool do you choose? Why? If the business scenario is high concurrency and the task takes a long time, what is the solution?