A thread scheduling method, system, device and medium

By allocating thread pools based on task execution time on multi-core CPUs, the problem of excessive resource occupation in multi-task processing is solved, and efficient thread scheduling and system performance improvement is achieved.

CN119415239BActive Publication Date: 2025-04-25SICHUAN AEROSPACE TOPCEN COMM NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510014906.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-06
Publication Date
2025-04-25
Estimated Expiration
2045-01-06

AI Technical Summary

Technical Problem

In a multitasking environment, when different types of tasks compete for system resources, it may cause too much system resources to be occupied by some tasks, causing other tasks to be unable to process normally, the system response speed will slow down, performance will decline or even crash.

Method used

By implementing the thread scheduling method on a multi-core CPU, the execution time of each subtask in each total task is obtained, the time threshold is formulated based on the execution time, the subtasks are grouped into fast thread pools and slow thread pools, and processed by different CPU cores.

Benefits of technology

It realizes the flexibility and efficiency of thread scheduling, improves the system's concurrent processing capability and execution efficiency, and reduces system overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119415239B_ABST
    Figure CN119415239B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of communication technology, and discloses a thread scheduling method, system, device and medium, which are implemented on a multi-core CPU, including: obtaining the execution time of each subtask in each total task; formulating a time threshold according to the execution time of each subtask in the total task, and respectively obtaining the number of the subtasks whose execution time is divided by the time threshold; establishing a fast thread pool and a slow thread pool according to the execution subtask group; placing the subtasks whose execution time is less than the time threshold in the fast thread pool, and placing the subtasks whose execution time is not less than the time threshold in the slow thread pool; the CPU core processes the threads in the fast thread pool or the slow thread pool accordingly. Through the method of the present invention, the number and size of thread pools are dynamically adjusted, and the concurrent processing capability and execution efficiency of the system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a thread scheduling method, system, device and medium. Background Art

[0002] With the development of network function virtualization, more and more function instances can realize their corresponding functions through software programs deployed in servers. There are a large number of tasks of different business types that need to be processed in batches within each system platform. The system overhead and resources required by different types of tasks vary greatly. It is very likely that a small number of types of tasks will cause all the core resources of the platform to be occupied, resulting in other businesses being unable to be processed normally, the system response speed slowing down, performance degradation or even crashing; seriously affecting user trust and project reputation.

[0003] After discussion, the following solutions were proposed for the above problems:

[0004] Thread pool isolation: The above problems are mainly caused by different types of tasks competing for common system resources at the same time. In theory, thread isolation can solve this problem.

[0005] Semaphore isolation: Use the counter mode to record the number of thread pools used by various tasks. When the semaphore upper limit is reached, stop processing tasks of this type.

[0006] MQ queue: Producers use different queues when publishing different types of tasks, and consumers monitor the tasks they are concerned about, naturally achieving the purpose of isolating resources.

[0007] However, the above scheme has the following characteristics:

[0008] The thread pool isolation solution supports active timeout and asynchronous calls, and is suitable for scenarios with low call frequency. However, it has high hardware requirements, and too many thread pools will bring a lot of extra overhead to the operating system, thus affecting the overall performance;

[0009] The semaphore isolation solution has the advantages of being lightweight and having no additional overhead, but it does not support active timeouts and asynchronous calls and has high maintenance costs. If there are many types of tasks that take too long to execute, it is likely to cause processing of other normal tasks.

[0010] Although the MQ queue isolation solution naturally isolates different types of tasks with the help of message queues and supports retries and persistence, this solution requires the transformation of thousands of interfaces on the platform, which will bring great risks to the stability and security of the platform.

[0011] Therefore, it is urgent to design a new thread scheduling method to complete thread scheduling while reducing system overhead as much as possible. Summary of the invention

[0012] The present invention provides a thread scheduling method, system, device and medium to achieve the above requirements.

[0013] The present invention is achieved through the following technical solutions:

[0014] A thread scheduling method is implemented on a multi-core CPU, comprising:

[0015] Get the execution time of each subtask in each total task;

[0016] A time threshold is set according to the execution time of each subtask in the total task, and the number of the subtasks whose execution time is divided by the time threshold is obtained respectively, wherein the subtasks within the same time range are regarded as a subtask group to be executed;

[0017] A fast thread pool and a slow thread pool are established according to the execution subtask groups, and the sizes of the fast thread pool and the slow thread pool are set according to the number of subtasks in each of the execution subtask groups, and the fast thread pool and the slow thread pool are processed by different CPU cores respectively;

[0018] The subtasks whose execution time is less than the time threshold are placed in the fast thread pool, and the subtasks whose execution time is not less than the time threshold are placed in the slow thread pool;

[0019] The CPU core processes threads in the fast thread pool or the slow thread pool accordingly.

[0020] As an optimization, the specific process of obtaining the execution time of each subtask in each total task is:

[0021] A1. Use the SlidingWindow class to record the most recent N execution times of each subtask, and calculate the average execution time of each subtask, set the average as the execution time of the subtask, and save the final execution time of each subtask;

[0022] A2. Obtain the type of each of the subtasks in the total task, and search for a corresponding sliding window according to the type of the subtask, so as to find the execution time corresponding to each of the subtasks.

[0023] As an optimization, the total number of the fast thread pool and the slow thread pool is not greater than the number of cores of the CPU.

[0024] As an optimization, the number of the time threshold is no greater than the number of CPU cores minus 1.

[0025] As an optimization, a time threshold is formulated according to the execution time of each subtask in the total task, and the specific process of obtaining the number of subtasks whose execution time is divided by the time threshold is as follows:

[0026] B1. Determine the number of the time thresholds, and let the number of the time thresholds be N;

[0027] B2. Sort each subtask in the total task according to the corresponding execution time to obtain a subtask sequence in ascending or descending order according to the execution time;

[0028] B3. Determine the total execution time T of the total task, and divide the total execution time T by N+1 to obtain the time average value P, that is, ;

[0029] B4, arranging the execution times corresponding to the subtask sequences in order to obtain an execution time sequence, and sequentially searching for the execution time combination closest to the time average value P from the execution time sequence, thereby dividing the execution time sequence obtained by arranging the execution times corresponding to the subtask sequences in order into N+1 groups of subtask groups to be executed;

[0030] B5. Define the subtasks corresponding to the N+1 execution time groups as to-be-executed subtask groups, and confirm the number of subtasks in each of the to-be-executed subtask groups;

[0031] B6. Let any number between the execution times corresponding to two adjacent subtasks in two adjacent groups of subtasks to be executed and in an adjacent relationship between the two adjacent groups of subtasks to be executed be the time threshold.

[0032] As an optimization, the number of the fast thread pool and the slow thread pool is determined according to the number of groups of the subtask groups to be executed, and the number of core threads in the corresponding fast thread pool and the slow thread pool is determined according to the number of subtasks in the subtask groups to be executed.

[0033] As an optimization, if there are at least two identical execution times in the execution time sequence, different random numbers are added to any one or more of the identical execution times to form new execution times so that the new execution times are all different, and the new execution times are reordered to form a new execution time sequence and divided into time groups to be executed, wherein the position of the new execution time in the new execution time sequence is consistent with the position of the execution times that constitute the new execution time in the original execution time sequence.

[0034] The present invention also discloses a thread scheduling system, which is used to execute the aforementioned thread scheduling method, comprising:

[0035] The acquisition module is used to obtain the execution time of each subtask in each total task;

[0036] A grouping module, used to formulate a time threshold according to the execution time of each subtask in the total task, and respectively obtain the number of the subtasks whose execution time is divided by the time threshold, wherein the subtasks within the same time range are regarded as a subtask group to be executed;

[0037] A thread pool creation module, used to establish a fast thread pool and a slow thread pool according to the execution subtask group, and set the size of the fast thread pool and the slow thread pool according to the number of subtasks in each of the execution subtask groups, and the fast thread pool and the slow thread pool are processed by different CPU cores respectively;

[0038] A placement module, used to place the subtasks whose execution time is less than the time threshold in the fast thread pool, and place the subtasks whose execution time is not less than the time threshold in the slow thread pool;

[0039] An execution module is used for the CPU core to process threads in the fast thread pool or the slow thread pool accordingly.

[0040] The present invention also discloses an electronic device, comprising at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute a thread scheduling method as described above.

[0041] The present invention also discloses a storage medium storing a computer program, wherein the computer program implements the aforementioned thread scheduling method when executed by a processor.

[0042] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0043] The present invention does not classify tasks according to their types, but isolates them according to the length of time they take to execute and supports adaptive adjustment, which can make thread scheduling more flexible and improve the concurrent processing capability and execution efficiency of the system.

[0044] The time threshold number of the present invention can be determined according to the number of CPU cores, thereby determining the size of the fast thread pool and the slow thread pool. The number of the fast thread pool and the slow thread pool is also determined based on the number of CPU cores. This method dynamically adjusts the size and number of the thread pool based on factors such as task load and system resource utilization to improve resource utilization. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The drawings described herein are used to provide a further understanding of the embodiments of the present invention, constitute a part of this application, and do not constitute a limitation of the embodiments of the present invention. In the drawings:

[0046] Figure 1 The present invention is a flowchart of a thread scheduling method. DETAILED DESCRIPTION

[0047] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with embodiments and drawings. The exemplary embodiments of the present invention and their description are only used to explain the present invention and are not intended to limit the present invention.

[0048] This embodiment 1 provides a thread scheduling method, such as Figure 1 As shown, it is implemented on a multi-core CPU.

[0049] On a single-core CPU, multithreading in the thread pool is implemented through time-sharing processing, that is, multithreading is processed in a concurrent manner. ‌ Since a single-core CPU has only one computing core, it cannot really execute multiple threads at the same time. The system will allocate CPU time to different threads in the form of time slices. Each thread executes a piece of code when it obtains a time slice, and then switches to the next thread. Although this switching gives people the illusion of multi-threaded concurrency, in fact, the execution of each thread is serial, and switching between threads will add additional overhead‌.

[0050] On a single-core CPU, thread management in the thread pool is implemented through operating system scheduling. The operating system allocates a time slice to each thread, which is usually very short, about 10 milliseconds. When the time slice of a thread is used up, the operating system switches to another thread for execution. This rapid thread switching makes multiple tasks appear to be running at the same time, but in fact each task is executed in an independent time slice.

[0051] Since current processors are basically multi-core CPUs, a process can be processed by multiple cores at the same time, that is, multiple threads in a process can be processed by multiple cores in parallel. The specific allocation of the thread pool can be scheduled by the method of the present invention.

[0052] Specifically include:

[0053] S1. Get the execution time of each subtask in each total task;

[0054] In some embodiments, the specific process of obtaining the execution time of each subtask in each total task is:

[0055] A1. Use the SlidingWindow class to record the most recent N execution times of each subtask, and calculate the average execution time of each subtask, set the average as the execution time of the subtask, and save the final execution time of each subtask;

[0056] A2. Obtain the type of each of the subtasks in the total task, and search for a corresponding sliding window according to the type of the subtask, so as to find the execution time corresponding to each of the subtasks.

[0057] Here, the total task can be understood as the task performed by a process, and a process includes multiple threads, and the task on each thread is a subtask.

[0058] For example, a total task has 10 subtasks, and the execution time of each subtask is shown in Table 1:

[0059] Table 1

[0060] Task Name Subtask 1 Subtask 2 Subtask 3 Subtask 4 Subtask 5 Subtask 6 Subtask 7 Subtask 8 Subtask 9 Subtask 10 Execution time 95 20 33 45 85 77 42 80 18 60

[0061] S2. According to the execution time of each subtask in the total task, a time threshold is set, and the number of the subtasks whose execution time is divided by the time threshold is respectively obtained, wherein the subtasks within the same time range are regarded as a subtask group to be executed;

[0062] In some embodiments, a time threshold is set according to the execution time of each subtask in the total task, and the specific process of respectively obtaining the number of subtasks whose execution time is divided by the time threshold is as follows:

[0063] B1. Determine the number of the time thresholds, and let the number of the time thresholds be N;

[0064] In some embodiments, the number of the time threshold is not greater than the number of CPU cores minus 1. Correspondingly, the total number of the fast thread pool and the slow thread pool is not greater than the number of CPU cores.

[0065] For example, if the CPU of the server used by the platform system is dual-core (two cores), then there is only one time threshold. If the CPU of the server used by the platform system is quad-core, then there can be 1-3 time thresholds.

[0066] In order to reduce system efficiency, in this embodiment, the time threshold is equal to the number of CPU cores minus 1. Correspondingly, the total number (sum) of the fast thread pool and the slow thread pool is equal to the number of CPU cores.

[0067] B2. Sort each subtask in the total task according to the corresponding execution time to obtain a subtask sequence in ascending or descending order according to the execution time;

[0068] For example, the data in Table 1 is sorted in descending order according to the execution time to obtain the subtask sequence table 2:

[0069] Table 2

[0070] Task Name Subtask 1 Subtask 5 Subtask 8 Subtask 6 Subtask 10 Subtask 4 Subtask 7 Subtask 3 Subtask 2 Subtask 9 Execution time 95 85 80 77 60 45 42 33 20 18

[0071] B3. Determine the total execution time T of the total task, and divide the total execution time T by N+1 to obtain the time average value P, that is, ;

[0072] Specifically, , is the execution time of the ith subtask, T is the total execution time, and I is the total number of subtasks.

[0073] For example, for a dual-core CPU, N=1, then, .

[0074] If it is a quad-core CPU, N=3, then, .

[0075] B4, arranging the execution times corresponding to the subtask sequences in order to obtain an execution time sequence, and finding the execution time combination closest to the time average value P from the execution time sequence, thereby dividing the execution time sequence obtained by arranging the execution times corresponding to the subtask sequences in order into N+1 groups of subtask groups to be executed;

[0076] For example, if it is a dual-core CPU, as shown in Table 2, the execution time combination of the to-be-executed time group in order is close to 277.5, then the execution time corresponding to subtask 1, subtask 5, and subtask 8 is divided into one to-be-executed time group, and the to-be-executed time group is called to-be-executed time group A, and subtask 6, subtask 10, subtask 4, subtask 7, subtask 3, subtask 2, and subtask 9 are divided into another to-be-executed time group, and the to-be-executed time group is called to-be-executed time group B.

[0077] For example, if it is a quad-core CPU, as shown in Table 2, the execution time combination of the to-be-executed time group is close to 138.75. Then, the execution time corresponding to subtask 1 and subtask 5 is divided into a to-be-executed time group, defined as to-be-executed time group I, the execution time corresponding to subtask 8 and subtask 6 is divided into a to-be-executed time group, defined as to-be-executed time group II, the execution time corresponding to subtask 10 and subtask 4 is divided into a to-be-executed time group, defined as to-be-executed time group III, and the execution time corresponding to subtask 7, subtask 3, subtask 2, and subtask 9 is divided into a to-be-executed time group, defined as to-be-executed time group IV.

[0078] Sequentially searching for the execution time combination closest to the time average value P can be obtained through multiple calculations, which will not be repeated here.

[0079] Of course, classification can also be obtained by learning a neural network model, so that the best combination of time groups to be executed can be obtained more quickly.

[0080] For example, find some training sets, which include the input and output of the learning neural network model. The input is the execution time of each subtask and the number of CPU cores, and the output is the classified execution time group. After multiple trainings, the learning neural network model is trained until the loss function of the learning neural network model converges. That is, the execution time of each subtask and the number of CPU cores are input into the learning neural network model, and the classified execution time group is used as the output of the learning neural network model. The classified execution time group in the training set can be obtained by the following calculation:

[0081] Find a combination of to-be-executed time groups of an execution time series, in which the sum of the absolute values ​​of the differences between the time in each to-be-executed time group and the time average value P is the smallest. This is the best combination.

[0082] That is, if a descending execution time series There are three combinations. The execution time series is a sorted time series. Each combination consists of three waiting time groups. The three combinations are:

[0083] one,

[0084] two,

[0085] three,

[0086] (*) indicates a time group to be executed.

[0087] If the sum of the absolute values ​​of the differences between the first case and the time average value P is 36, the sum of the absolute values ​​of the differences between the second case and the time average value P is 47, and the sum of the absolute values ​​of the differences between the third case and the time average value P is 34, then the combination of the third case is the best combination, and the combination of the third case is defined as the output of the learning neural network model.

[0088] The absolute value of the difference between the time in the to-be-executed time group and the time average value P can be expressed as:

[0089] , is the execution time in the time group to be executed, and J is the number of time groups to be executed.

[0090] , which is expressed as the sum of the absolute values ​​of the differences between the time in the J to-be-executed time groups into which an execution time series is divided and the time average value P.

[0091] B5. Define the subtasks corresponding to the N+1 execution time groups as to-be-executed subtask groups, and confirm the number of subtasks in each of the to-be-executed subtask groups;

[0092] B6. Let any number between the execution times corresponding to two adjacent subtasks in two adjacent groups of subtasks to be executed and in an adjacent relationship between the two adjacent groups of subtasks to be executed be the time threshold.

[0093] For example, the combination of the third case To be the best combination, the two time thresholds are respectively set between c and d and between g and h.

[0094] If c is 50 and d is 40, then the first time threshold can be 41-49. For example, if g is 30 and h is 28, then the second time threshold can be 29. Of course, the time threshold can also be a floating point number, that is, a decimal.

[0095] In some embodiments, if there are at least two identical execution times in the execution time sequence, different random numbers are added to any one or more of the identical execution times to form new execution times so that the new execution times are all different, and the new execution times are reordered to form a new execution time sequence and divided into time groups to be executed, wherein the position of the new execution time in the new execution time sequence is consistent with the position of the execution times that constitute the new execution time in the original execution time sequence.

[0096] This step is mainly to avoid unclear division of the time groups to be executed. Therefore, in order to better divide the time groups to be executed, if there are several subtasks with the same execution time, when the execution time sequence is initially formed, the order of these subtasks can be randomly arranged in the execution time sequence (that is, the order between these subtasks can change, but the combination of these subtasks in the execution time sequence is unchanged). That is, if the execution time sequence In the example, c and d are the same, then the execution time series can also be expressed as .

[0097] Adding different random numbers to any one or more identical execution times to form new execution times makes the new execution times different. This means that if the initial execution time sequence If c and d are the same, then add different random numbers to c and d to get and ,in, , , rand represents a random number.

[0098] Since c and d are the same, It can also be understood as ,at this time It can also be understood as .

[0099] The position of the new execution time in the new execution time sequence is consistent with the position of the execution times constituting the new execution time in the original execution time sequence.

[0100] This sentence means: Due to the above two situations, therefore, and The position of c and d in the new execution time sequence must be consistent with the position of c and d in the original execution time sequence, or and The position of the new execution time sequence must be consistent with the position of d and c in the original execution time sequence. That is to say, there are two situations in which the new execution time sequence is obtained, one of which is: , another case is , as for The order between them is related to the random number. If they are sorted in descending order, , then the new execution time series is the first case, if , then the new execution time sequence is the second case. However, the execution time with the random number added will not exceed the value of the adjacent execution time that is greater than the execution time.

[0101] S3, establishing a fast thread pool and a slow thread pool according to the execution subtask group, and setting the sizes of the fast thread pool and the slow thread pool according to the number of subtasks in each of the execution subtask groups, and the fast thread pool and the slow thread pool are processed by different CPU cores respectively;

[0102] Here, the fast thread pool and slow thread pool are just name definitions. If there is only one time threshold, then subtasks above the time threshold are assigned to the slow thread pool, and subtasks below the time threshold are assigned to the fast thread pool.

[0103] In some embodiments, the number of the fast thread pool and the slow thread pool are determined according to the number of groups of the to-be-executed subtask groups, and the number of core threads in the fast thread pool and the slow thread pool are determined according to the number of subtasks in the to-be-executed subtask groups.

[0104] In this embodiment, the time threshold = the number of CPU cores - 1, then the number of groups of subtasks to be executed is the same as the number of CPU cores, and the total number of fast thread pools and slow thread pools is the same as the number of groups of subtasks to be executed.

[0105] S4, placing the subtasks whose execution time is less than the time threshold in the fast thread pool, and placing the subtasks whose execution time is not less than the time threshold in the slow thread pool;

[0106] If three pending time groups The corresponding subtask groups to be executed are Then, we can define two fast thread pools and one slow thread pool. Assigned to the slow thread pool, , Assigned to two fast thread pools respectively.

[0107] The number of threads in the slow thread pool is 1, that is, the size of the slow thread pool is 1.

[0108] The number of threads in the two fast thread pools is 4 and 4 respectively, that is, the size of the two fast thread pools is 4.

[0109] S5. The CPU core processes threads in the fast thread pool or the slow thread pool accordingly.

[0110] As shown in the above example, three CPU cores process threads in three thread pools respectively.

[0111] Embodiment 2 further discloses a thread scheduling system, which is used to execute a thread scheduling method of embodiment 1, including:

[0112] The acquisition module is used to obtain the execution time of each subtask in each total task;

[0113] A grouping module, used to formulate a time threshold according to the execution time of each subtask in the total task, and respectively obtain the number of the subtasks whose execution time is divided by the time threshold, wherein the subtasks within the same time range are regarded as a subtask group to be executed;

[0114] A thread pool creation module, used to establish a fast thread pool and a slow thread pool according to the execution subtask group, and set the size of the fast thread pool and the slow thread pool according to the number of subtasks in each of the execution subtask groups, and the fast thread pool and the slow thread pool are processed by different CPU cores respectively;

[0115] A placement module, used to place the subtasks whose execution time is less than the time threshold in the fast thread pool, and place the subtasks whose execution time is not less than the time threshold in the slow thread pool;

[0116] An execution module is used for the CPU core to process threads in the fast thread pool or the slow thread pool accordingly.

[0117] Example 3 also discloses an electronic device, comprising at least one processor, and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute a thread scheduling method as described in Example 1.

[0118] Embodiment 4 further discloses a storage medium storing a computer program, wherein the computer program implements a thread scheduling method of embodiment 1 when executed by a processor.

[0119] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A thread scheduling method, implemented on a multi-core CPU, characterized in that: include: Get the execution time of each subtask in each total task; A time threshold is set according to the execution time of each subtask in the total task, and the number of the subtasks whose execution time is divided by the time threshold is respectively obtained, wherein the subtasks in the same time range are regarded as a subtask group to be executed, and the number of the time threshold is not greater than the number of CPU cores - 1; The specific process of formulating a time threshold according to the execution time of each subtask in the total task and respectively obtaining the number of subtasks whose execution time is divided by the time threshold is as follows: B1. Determine the number of the time thresholds, and let the number of the time thresholds be N; B2. Sort each subtask in the total task according to the corresponding execution time to obtain a subtask sequence in ascending or descending order according to the execution time; B3. Determine the total execution time T of the total task, and divide the total execution time T by N+1 to obtain the time average value P, that is, t i is the execution time of the ith subtask, T is the total execution time, and I is the total number of subtasks; B4, arranging the execution times corresponding to the subtask sequences in order to obtain an execution time sequence, and finding the execution time combination closest to the time average value P from the execution time sequence, thereby dividing the execution time sequence obtained by arranging the execution times corresponding to the subtask sequences in order into N+1 groups of subtask groups to be executed; B5. Define the subtasks corresponding to the N+1 execution time groups as to-be-executed subtask groups, and confirm the number of subtasks in each of the to-be-executed subtask groups; B6. Let any number between the execution times corresponding to two adjacent subtasks in two adjacent subtask groups to be executed and in an adjacent relationship in the two adjacent subtask groups to be executed be the time threshold; A fast thread pool and a slow thread pool are established according to the execution subtask groups, and the sizes of the fast thread pool and the slow thread pool are set according to the number of subtasks in each of the execution subtask groups, and the fast thread pool and the slow thread pool are processed by different CPU cores respectively; The subtasks whose execution time is less than the time threshold are placed in the fast thread pool, and the subtasks whose execution time is not less than the time threshold are placed in the slow thread pool; The CPU core processes threads in the fast thread pool or the slow thread pool accordingly.

2. A thread scheduling method according to claim 1, characterized in that: The specific process of obtaining the execution time of each subtask in each total task is: A1. Use the SlidingWindow class to record the most recent N execution times of each subtask, and calculate the average execution time of each subtask, set the average as the execution time of the subtask, and save the final execution time of each subtask; A2. Obtain the type of each of the subtasks in the total task, and search for a corresponding sliding window according to the type of the subtask, so as to find the execution time corresponding to each of the subtasks.

3. A thread scheduling method according to claim 1, characterized in that: The total number of the fast thread pool and the slow thread pool is not greater than the number of cores of the CPU.

4. A thread scheduling method according to claim 1, characterized in that: The number of the fast thread pool and the slow thread pool are determined according to the number of groups of the to-be-executed subtask groups, and the number of core threads in the fast thread pool and the slow thread pool are determined according to the number of subtasks in the to-be-executed subtask groups.

5. A thread scheduling method according to claim 1, characterized in that: If there are at least two identical execution times in the execution time sequence, different random numbers are added to any one or more of the identical execution times to form new execution times so that the new execution times are all different, and the new execution times are reordered to form a new execution time sequence and divided into time groups to be executed, wherein the position of the new execution time in the new execution time sequence is consistent with the position of the execution times that constitute the new execution time in the original execution time sequence.

6. A thread scheduling system, used to execute a thread scheduling method according to any one of claims 1 to 5, characterized in that: include: The acquisition module is used to obtain the execution time of each subtask in each total task; A grouping module, used to formulate a time threshold according to the execution time of each subtask in the total task, and respectively obtain the number of the subtasks whose execution time is divided by the time threshold, wherein the subtasks within the same time range are regarded as a subtask group to be executed, and the number of the time threshold is not greater than the number of CPU cores - 1; The specific process of formulating a time threshold according to the execution time of each subtask in the total task and respectively obtaining the number of subtasks whose execution time is divided by the time threshold is as follows: B1. Determine the number of the time thresholds, and let the number of the time thresholds be N; B2. Sort each subtask in the total task according to the corresponding execution time to obtain a subtask sequence in ascending or descending order according to the execution time; B3. Determine the total execution time T of the total task, and divide the total execution time T by N+1 to obtain the time average value P, that is, t i is the execution time of the ith subtask, T is the total execution time, and I is the total number of subtasks; B4, arranging the execution times corresponding to the subtask sequences in order to obtain an execution time sequence, and finding the execution time combination closest to the time average value P from the execution time sequence, thereby dividing the execution time sequence obtained by arranging the execution times corresponding to the subtask sequences in order into N+1 groups of subtask groups to be executed; B5. Define the subtasks corresponding to the N+1 execution time groups as to-be-executed subtask groups, and confirm the number of subtasks in each of the to-be-executed subtask groups; B6. Let any number between the execution times corresponding to two adjacent subtasks in two adjacent subtask groups to be executed and in an adjacent relationship in the two adjacent subtask groups to be executed be the time threshold; A thread pool creation module, used to establish a fast thread pool and a slow thread pool according to the execution subtask group, and set the size of the fast thread pool and the slow thread pool according to the number of subtasks in each of the execution subtask groups, and the fast thread pool and the slow thread pool are processed by different CPU cores respectively; A placement module, used to place the subtasks whose execution time is less than the time threshold in the fast thread pool, and place the subtasks whose execution time is not less than the time threshold in the slow thread pool; An execution module is used for the CPU core to process threads in the fast thread pool or the slow thread pool accordingly.

7. An electronic device, characterized in that: It includes at least one processor and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute a thread scheduling method as described in any one of claims 1 to 5.

8. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, a thread scheduling method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Task processing method, device and system

    CN107766129A

  • Task scheduling method and device, equipment and storage medium

    CN113535361A