Multithreading number setting
1 There are several scenarios for using multithreading in Web applications:
1.1 A thread is quick to respond to a request, putting some other business operations on the thread to do, while this thread test continues quickly.
1.2 Some businesses need to be handled uniformly, using some threads alone.
1.3 ... I can't think of any other scenarios in the Web App.
2 When using multi-threading, it is generally necessary to start several threads to do the loop, and as for the number of tasks to start, it is based on the amount and frequency of the unified type task, that is, how many tasks are waiting to be executed in the average seconds.
2.1 If the task is very small, or the maximum number of tasks to execute in a second, in this case, only one thread is started to cycle through the tasks in the task queue for this type of task.
2.2 If the task is many, dozens of or more tasks in a second need to execute, this situation requires the best performance of the system, the number of simultaneous threads of the system is the number of CPU cores of the machine, so set the number of threads and CPU cores are similar, the number of threads is generally set to the number of CPUs +1.
2.3 The number of threads is also related to the resources used by the task to execute the system, such as IO blocking in the task. This can take a long time to execute, and it is possible to set the number of threads more.
2.4 If the task type is only calculated and consumes more CPU, set the number of threads equal to the number of CPU cores.
The number of threads is set when multithreading is used