The number of threads is set when multithreading is used

Source: Internet
Author: User

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

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.