A task processing method, device, equipment and storage medium

By selecting appropriate thread processing time-strong-quantity related tasks from the thread pool in advance based on the historical task volume of the task category in the business system, the problems of waste of resources and slow processing speed in the existing technology are solved, and efficient task processing is achieved.

CN114661476BActive Publication Date: 2025-04-18BEIJING KINGSOFT DIGITAL ENTERTAINMENT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210340544.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-31
Publication Date
2025-04-18
Estimated Expiration
2042-03-31

AI Technical Summary

Technical Problem

When processing time-intensive related tasks in a business system, it is difficult for the prior art to improve task processing speed while saving system resources, and the thread pool switching method leads to resource waste.

Method used

By obtaining the pending target task, select thread processing tasks that meet the requirements of the specified time period from the pre-selected thread pool according to the target category to which it belongs, avoiding the creation of a new thread pool.

Benefits of technology

It realizes the improvement of task processing speed while saving system resources, and avoids resource waste and overhead caused by thread pool switching.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114661476B_ABST
    Figure CN114661476B_ABST
Patent Text Reader

Abstract

The embodiments of the present invention provide a task processing method, apparatus, device and storage medium, which relate to the field of computer technology, and in particular to the field of task processing technology. The specific implementation scheme is: obtaining a target task to be processed; wherein the target task belongs to a target category; if the target task is a task generated within a specified time period, then selecting a thread from at least one thread corresponding to the target category; wherein at least one thread corresponding to each task category is pre-selected from at least one thread pool, and the number of threads meets the task volume processing requirements of the task category under the specified time period; calling the selected thread to process the target task. It can be seen that through this scheme, the task processing speed can be improved while saving system resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, in particular to the field of task processing technology, and specifically to a task processing method, device, equipment and storage medium. Background Art

[0002] When there are multiple types of tasks to be processed in a business system, the corresponding thread pool can be set according to the characteristics of each type of task, so that the corresponding type of task can be processed by the threads in each thread pool. For example, the number of core threads, total number of threads, type and length of waiting queues, and other parameters of the thread pool can be set according to the TPS (Transaction Per Second) and hardware capabilities required for each type of task.

[0003] When using a thread pool to process tasks that are strongly time-volume-related, since the parameters of the thread pool are usually immutable after creation, the processing speed is slow when the task volume is large, and the threads are idle for a long time when the task volume is small. In addition, for the entire business system, there may be a time when some threads in the thread pool are idle while the waiting queues of other thread pools are backlogged, resulting in low processing efficiency of the business system. Among them, time-volume-strongly-related tasks are tasks that have a very strong correlation between task volume and time.

[0004] In the related art, for tasks with a strong correlation between time and quantity, the task processing speed is generally improved by switching thread pools. For example, in a period of time when the task volume is very large, a thread pool suitable for processing a large number of tasks is created to receive and process tasks. At the same time, the previous thread pool stops receiving new tasks and is destroyed when all tasks are processed.

[0005] However, the method of switching thread pools will cause the number of thread pools working at the same time to double during the switching process, resulting in a waste of system resources. Therefore, a task processing method that improves the task processing speed while saving system resources is urgently needed. Summary of the invention

[0006] The purpose of the embodiments of the present invention is to provide a task processing method, device, equipment and storage medium to improve the task processing speed while saving system resources. The specific technical solution is as follows:

[0007] In a first aspect, an embodiment of the present invention provides a task processing method, the method comprising:

[0008] Obtaining a target task to be processed; wherein the target task belongs to a target category;

[0009] If the target task is a task generated within a specified time period, a thread is selected from at least one thread corresponding to the target category; wherein the at least one thread corresponding to each task category is pre-selected from at least one thread pool, and the number of threads meets the task volume processing requirement of the task category within the specified time period;

[0010] The selected thread is called to process the target task.

[0011] Optionally, the method further comprises:

[0012] If the target task is a task generated in a time period other than the specified time period, determining a thread pool pre-allocated for the target category;

[0013] An idle thread in the determined thread pool is called to process the target task.

[0014] Optionally, a method for determining at least one thread corresponding to each task category includes:

[0015] Determine the specified characterization information of each task category in the historical time period; wherein the historical time period is a time period matching the specified time period, and the specified characterization information is used to characterize the task volume;

[0016] At least one thread corresponding to each task category is determined based on the specified characterization information of each task category in the historical time period.

[0017] Optionally, determining at least one thread corresponding to each task category based on the specified characterization information of each task category in the historical time period includes:

[0018] Determine the thread call rate of each task category for the total number of threads by using the specified characterization information of each task category in the historical time period; wherein the total number of threads is the sum of the number of threads in each thread pool;

[0019] For each task category, at least one thread is selected from at least one thread pool of each thread pool according to the thread call rate of the task category to the total number of threads, to obtain at least one thread corresponding to the task category.

[0020] Optionally, the specified characterization information includes the number of tasks;

[0021] The method of using the specified characterization information of each task category in the historical time period to determine the thread call rate of each task category with respect to the total number of threads includes:

[0022] For each task category, determine the ratio of the number of tasks of the task category in the historical time period to the total amount of tasks, and determine the thread call rate of the task category based on the determined ratio;

[0023] The total task volume is the sum of the number of tasks of each task category in the historical time period.

[0024] Optionally, determining the thread call rate of the task category based on the determined ratio includes:

[0025] The determined ratio is used as the thread call rate of the task category.

[0026] Optionally, determining the thread call rate of the task category based on the determined ratio includes:

[0027] Based on the determined ratio, and the task execution time and / or task priority of the task category, a thread call rate of the task category is determined.

[0028] In a second aspect, an embodiment of the present invention provides a task processing device, the device comprising:

[0029] An acquisition module, used for acquiring a target task to be processed; wherein the target task belongs to a target category;

[0030] A selection module, configured to select a thread from at least one thread corresponding to the target category if the target task is a task generated within a specified time period; wherein the at least one thread corresponding to each task category is pre-selected from at least one thread pool, and the number of threads meets the task volume processing requirement of the task category within the specified time period;

[0031] The processing module is used to call the selected thread to process the target task.

[0032] Optionally, the device further comprises:

[0033] a determination module, configured to determine a thread pool pre-allocated to the target category if the target task is a task generated in a time period other than a specified time period;

[0034] The calling module is used to call an idle thread in the determined thread pool to process the target task.

[0035] Optionally, a method for determining at least one thread corresponding to each task category includes:

[0036] Determine the specified characterization information of each task category in the historical time period; wherein the historical time period is a time period matching the specified time period, and the specified characterization information is used to characterize the task volume;

[0037] At least one thread corresponding to each task category is determined based on the specified characterization information of each task category in the historical time period.

[0038] Optionally, determining at least one thread corresponding to each task category based on the specified characterization information of each task category in the historical time period includes:

[0039] Determine the thread call rate of each task category for the total number of threads using the specified characterization information of each task category in the historical time period, where the total number of threads is the sum of the number of threads in each thread pool;

[0040] For each task category, at least one thread is selected from at least one thread pool of each thread pool according to the thread call rate of the task category to the total number of threads, to obtain at least one thread corresponding to the task category.

[0041] Optionally, the specified characterization information includes the number of tasks;

[0042] The method of using the specified characterization information of each task category in the historical time period to determine the thread call rate of each task category with respect to the total number of threads includes:

[0043] For each task category, determine the ratio of the number of tasks of the task category in the historical time period to the total amount of tasks, and determine the thread call rate of the task category based on the determined ratio;

[0044] The total task volume is the sum of the number of tasks of each task category in the historical time period.

[0045] Optionally, determining the thread call rate of the task category based on the determined ratio includes:

[0046] The determined ratio is used as the thread call rate of the task category.

[0047] Optionally, determining the thread call rate of the task category based on the determined ratio includes:

[0048] Based on the determined ratio, and the task execution time and / or task priority of the task category, a thread call rate of the task category is determined.

[0049] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0050] Memory, used to store computer programs;

[0051] The processor is used to implement the steps of any of the above-mentioned task processing methods when executing the program stored in the memory.

[0052] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned task processing methods are implemented.

[0053] Beneficial effects of the embodiments of the present invention:

[0054] The solution provided by the embodiment of the present invention, after obtaining the target task to be processed, selects a thread from at least one thread corresponding to the target category to process the target task according to the target category to which the target task belongs. Since at least one thread corresponding to each task category is selected in advance from at least one thread pool, and the number of threads meets the task volume processing requirements of the task category in the specified time period, that is, the corresponding processing resources are flexibly allocated to each task category in advance according to the task volume processing requirements of each task category in the specified time period, therefore, it can be ensured that the tasks under each task category within the specified time period can be processed promptly and quickly. It can be seen that compared with the method of switching thread pools in the prior art, this solution can improve the task processing speed by making full use of the threads of the existing thread pool, without the need to create a new thread pool. Therefore, through this solution, the task processing speed can be improved under the premise of saving system resources.

[0055] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can also be obtained based on these drawings.

[0057] Figure 1 A flowchart of a task processing method provided by an embodiment of the present invention;

[0058] Figure 2 Another flow chart of the task processing method provided by an embodiment of the present invention;

[0059] Figure 3 A schematic diagram of a thread pool provided by an embodiment of the present invention;

[0060] Figure 4 A schematic diagram of a monitoring thread pool provided by an embodiment of the present invention;

[0061] Figure 5 A schematic diagram of thread pool allocation provided by an embodiment of the present invention;

[0062] Figure 6 A schematic diagram of the structure of a task processing device provided by an embodiment of the present invention;

[0063] Figure 7 A schematic diagram of the structure of an electronic device for implementing the task processing method provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0064] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field based on this application belong to the scope of protection of the present invention.

[0065] Below, the professional terms involved in the embodiments of the present invention are first introduced:

[0066] Strong time-volume correlation: refers to the strong correlation between the volume of a task and time. For example, the number of tasks such as online ordering during the Double 11 event is significantly higher than that during other time periods. Another example is that the volume of backlogged trading tasks in the stock market reaches a peak between 9:30 and 10:00.

[0067] Autocorrelation analysis: Autocorrelation refers to the degree of correlation between the values ​​of the same time series at different times. Autocorrelation analysis is used to analyze whether the data is related to time.

[0068] P value: A parameter used to determine the results of a hypothesis test. It can also be compared using the rejection region of a distribution according to different distributions. If the P value is smaller than the selected significance level (e.g. 0.05), the null hypothesis will be rejected and unacceptable. Among them, the set of all possible values ​​of the test statistic that can reject the null hypothesis is called the rejection region; the null hypothesis, also known as the original hypothesis, refers to the hypothesis established in advance when conducting a statistical test.

[0069] When there are multiple types of tasks that need to be processed in a business system, developers can create corresponding thread pools for each type of task based on the characteristics of each type of task, and one thread pool is used to process one type of task. When creating a thread pool, you can set parameters such as the number of core threads, the total number of threads, the type and length of the waiting queue for the thread pool based on the TPS required for each type of task and the hardware capabilities of the system. Exemplarily, the multiple types of tasks here can be multiple types of asynchronous tasks, which refer to multiple types of tasks that do not affect each other during execution. For example, the multiple types of tasks can be: submission tasks, review tasks, and so on for text annotation projects.

[0070] When the thread pool is created, these parameters are usually unchangeable except when the thread expires and is recycled by the system. When using the created thread pool to process tasks that are strongly time-volume-related, some threads in the thread pool will be idle during periods of low task volume; and during periods of high task volume, there will not be enough threads in the thread pool, resulting in slow task processing. Moreover, for the system as a whole, in the same period of time, there may be some threads in the thread pool that are idle, while the waiting queues of tasks to be processed in other thread pools are backlogged, resulting in inefficient thread usage for the entire system. It is understandable that when the task volume is large, if some threads in the thread pool are recycled by the system due to expiration, it will undoubtedly lead to slower task processing.

[0071] In the related art, for tasks that are strongly time-volume-dependent, the task processing speed is generally increased by switching thread pools. For example, during a period of time when there are a lot of tasks, a thread pool suitable for processing a large number of tasks is created to receive and process tasks. At the same time, the previous thread pool stops receiving new tasks and is destroyed when all tasks are processed.

[0072] However, the method of switching thread pools will lead to the following disadvantages during the switching process: during the switching process, the number of thread pools working at the same time will double, resulting in a waste of system resources; when threads are opened and destroyed, the system expenses will increase; if the old thread pool cannot be destroyed in time, the number of thread pools working at the same time will double for too long, further wasting system resources.

[0073] Based on the above content, in order to improve the task processing speed while saving system resources, the embodiments of the present invention provide a task processing method, apparatus, device and storage medium.

[0074] Below, a task processing method provided by an embodiment of the present invention is first introduced.

[0075] A task processing method provided in an embodiment of the present invention can be applied to an electronic device. In a specific application, the electronic device can be a server or a terminal device, which is reasonable. In a practical application, the terminal device can be a tablet computer, a desktop computer, etc.

[0076] Specifically, the execution subject of the task processing method may be a task processing device. Exemplarily, when the task processing method is applied to a terminal device, the task processing device may be an application program running in the terminal device for processing tasks, such as a multi-threaded application program. Exemplarily, when the task processing method is applied to a server, the task processing device may be a computer program running in the server, and the computer program may be used to process the task to be processed.

[0077] The task processing method provided by the embodiment of the present invention may include the following steps:

[0078] Obtaining a target task to be processed; wherein the target task belongs to a target category;

[0079] If the target task is a task generated within a specified time period, a thread is selected from at least one thread corresponding to the target category; wherein the at least one thread corresponding to each task category is pre-selected from at least one thread pool, and the number of threads meets the task volume processing requirement of the task category within the specified time period;

[0080] The selected thread is called to process the target task.

[0081] The solution provided in this embodiment, after obtaining the target task to be processed, selects a thread from at least one thread corresponding to the target category to process the target task according to the target category to which the target task belongs. Since at least one thread corresponding to each task category is selected in advance from at least one thread pool, and the number of threads meets the task volume processing requirements of the task category in the specified time period, that is, the corresponding processing resources are flexibly allocated to each task category in advance according to the task volume processing requirements of each task category in the specified time period, so it can be ensured that the tasks under each task category in the specified time period can be processed promptly and quickly. It can be seen that compared with the method of switching thread pools in the prior art, this solution can improve the task processing speed by making full use of the threads of the existing thread pool, without the need to create a new thread pool. Therefore, through this solution, the task processing speed can be improved under the premise of saving system resources.

[0082] The task processing method provided by the embodiment of the present invention is introduced below with reference to the accompanying drawings.

[0083] like Figure 1 As shown, the task processing method provided by the embodiment of the present invention may include steps S101-S103:

[0084] S101, obtaining a target task to be processed; wherein the target task belongs to a target category;

[0085] Exemplarily, the target task may be a task received from a task generation terminal. Exemplarily, for a business system of a text annotation project, the target task may be a submission task for text annotation, or a review task, etc. Correspondingly, the category of the target task may be a submission category, or a review category, etc. Exemplarily, for a business system of online shopping, the target task may be an online ordering task, a shipping task, etc. Correspondingly, the task category of the target task may be an online ordering category, a shipping category, etc.

[0086] S102, if the target task is a task generated within a specified time period, selecting a thread from at least one thread corresponding to the target category; wherein the at least one thread corresponding to each task category is pre-selected from at least one thread pool, and the number of threads meets the task volume processing requirement of the task category within the specified time period;

[0087] It can be understood that since at least one thread corresponding to the target category is a thread used to process the tasks of the target category and meets the task volume processing requirements of the target category in the time period, therefore, within the specified time period, the at least one thread corresponding to the target category can meet the processing requirements of each task of the target category. At this time, a thread can be selected from the at least one thread corresponding to the target category to process the target task.

[0088] Exemplarily, a management thread can be set up to manage tasks of each task category. The management thread is used to maintain task queues of different task categories and can monitor the thread status of each thread in each thread pool. When the business system receives a task belonging to any task category, the task can first enter the task queue belonging to the task category managed by the management thread. Then, the management thread takes the task out of the task queue according to the first-in-first-out principle, selects a thread from at least one thread corresponding to the task category to which the task belongs, and distributes the task to the selected thread.

[0089] It should be noted that when a task in the task queue is taken out and distributed to the selected thread, if the state of the selected thread is idle, the selected thread is used to process the task. If the state of the selected thread is occupied, the task is distributed to the waiting queue of the thread pool corresponding to the selected thread.

[0090] In the present embodiment, the specified time period may be a time period when the amount of tasks belonging to the target category suddenly increases, or a time period when the amount of tasks belonging to other task categories suddenly increases. It is understandable that outside the specified time period, that is, when the amount of tasks of each task category processed in the system is within the normal range, the threads in the thread pool pre-set for each task category can be used to process the tasks of each task category. Within the specified time period, that is, when the amount of tasks of any task category suddenly increases, the threads in the thread pool corresponding to the task category will not be able to meet the processing requirements of the suddenly increased amount of tasks. In order to improve the task processing speed of the task category, the threads in the thread pool can be reallocated according to all thread pools pre-set in the system and the amount of tasks of each task category. At this time, at least one thread corresponding to each task category may include a thread selected from a thread pool pre-set for the task category, and / or a thread called from a thread pool pre-set for other types of tasks.

[0091] Exemplarily, a method of selecting a thread from at least one thread corresponding to any task category may be to number at least one thread corresponding to the task category, and then determine a thread selected for the target task by using a circular linked list or counting modulo method according to the number of each thread. For example: if at least one thread corresponding to a task of class A includes two threads numbered 1 and 2 in the A thread pool, and a thread numbered 3 in the B thread pool. When distributing tasks belonging to the A task category to the selected threads, a circular linked list may be used to record the distributed tasks, that is, to loop in the order of numbers 1, 2, and 3. If the thread numbered 1 was distributed last time, the task should be distributed to the thread numbered 2 this time. Alternatively, the distributed tasks may be counted by counting modulo method. For example, this is the fifth distribution of tasks belonging to the A task category, and 5 modulo 3 is 2, so the task is distributed to the thread numbered 2 this time.

[0092] In addition, the method for determining the designated time period may be to perform autocorrelation analysis on the task category based on the task volume at each historical moment of each task category to determine whether the task category is a task category with strong time-volume correlation, and if so, determine the time period that matches the time period with a large task volume as the designated time period. Of course, the method for determining the designated time period may also be other statistical analysis methods, and the embodiment of the present invention does not limit the method for determining the designated time period.

[0093] S103, calling the selected thread to process the target task.

[0094] In this embodiment, after the thread is selected in step S102, the state of the thread can be monitored. If the thread is an idle thread, the thread can be used to process the target task. It can be understood that since the idle thread selected in step S102 is a thread selected from at least one thread pre-set for the target category, and the at least one thread is at least one thread that meets the processing requirements of each task of the target category, therefore, using a thread in the at least one thread to process the target task can enable the target task to be processed in a timely manner, thereby improving the task processing speed.

[0095] The solution provided by the embodiment of the present invention, after obtaining the target task to be processed, selects a thread from at least one thread corresponding to the target category to process the target task according to the target category to which the target task belongs. Since at least one thread corresponding to each task category is selected in advance from at least one thread pool, and the number of threads meets the task volume processing requirements of the task category in the specified time period, that is, the corresponding processing resources are flexibly allocated to each task category in advance according to the task volume processing requirements of each task category in the specified time period, therefore, it can be ensured that the tasks under each task category in the specified time period can be processed promptly and quickly. It can be seen that compared with the method of switching thread pools in the prior art, this solution can improve the task processing speed by making full use of the threads of the existing thread pool, without the need to create a new thread pool. Therefore, through this solution, the task processing speed can be improved under the premise of saving system resources.

[0096] Optionally, in another embodiment of the present invention, the method for determining at least one thread corresponding to each task category may include steps A1-A2:

[0097] A1, determining the designated characterization information of each task category in a historical time period; wherein the historical time period is a time period matching the designated time period, and the designated characterization information is used to characterize the task volume;

[0098] A2: determining at least one thread corresponding to each task category based on designated characterization information of each task category in a historical time period.

[0099] Exemplarily, the specified characterization information may be the number of tasks, or the frequency level of tasks, etc. Exemplarily, the specified characterization information may be determined based on log information of tasks of different task categories received in a historical time period, or determined by the number of calls to interfaces for processing the different task categories in a historical time period, for example, by obtaining access data of each interface that needs to call an asynchronous processing task, and determining the number of tasks through the access data.

[0100] In this embodiment, the historical time period is a time period that matches the specified time period, that is, a historical time period of a burst of tasks belonging to any task category. Exemplarily, if one of the multiple task categories of the same business system is a securities trading category, by analyzing the specified characterization information of each historical time period of the task category, it can be known that 9:30 to 10:00 in the morning is the time period of a burst of tasks of the task category. At this time, 9:30 to 10:00 in the afternoon can be determined as the specified time period, and 9:30 to 10:00 in the morning of any day before the current time can be used as the historical time period. Exemplarily, if one of the multiple task categories of the same business system is an online order category, by analyzing the specified characterization information of each historical time period of the task category, it can be known that during the Double Eleven event, that is, November 11th of each year is the time period of a burst of tasks of the category, at this time, 0:00 to 24:00 on November 11th can be determined as the specified time period, and 0:00 to 24:00 on November 11th of any year before the current time can be used as the historical time period. Among them, the so-called current time here is the time of executing the determination process of at least one thread corresponding to each task category.

[0101] It is understandable that after analyzing the historical time period in which the burst of task volume of each task category is obtained, in order to efficiently process the burst of task volume within the specified time period matching the historical time period, the specified characterization information of each task category in the historical time period can be analyzed, so that at least one thread corresponding to each task category in the specified time period can be allocated to each task category according to the specified characterization information of each task category in the historical time period matching the specified time period. That is, firstly, by determining the specified characterization information of each task category in the historical time period, then, based on the specified characterization information of each task category in the historical time period, at least one thread corresponding to each task category in the specified time period is determined.

[0102] Exemplarily, a method for determining at least one thread corresponding to each task category based on the specified characterization information of each task category in a historical time period may be to determine at least one thread for the task category based on the ratio of the number of tasks belonging to each task category in the historical time period to the total amount of tasks, or to determine at least one thread for the task category based on the task frequency level of each task category in the historical time period, wherein the higher the task frequency level of the task category, the more threads are allocated.

[0103] It can be seen that through this solution, based on the specified characterization information of each task category in the historical time period matching the specified time period, at least one thread corresponding to each task category is determined. In this way, threads can be effectively allocated in advance for each task category in the specified time period according to the task processing requirements of each task category in the historical time period. Therefore, subsequently in the specified time period, tasks of each task category can be processed according to the at least one thread determined in advance for each task category, so as to improve thread utilization efficiency.

[0104] Optionally, in another embodiment of the present invention, determining at least one thread corresponding to each task category based on the specified characterization information of each task category in the historical time period may include steps B1-B2:

[0105] B1, using the specified characterization information of each task category in the historical time period, determine the thread call rate of each task category for the total number of threads; wherein the total number of threads is the sum of the number of threads in each thread pool;

[0106] In this embodiment, a thread pool is pre-set for each task category in the business system. The thread pool corresponding to each task category has a certain number of threads, and the sum of the number of threads in all thread pools is the total number of threads. The thread call rate of each task category for the total number of threads is the ratio of the number of at least one thread corresponding to each task category to the total number of threads.

[0107] It can be understood that in order to process the demand according to the task volume of each task category within a specified time period and determine at least one thread corresponding to each task category, it is possible to first determine the thread call rate of each task category with respect to the total number of threads, and then determine at least one thread corresponding to each task category based on the thread call rate and the total number of threads.

[0108] Since the specified characterization information is used to characterize the task volume, the task volume processing requirements of each task category within the specified time period can be determined based on the specified characterization information of the historical time period that matches the specified time period. Therefore, the thread call rate of each task category for the total number of threads can be determined by using the specified characterization information of each task category in the historical time period.

[0109] B2, for each task category, according to the thread call rate of the task category to the total number of threads, select at least one thread from at least one thread pool of each thread pool to obtain at least one thread corresponding to the task category.

[0110] It is understandable that after determining the thread call rate of each task category to the total number of threads through step B1, at least one thread can be allocated to each task category according to the thread call rate to obtain at least one thread corresponding to the task category. Exemplarily, for task categories A and B, if the thread call rate corresponding to category A is 0.7, the thread call rate corresponding to category B is 0.3, and the total number of threads is 10, then 7 threads can be selected from each thread pool as threads corresponding to category A, and the other 3 threads as threads corresponding to category B.

[0111] It can be seen that through this solution, the thread call rate of each task category for the total number of threads can be determined based on the specified characterization information of each task category in the historical time period, and then at least one thread corresponding to the task category can be determined based on the thread call rate, so that for each task category, the number of threads that matches the task volume requirements of the specified time period can be quickly and effectively allocated.

[0112] Optionally, in another embodiment of the present invention, the specified characterization information includes the number of tasks;

[0113] Accordingly, in the above step B1, the thread call rate of each task category with respect to the total number of threads is determined by using the designated characterization information of each task category in the historical time period, including:

[0114] For each task category, determine the ratio of the number of tasks of the task category in the historical time period to the total amount of tasks, and determine the thread call rate of the task category based on the determined ratio;

[0115] The total task volume is the sum of the number of tasks in each task category in the historical time period.

[0116] It can be understood that in order to make at least one thread corresponding to each task category within a specified time period be at least one thread that meets the task volume processing requirements of the task category within the specified time period, when using the specified characterization information of the historical time period to determine the thread call rate of each task category for the total number of threads, the thread call rate of the task category can be determined based on the ratio between the task volume of each task category within the historical time period and the sum of the task volumes of each task category.

[0117] In addition, it should be noted that when the designated characterization information is the task frequency level, the thread call rate of each task category can be determined according to the task frequency level of each task category in the historical time period. The higher the task frequency level, the higher the thread call rate. For example, if the frequency levels of tasks A, B, and C are high, medium, and low, respectively, the thread call rates of the three tasks can be allocated in a ratio of 5:3:2.

[0118] Optionally, in one implementation, determining the thread call rate of the task category based on the determined ratio may include:

[0119] The determined ratio is used as the thread call rate of the task category.

[0120] For example, if the number of A-type tasks and B-type tasks generated by the task generation terminal in the historical time period is 700 and 300 respectively, then the ratio between the amount of tasks in the A-type and the total amount of tasks in the historical time period is 0.7, and the ratio between the amount of tasks in the B-type and the total amount of tasks is 0.3. The determined ratio is used to determine the thread call rate of the task category, that is, the thread call rate of the A-type is 0.7, and the thread call rate of the B-type is 0.3.

[0121] Optionally, in another implementation, determining the thread call rate of the task category based on the determined ratio may include:

[0122] Based on the determined ratio, and the task execution time and / or task priority of the task category, a thread call rate of the task category is determined.

[0123] It is understandable that, when determining at least one thread corresponding to each task category, in addition to allocating threads in each thread pool to each task category according to the task amount, the task execution time and / or task priority of each task category can also be comprehensively considered to determine at least one thread corresponding to each task category. Therefore, in this implementation, for any task category, the ratio of the number of tasks of the task category to the total amount of tasks in the historical time period can be used to perform weighted summation on the ratio, task execution time and / or task priority to obtain the thread call rate of the task category. Exemplary, the weighted summation of the ratio, task execution time and / or task priority can be performed by first normalizing the ratio, task execution time and / or task priority, for example, using a softmax function to normalize the ratio, task execution time and / or task priority, and then performing weighted summation on the normalized ratio, task execution time and / or task priority to obtain the thread call of the task category. The weighted sum formula and the weights of each weighted item may be predetermined by relevant technical personnel, and the embodiment of the present invention is not limited thereto.

[0124] In addition, the task execution time of each task category may be the average execution time of the thread processing the tasks of the task category, or the median execution time of the thread processing the task category, etc. The task priority of each task category may be set by relevant technical personnel based on work experience, for example, determined based on the importance of the tasks of each task category.

[0125] It can be seen that through this solution, the thread call rate of each task category is determined according to the ratio of the number of tasks of each task category in the historical time period to the total amount of tasks. The thread call rate can be reasonably determined for each task category according to the number of tasks in each task category, thereby maximizing the thread utilization efficiency.

[0126] Alternatively, in another embodiment of the present invention, Figure 2 As shown, the method includes steps S201-S205:

[0127] S201, obtaining a target task to be processed; wherein the target task belongs to a target category;

[0128] S202, if the target task is a task generated within a specified time period, selecting a thread from at least one thread corresponding to the target category; wherein the at least one thread corresponding to each task category is pre-selected from at least one thread pool, and the number of threads meets the task volume processing requirement of the task category within the specified time period;

[0129] S203, calling the selected thread to process the target task.

[0130] The contents of steps S201-S203 are the same as those of the above steps S101-S103, and are not repeated here.

[0131] S204, if the target task is a task generated in a time period other than the specified time period, determining a thread pool pre-allocated for the target category;

[0132] S205, calling an idle thread in the determined thread pool to process the target task.

[0133] In this embodiment, the time period outside the specified time period is a time period when the task volume of each task category is in a normal state, that is, a time period other than the time period when the task volume of any task category is in a burst. In the time period outside the specified time period, since there is no task burst, the thread pool pre-set for each task category can be used to process the corresponding task using the threads in the thread pool. Therefore, if the target task is a task generated in the time period outside the specified time period, the thread pool pre-assigned for the target category can be determined, and then an idle thread in the determined thread pool can be called to process the target task.

[0134] It can be seen that through this solution, outside the specified time period, by using the threads in the thread pool pre-set for each task category to process the corresponding tasks, the threads in the thread pool can be quickly allocated to each task to be processed.

[0135] In order to better illustrate the content of the embodiment of the present invention, the task processing method provided by the embodiment of the present invention is introduced below with reference to a specific example.

[0136] like Figure 3 As shown, the system is provided with three thread pools, thread pool A', thread pool B', and thread pool C', wherein thread pool A' is used to process asynchronous tasks of category A, thread pool B' is used to process asynchronous tasks of category B, and thread pool C' is used to process asynchronous tasks of category C. The number of threads in each thread pool is 5, Figure 3 The middle circle A represents the thread used to process asynchronous tasks of category A, the circle B represents the thread used to process asynchronous tasks of category B, and the circle C represents the thread used to process asynchronous tasks of category C. Within the specified time period, the processing flow of the target tasks belonging to the target category is as follows:

[0137] (1) Determine the designated time period.

[0138] Since the designated time period is a time period when the amount of tasks belonging to any task category suddenly increases, the designated time period can be determined based on the historical data of each task category. The historical data may include the amount of tasks of the task category at each historical moment. The designated time period may be determined by verifying whether the task category is a task category with strong time-volume correlation based on the historical data of the task category. If so, the time period with a large amount of tasks is determined as the designated time period. The method for verifying whether the task category is a task category with strong time-volume correlation may be to verify through autocorrelation analysis. For example, assuming that the amount of tasks is not correlated with the moment, 100 groups of moments and the amount of tasks corresponding to the moment are input, and the P value is 0.013, which is less than the significance level of 0.05. Then the task category is a task category with strong time-volume correlation.

[0139] By performing autocorrelation analysis on the historical data of the three types of asynchronous tasks A, B, and C, it is found that 13:00 to 14:00 is the designated time period.

[0140] (2) Determine from the historical data the task volume of each task category in the historical time period that matches the specified time period (corresponding to the specified representation information in the above text); among which, the task volume of category A is 533, the task volume of category B is 200, and the task volume of category C is 267.

[0141] (3) Based on the ratio of the task volume of each task category in the historical time period to the total task volume, it is determined that the thread call rate of category A relative to the total number of threads is 0.53, the thread call rate of category B relative to the total number of threads is 0.2, and the thread call rate of category C relative to the total number of threads is 0.27.

[0142] (4) Allocate at least one thread to each task category according to the thread call rate corresponding to each task category. Since the total number of threads is 15, according to the ratio of thread call rates corresponding to each task category, i.e., 0.53:0.2:0.27, 8 threads are selected from the 15 thread pool as threads corresponding to category A, 3 threads are selected as threads corresponding to category B, and 4 threads are selected as threads corresponding to category A.

[0143] (5) After obtaining the target task to be processed belonging to the target category, if the target task is a task belonging to the specified time period, a thread is selected from the at least one thread allocated to the target category according to at least one thread allocated to each task category to process the target task.

[0144] Set up a selector thread (corresponding to the management thread mentioned above) to monitor the thread status of each thread in each thread pool. Figure 4 As shown in the figure, the selector thread ( Figure 4 The middle circle S) traverses each thread in each thread pool and monitors the status of each thread.

[0145] Figure 5 The diagram shows how to allocate and monitor at least one thread corresponding to each task category within a specified time period. Figure 5 As shown, the number of threads corresponding to category A is 8, which are 5 threads in thread pool A' and 3 threads in thread pool B'; the number of threads corresponding to category B is 3, which are 2 threads in thread pool B' and 1 thread in thread pool C'; the number of threads corresponding to category C is 4, which are 4 threads in thread pool C'.

[0146] If it is monitored that a thread selected for the target category is idle, the idle thread is called to process the target task; wherein the target task can be a task obtained from the task queue of the target category managed by the selector thread. It should be noted that when the business system receives a task belonging to any task category generated by the task generation end, the task first enters the task queue belonging to each task category managed by the selector thread. The selector thread can set a number for each thread, for example, numbering each thread in the thread pool A, B and C from 1 to 15 respectively. When the selector thread takes the task out of the task queue, it can control which thread the task should be distributed to by the number.

[0147] In addition, when the target task is distributed to the corresponding thread by number, if the state of the thread is occupied at this time, the target task can be distributed to the waiting queue of the thread pool corresponding to the thread. When the control task is distributed to the corresponding thread, the thread to which the task is distributed each time can be recorded by means of a circular linked list or a counting modulus operation, or the distributed tasks can be counted, so as to calculate which thread or which thread pool the target task received this time should be distributed to. In this way, it can be ensured that the ratio of Class A tasks distributed to thread pool A' and thread pool B' is 5:3, the ratio of Class B tasks distributed to thread pool B' and thread pool C' is 2:1, and all Class C tasks are distributed to thread pool C', so that each thread can be reasonably called, so that the utilization rate of each thread is improved.

[0148] It can be seen that through this solution, the resource proportion that should be allocated to each type of task in a specified time period can be determined according to the task volume of each type of task in the historical time period, so that each task can be scientifically assigned to each thread for processing, so that the thread utilization rate is improved, and the thread task squeezing and thread idleness can be reduced, thereby improving the task processing speed while saving system resources.

[0149] Based on the above method embodiment, the present invention also provides a task processing device, such as Figure 6 As shown, the device comprises:

[0150] An acquisition module 610 is used to acquire a target task to be processed; wherein the target task belongs to a target category;

[0151] A selection module 620 is configured to select a thread from at least one thread corresponding to the target category if the target task is a task generated within a specified time period; wherein the at least one thread corresponding to each task category is pre-selected from at least one thread pool, and the number of threads meets the task volume processing requirement of the task category within the specified time period;

[0152] The processing module 630 is used to call the selected thread to process the target task.

[0153] Optionally, the device further comprises:

[0154] a determination module, configured to determine a thread pool pre-allocated to the target category if the target task is a task generated in a time period other than a specified time period;

[0155] The calling module is used to call an idle thread in the determined thread pool to process the target task.

[0156] Optionally, a method for determining at least one thread corresponding to each task category includes:

[0157] Determine the specified characterization information of each task category in the historical time period; wherein the historical time period is a time period matching the specified time period, and the specified characterization information is used to characterize the task volume;

[0158] At least one thread corresponding to each task category is determined based on the specified characterization information of each task category in the historical time period.

[0159] Optionally, determining at least one thread corresponding to each task category based on the specified characterization information of each task category in the historical time period includes:

[0160] Determine the thread call rate of each task category for the total number of threads using the specified characterization information of each task category in the historical time period, where the total number of threads is the sum of the number of threads in each thread pool;

[0161] For each task category, at least one thread is selected from at least one thread pool of each thread pool according to the thread call rate of the task category to the total number of threads, to obtain at least one thread corresponding to the task category.

[0162] Optionally, the specified characterization information includes the number of tasks;

[0163] The method of using the specified characterization information of each task category in the historical time period to determine the thread call rate of each task category with respect to the total number of threads includes:

[0164] For each task category, determine the ratio of the number of tasks of the task category in the historical time period to the total amount of tasks, and determine the thread call rate of the task category based on the determined ratio;

[0165] The total task volume is the sum of the number of tasks of each task category in the historical time period.

[0166] Optionally, determining the thread call rate of the task category based on the determined ratio includes:

[0167] The determined ratio is used as the thread call rate of the task category.

[0168] Optionally, determining the thread call rate of the task category based on the determined ratio includes:

[0169] Based on the determined ratio, and the task execution time and / or task priority of the task category, a thread call rate of the task category is determined.

[0170] The embodiment of the present invention further provides an electronic device, such as Figure 7As shown, it includes a processor 701, a communication interface 702, a memory 703 and a communication bus 704, wherein the processor 701, the communication interface 702, and the memory 703 communicate with each other through the communication bus 704.

[0171] Memory 703, used for storing computer programs;

[0172] The processor 701 is used to implement the steps of the task processing method described in any of the above embodiments when executing the program stored in the memory 703.

[0173] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0174] The communication interface is used for communication between the above electronic device and other devices.

[0175] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0176] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0177] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned task processing methods are implemented.

[0178] In another embodiment provided by the present invention, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the steps of the task processing method described in any one of the above embodiments.

[0179] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0180] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0181] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0182] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A task processing method, characterized in that: The method comprises: Obtaining a target task to be processed; wherein the target task belongs to a target category; If the target task is a task generated within a specified time period, a thread is selected from at least one thread corresponding to the target category; wherein the at least one thread corresponding to each task category is pre-selected from at least one thread pool, and the number of threads meets the task volume processing requirement of the task category within the specified time period; The selected thread is called to process the target task.

2. The method according to claim 1, characterized in that The method further comprises: If the target task is a task generated in a time period other than the specified time period, determining a thread pool pre-allocated for the target category; An idle thread in the determined thread pool is called to process the target task.

3. The method according to claim 1 or 2, characterized in that: The method of determining at least one thread corresponding to each task category includes: Determine the specified characterization information of each task category in the historical time period; wherein the historical time period is a time period matching the specified time period, and the specified characterization information is used to characterize the task volume; At least one thread corresponding to each task category is determined based on the specified characterization information of each task category in the historical time period.

4. The method according to claim 3, characterized in that: The determining at least one thread corresponding to each task category based on the specified characterization information of each task category in the historical time period includes: Determine the thread call rate of each task category for the total number of threads by using the specified characterization information of each task category in the historical time period; wherein the total number of threads is the sum of the number of threads in each thread pool; For each task category, at least one thread is selected from at least one thread pool of each thread pool according to the thread call rate of the task category to the total number of threads, to obtain at least one thread corresponding to the task category.

5. The method according to claim 4, characterized in that The specified representation information includes the number of tasks; The method of using the designated characterization information of each task category in the historical time period to determine the thread call rate of each task category with respect to the total number of threads includes: For each task category, determine the ratio of the number of tasks of the task category in the historical time period to the total amount of tasks, and determine the thread call rate of the task category based on the determined ratio; The total task volume is the sum of the number of tasks of each task category in the historical time period.

6. The method according to claim 5, characterized in that Determining the thread call rate of the task category based on the determined ratio includes: The determined ratio is used as the thread call rate of the task category.

7. The method according to claim 5, characterized in that Determining the thread call rate of the task category based on the determined ratio includes: Based on the determined ratio, and the task execution time and / or task priority of the task category, a thread call rate of the task category is determined.

8. A task processing device, characterized in that: The device comprises: An acquisition module, used for acquiring a target task to be processed; wherein the target task belongs to a target category; A selection module, configured to select a thread from at least one thread corresponding to the target category if the target task is a task generated within a specified time period; wherein the at least one thread corresponding to each task category is pre-selected from at least one thread pool, and the number of threads meets the task volume processing requirement of the task category within the specified time period; The processing module is used to call the selected thread to process the target task.

9. The device according to claim 8, characterized in that The device also includes: a determination module, configured to determine a thread pool pre-allocated to the target category if the target task is a task generated in a time period other than a specified time period; The calling module is used to call an idle thread in the determined thread pool to process the target task.

10. The device according to any one of claims 8 or 9, characterized in that The method of determining at least one thread corresponding to each task category includes: Determine the specified characterization information of each task category in the historical time period; wherein the historical time period is a time period matching the specified time period, and the specified characterization information is used to characterize the task volume; At least one thread corresponding to each task category is determined based on the specified characterization information of each task category in the historical time period.

11. The device according to claim 10, characterized in that The determining at least one thread corresponding to each task category based on the specified characterization information of each task category in the historical time period includes: Determine the thread call rate of each task category for the total number of threads using the specified characterization information of each task category in the historical time period, where the total number of threads is the sum of the number of threads in each thread pool; For each task category, at least one thread is selected from at least one thread pool of each thread pool according to the thread call rate of the task category to the total number of threads, to obtain at least one thread corresponding to the task category.

12. The device according to claim 11, characterized in that The specified representation information includes the number of tasks; The method of using the specified characterization information of each task category in the historical time period to determine the thread call rate of each task category with respect to the total number of threads includes: For each task category, determine the ratio of the number of tasks of the task category in the historical time period to the total amount of tasks, and determine the thread call rate of the task category based on the determined ratio; The total task volume is the sum of the number of tasks of each task category in the historical time period.

13. The device according to claim 12, characterized in that Determining the thread call rate of the task category based on the determined ratio includes: The determined ratio is used as the thread call rate of the task category.

14. The device according to claim 12, characterized in that Determining the thread call rate of the task category based on the determined ratio includes: Based on the determined ratio, and the task execution time and / or task priority of the task category, a thread call rate of the task category is determined.

15. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-7 when executing a program stored in a memory.

16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • A thread resource grouping method and device

    CN109710400A

  • Task processing method and device

    CN112817745A