The relationship of thread pool threads to (CPU-intensive tasks and I/O intensive tasks)

Source: Internet
Author: User
Tags bulk insert

Some recent columns of JVM and concurrent programming, combined with their own understanding, are a summary of the relationship between the number of thread pool threads and (CPU-intensive tasks and I/O intensive tasks):

1. Examples of task types:

1.1:CPU Intensive:

For example, in general, the static resources of our system, such as JS,CSS, there will be a version number, such as main.js?v0, each time the user accesses this resource, will send a request to the server, compared to the local static file version and the server version of the file is consistent, Inconsistencies are updated. This task generally does not occupy a large amount of Io, so the backend server can be processed quickly and the pressure falls on the CPU.

1.2:I/O Intensive:

For example, recently we do the Vanke CRM system, often large data volumes of queries and BULK insert operations, at this time the pressure is mainly on I/O.

2. The relationship between the number of threads and the task type:

2.1: CPU-intensive Relationship:

In general, the CPU cores = = Maximum number of simultaneous threads. In this case (set the CPU core number N), a large number of clients send requests to the server, but the server can only execute n threads at most.

Set the thread pool work queue length is M, and m>>n, this will cause the CPU to switch threads frequently to execute (if the CPU is using FCFS, it will not switch frequently, such as using other CPU scheduling algorithms, such as the time slice rotation method, the shortest time first, may lead to frequent thread switching) .

So in this case, there is no need to set excessive thread pool work queues (Queue Length = number of CPU Cores | | CPU core number +1).

2.2: Relationship with I/O intensive:

1 threads correspond to 1 stack of methods, and the thread's life cycle is the same as the method stack.

For example, a thread's method stack corresponds to the inbound order: Controller ()->service ()->dao (), because the DAO long-time I/O operation, causing the thread to remain in the work queue, but it does not occupy the CPU, At this point, 1 CPUs are idle.

Therefore, in this case, you should increase the length of the thread pool work queue (if the CPU scheduling algorithm is using FCFS, you cannot switch), try not to let the CPU idle and improve CPU utilization.

If you understand wrong, please correct me.

The relationship of thread pool threads to (CPU-intensive tasks and I/O intensive tasks)

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.