Task processing method and device
By dynamically adjusting resource allocation and task queue design, the server-side delay and response timeout caused by insufficient thread pool configuration are solved, and the system's processing efficiency and QPS stability are improved.
Patent Information
- Application Number
- CN202411322167.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2025-01-07
AI Technical Summary
In the distributed microservice technology ecosystem, insufficient thread pool configuration leads to server delay and client response timeout when traffic increases suddenly, resulting in a sharp drop in effective QPS or even drop to zero.
By pre-calling the preset number of resources, it is divided into each task queue, and the resource allocation is dynamically adjusted according to the queue waiting time and queue status, and the tasks are allocated to different types of task queues, using the dynamic resources of the first type of task queue and Static resources for multiple second type task queues set in parallel, periodically monitor and optimize resources and tasks.
It improves task processing efficiency, avoids server delays and response timeouts caused by sudden traffic increase, and maintains the system's stable QPS.
Smart Images

Figure CN119271370A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of network data processing, and can also be used in the financial field, and in particular to a task processing method and device. Background Art
[0002] In the distributed microservice technology ecosystem, the web container uses the default thread pool configuration for processing business IO. Different business types require different configurations and reliable monitoring systems to maintain a stable QPS of the system. Generally, when traffic increases suddenly, a large number of tasks are piled up in the thread pool blocking queue. At this time, the server has a delay in processing tasks, resulting in a large number of timeouts and fuses in the client response, which will cause the effective QPS of the web server to drop sharply. In extreme cases, the effective QPS of the system may even drop to zero.
[0003] For example, during a major promotion, user traffic continued to surge. When the number of active threads in the web server's thread pool was less than the number of core threads, there was no backlog in the Socket delay task queue, the server responded promptly, and the system QPS was quite stable. When the number of requests continued to increase, the number of active threads in the thread pool was equal to the maximum number of threads, and a large number of tasks were backlogged in the Socket delay queue in a short period of time.
[0004] At this time, the socket requests at the end of the queue are processed with a long delay, which prolongs the response time of the entire system. User requests generally have a fuse timeout setting. When the waiting timeout is reached but the socket user requests are in the waiting queue on the server, they will also be processed by the thread pool, consuming system resources. When executing requests that have timed out in the task queue, if user requests continue to increase, these users' socket requests will also be placed at the end of the queue, causing these new requests to time out. Therefore, during the period of continuous traffic bursts, the effective QPS of the requests will drop a lot, or even drop to zero.
[0005] This section is intended to provide a background or context to the embodiments of the invention recited in the claims. No admission is made that the description herein is prior art by inclusion in this section. Summary of the invention
[0006] An embodiment of the present invention provides a task processing method, the method comprising:
[0007] Pre-calling a preset number of resources, and evenly distributing the preset number of resources to each task queue, and allocating the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue;
[0008] Get the waiting time for a task to join the first type of task queue;
[0009] If it is determined that the queue waiting time exceeds a preset timeout threshold, the task is added to a second type task queue;
[0010] The first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources;
[0011] If it is monitored that there is no to-be-processed task in the first type task queue, a target task that has not been processed by the second type task queue is retrieved from the second type task queue, and the target task is added to the first type task queue.
[0012] If it is determined that the queue waiting time exceeds a preset timeout threshold, adding the task to the second type task queue includes:
[0013] For each task whose waiting time for joining the queue exceeds the preset timeout threshold, a task number is assigned in chronological order. According to the mapping relationship between the pre-configured preset task number and the preset task queue number, the task corresponding to the current task number is added to a task queue with the corresponding number.
[0014] The step of retrieving, from the second type task queue, a target task that has not been processed by the second type task queue, includes:
[0015] The currently processed tasks in each task queue are obtained, and a preset number of batch tasks after each currently processed task are used as the target tasks.
[0016] Wherein, the method further comprises:
[0017] Periodically obtain the queue status of each task queue;
[0018] Resources are reallocated to each task queue according to the queue status of each task queue and the resources allocated to each task queue.
[0019] Wherein, reallocating resources to each task queue according to the queue state of each task queue and the resources allocated to each task queue includes:
[0020] Determine the average processing time of tasks corresponding to each task queue according to the queue status of each task queue;
[0021] The amount of resources to be reallocated to each task queue is determined based on a comparison result of an average of the average task processing time durations of all task queues and an average task processing time duration corresponding to each task queue.
[0022] Wherein, the method further comprises:
[0023] Periodically obtain the corresponding remaining tasks in each task queue;
[0024] The amount of tasks to be reallocated to each task queue is determined based on a comparison result between an average value of the total remaining task amounts of all task queues and the remaining task amounts corresponding to each task queue.
[0025] Wherein, the method further comprises:
[0026] Periodically monitoring the task queue indicator parameters of the first type of task queue;
[0027] If it is determined that at least one type of task queue indicator parameter is abnormal, the task queue parameters of the first type of task queue are optimized according to the abnormal indicator type and the remaining resources.
[0028] An embodiment of the present invention further provides a task processing device, the device comprising:
[0029] An allocation unit, configured to pre-call a preset number of resources, and evenly allocate the preset number of resources to each task queue, and allocate the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue;
[0030] An acquisition unit, used for acquiring the waiting time for a task to join a first type of task queue;
[0031] An adding unit, configured to add the task to a second type task queue if it is determined that the queue waiting time exceeds a preset timeout threshold;
[0032] The first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources;
[0033] The processing unit is configured to retrieve a target task that has not been processed by the second type of task queue from the second type of task queue and add the target task to the first type of task queue if it is detected that there is no to-be-processed task in the first type of task queue.
[0034] Wherein, the adding unit is specifically used for:
[0035] For each task whose waiting time for joining the queue exceeds the preset timeout threshold, a task number is assigned in chronological order. According to the mapping relationship between the pre-configured preset task number and the preset task queue number, the task corresponding to the current task number is added to a task queue with the corresponding number.
[0036] Wherein, the processing unit is specifically used for:
[0037] The currently processed tasks in each task queue are obtained, and a preset number of batch tasks after each currently processed task are used as the target tasks.
[0038] Wherein, the device is also used for:
[0039] Periodically obtain the queue status of each task queue;
[0040] Resources are reallocated to each task queue according to the queue status of each task queue and the resources allocated to each task queue.
[0041] The device is also specifically used for:
[0042] Determine the average processing time of tasks corresponding to each task queue according to the queue status of each task queue;
[0043] The amount of resources to be reallocated to each task queue is determined based on a comparison result of an average of the average task processing time durations of all task queues and an average task processing time duration corresponding to each task queue.
[0044] Allocate the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue. An embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following method when executing the computer program:
[0045] Pre-calling a preset number of resources, and evenly distributing the preset number of resources to each task queue, and allocating the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue;
[0046] Get the waiting time for a task to join the first type of task queue;
[0047] If it is determined that the queue waiting time exceeds a preset timeout threshold, the task is added to a second type task queue;
[0048] The first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources;
[0049] If it is monitored that there is no to-be-processed task in the first type task queue, a target task that has not been processed by the second type task queue is retrieved from the second type task queue, and the target task is added to the first type task queue.
[0050] An embodiment of the present invention further 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 following method is implemented:
[0051] Pre-calling a preset number of resources, and evenly distributing the preset number of resources to each task queue, and allocating the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue;
[0052] Get the waiting time for a task to join the first type of task queue;
[0053] If it is determined that the queue waiting time exceeds a preset timeout threshold, the task is added to a second type task queue;
[0054] The first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources;
[0055] If it is monitored that there is no to-be-processed task in the first type task queue, a target task that has not been processed by the second type task queue is retrieved from the second type task queue, and the target task is added to the first type task queue.
[0056] The embodiment of the present invention further provides a computer program product, the computer program product comprising a computer program, and when the computer program is executed by a processor, the following method is implemented:
[0057] Pre-calling a preset number of resources, and evenly distributing the preset number of resources to each task queue, and allocating the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue;
[0058] Get the waiting time for a task to join the first type of task queue;
[0059] If it is determined that the queue waiting time exceeds a preset timeout threshold, the task is added to a second type task queue;
[0060] The first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources;
[0061] If it is monitored that there is no to-be-processed task in the first type task queue, a target task that has not been processed by the second type task queue is retrieved from the second type task queue, and the target task is added to the first type task queue.
[0062] The task processing method and device provided by the embodiment of the present invention pre-call a preset number of resources, and evenly distribute the preset number of resources to each task queue, and allocate the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue; obtain the queue waiting time for the task to join the first type of task queue; if it is determined that the queue waiting time exceeds the preset timeout threshold, add the task to the second type of task queue; wherein the first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources; if it is monitored that there is no task to be processed in the first type of task queue, the target task that has not been processed by the second type of task queue is retrieved from the second type of task queue, and the target task is added to the first type of task queue, which can improve the task processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0064] Figure 1 A flowchart of a task processing method provided by an embodiment of the present invention;
[0065] Figure 2 A schematic diagram illustrating a first type of task queue and a second type of task queue provided in an embodiment of the present invention;
[0066] Figure 3It is a structural diagram of a task processing device provided by an embodiment of the present invention.
[0067] Figure 4 A schematic diagram of the physical structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0068] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0069] The information collected in the technical solution of this application is information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data comply with the relevant laws, regulations and standards of relevant countries and regions, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0070] The acquisition, transmission, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.
[0071] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0072] Figure 1 is a flowchart of a task processing method provided by an embodiment of the present invention, such as Figure 1 As shown, the task processing method provided by the embodiment of the present invention includes:
[0073] Step S1: pre-calling a preset number of resources, and evenly distributing the preset number of resources to each task queue, and allocating the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue.
[0074] Step S2: Obtain the waiting time for the task to join the first type task queue.
[0075] Step S3: If it is determined that the queue waiting time exceeds a preset timeout threshold, the task is added to a second type task queue;
[0076] Among them, the first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources.
[0077] Step S4: if it is detected that there is no to-be-processed task in the first type task queue, a target task that has not been processed by the second type task queue is retrieved from the second type task queue, and the target task is added to the first type task queue.
[0078] In the above step S1, the device pre-calls a preset number of resources, and evenly distributes the preset number of resources to each task queue, and allocates the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue. The device may be a computer device that executes the method. The total amount of resources in the resource pool at the time of resource configuration may be determined first, and a preset percentage of the total amount of resources, such as 30%, may be used as the preset number of resources. Figure 2 As shown, each of the three task queues is allocated 10% of the total resources at the time of resource configuration.
[0079] Since the amount of resources in the resource pool can change dynamically, and the preset number of resources is a fixed value, the remaining resources are also dynamically changing amounts of resources, and therefore the amount of resources that can be used by the first type of task queue is dynamically changing.
[0080] In the above step S2, the device obtains the waiting time for the task to be added to the first type task queue.
[0081] In the above step S3, if the device determines that the queue waiting time exceeds the preset timeout threshold, the task is added to the second type task queue;
[0082] Among them, the first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources.
[0083] In the decentralized configuration center, a configuration space is declared separately to configure the thread pool parameters for the IO business processing of the web server, such as thread name, number of core threads, maximum number of threads, maximum number of connections, delay queue size, task delay processing time threshold, and thread status collection frequency.
[0084] The custom Task Queue queue (the first type of task queue) encapsulates a custom task and task processing filter. Its function is to monitor the task delay time (queue waiting time) and discard or copy these delayed socket tasks to the slow task queue (the second type of task queue). The specific logic is as follows:
[0085] When the socket task request is queued, the above custom task is packaged, the time when the socket task is queued is recorded, and the task is bound to the currently processed thread through the ThreadLocal class.
[0086] When the web container thread pool processes tasks, it uses a custom task filter and the ThreadLocal class to obtain the task queue entry time bound to the current thread, and determines whether the current socket task reaches the waiting timeout threshold (preset timeout threshold). If exceeded, it is discarded or moved to the slow task queue. The embodiment of the present invention does not consider the situation of discarding tasks.
[0087] That is, the task queue architecture of the present invention is one first-type task queue and multiple second-type task queues. Since the present invention needs to dynamically optimize the task queue parameters of the first-type task queue according to the dynamically changing resource pool (which may include thread pool, system IO, CPU, etc.), the purpose is to make this task queue have a faster task processing speed. All resources are invested in this task queue. If multiple first-type task queues are set, it is impossible to reasonably and effectively allocate dynamic resources to the multiple first-type task queues.
[0088] Multiple second-type task queues are allocated fixed resources (preset number of resources), which can be understood as static resources, usually resources that will not change without manual configuration modification. Each second-type task queue is evenly divided into the above fixed resources. The advantage of this setting is that: based on the application scenario during the promotion period, the task volume is large, but the processing of each task itself does not take too much time. It is just that the new tasks cannot be processed in time due to the congestion and accumulation of tasks, rather than the increase in data processing time caused by a large task volume and a large amount of data to be processed. Therefore, although the second-type task queue processes tasks slowly, it can effectively cope with application scenarios with large task volumes but small data volumes processed by each task through parallel processing.
[0089] In addition, by dynamically optimizing the task queue parameters of the first type of task queue so that it has a faster task processing speed, when there is no task backlog, the unprocessed tasks in the second type of task queue can be processed in batches. Multiple second type task queues can process as many tasks in their respective queues as possible by adjusting the amount of resources and the amount of tasks when there are pending tasks in the first type of task queue, so that the method of the present invention makes full use of the corresponding amount of resources at each moment, thereby efficiently completing task processing.
[0090] In the above step S4, if the device detects that there is no task to be processed in the first type of task queue, the target task that has not been processed by the second type of task queue is retrieved from the second type of task queue, and the target task is added to the first type of task queue. If the current task queue is empty, the delayed slow task queue is taken for processing. If it is determined that the queue waiting time exceeds the preset timeout threshold, the task is added to the second type of task queue, including:
[0091] For each task whose waiting time for joining the queue exceeds the preset timeout threshold, a task number is assigned in chronological order. According to the mapping relationship between the preset task number and the preset task queue number, the task corresponding to the current task number is added to a task queue with the corresponding number. The number of task queues set in parallel can be set according to the actual situation, and can be selected as 3, such as Figure 2 As described above, they can be numbered as task queue No. 1 to task queue No. 3. Task queue No. 1 to task queue No. 3 can process the tasks in their queues in parallel.
[0092] like Figure 2 As shown, the mapping relationship can be specifically that task queue No. 1 is responsible for processing tasks with task numbers ending in 1, 4, and 7; task queue No. 2 is responsible for processing tasks with task numbers ending in 2, 5, and 8; and task queue No. 3 is responsible for processing tasks with task numbers ending in 0, 3, 6, and 9.
[0093] If task No. 9 in the first type task queue is the first task to time out, then add the task to the first task in task queue No. 1; if task No. 10 in the first type task queue is the second task to time out, then add the task to the first task in task queue No. 2; if task No. 11 in the first type task queue has not timed out, then continue to be processed by the first type task queue; if task No. 12 in the first type task queue is the third task to time out, then add the task to the first task in task queue No. 3.
[0094] The retrieving, from the second type task queue, a target task that has not been processed by the second type task queue, comprises:
[0095] Get the currently processed tasks in each task queue, and use the preset number of batch tasks after each currently processed task as the target task. Since the first type of task queue processes tasks quickly and the second type of task queue processes tasks slowly, there is a situation where there are no pending tasks in the first type of task queue and there are unprocessed tasks in at least one task queue of the second type of task queue. The preset number can be set independently according to the actual situation. Taking 3 as an example, the following is explained:
[0096] like Figure 2 As shown, if the current processing task of task queue No. 1 is the 2nd task, if the current processing task of task queue No. 2 is the 3rd task, if the current processing task of task queue No. 3 is the 3rd task, then the 3rd to 5th tasks in task queue No. 1, the 4th to 6th tasks in task queue No. 2, and the 4th to 6th tasks in task queue No. 3 are used as target tasks and sent to the first type task queue. The first type task queue can add these tasks to the first type task queue in the order in which the tasks are received. Figure 2 As shown, at this time, there is still one 6th task left in task queue No. 1, no tasks left in task queue No. 2, and there are two 7th-8th tasks left in task queue No. 3.
[0097] The method further comprises:
[0098] The queue status of each task queue is obtained periodically; the queue status of each task queue can reflect the task processing speed of the task queue. For example, each time task queue No. 1 completes a task, the number of processed tasks is increased. Then, based on the time interval corresponding to the current cycle and the number of tasks processed by task queue No. 1 within the time interval, the task processing speed of task queue No. 1 is calculated, for example, 2 tasks / s. Since the task allocation mechanism of the above task queues can basically ensure that the number of tasks allocated to each task queue is roughly the same, the task processing speed can also reflect the corresponding remaining tasks in each task queue.
[0099] The period for obtaining the queue status can be set independently according to actual conditions and can be selected as 3 minutes.
[0100] According to the queue status of each task queue and the resources allocated to each task queue, reallocate resources to each task queue. According to the queue status of each task queue and the resources allocated to each task queue, reallocate resources to each task queue, including:
[0101] The average time taken to process tasks in each task queue is determined according to the queue status of each task queue. The average time taken to process tasks in the corresponding task queue can be calculated according to the above task processing speed. Referring to the above example, the task processing speed of task queue No. 1 is 2 tasks / s, so the average time taken to process tasks in task queue No. 1 is 0.5s.
[0102] The amount of resources to be reallocated to each task queue is determined based on the comparison result of the average task processing time of all task queues and the average task processing time of each task queue. If the average task processing time of task queue 2 is 0.6s and the average task processing time of task queue 3 is 0.4s, then the average task processing time of these three task queues is 0.5s. Since the average task processing time of task queue 1 is equal to 0.5s, resources do not need to be reallocated to task queue 1.
[0103] Since the average processing time of tasks in task queue No. 2 is less than 0.5s, and the average processing time of tasks in task queue No. 3 is greater than 0.5s, it means that task queue No. 2 processes tasks faster than task queue No. 3. Based on the characteristic that task queues are all slow queues, by making each task queue have the same task processing speed, the efficiency of task queues in processing tasks can be improved as a whole.
[0104] That is, the amount of reallocated resources can be determined according to the numerical amplitude less than or greater than 0.5s. Referring to the above example, based on the numerical amplitude between 0.4s and 0.5s, the network bandwidth resource amount is determined to be 100Kbps, and 100Kbps of task queue No. 2 is transferred to task queue No. 3.
[0105] The method further comprises:
[0106] Periodically obtain the corresponding remaining tasks in each task queue;
[0107] The amount of tasks to be reallocated to each task queue is determined based on the comparison result between the average of the total remaining task amounts of all task queues and the remaining task amounts corresponding to each task queue. Figure 2 As shown, in the current cycle, if the remaining tasks in task queue No. 1 are 4, the remaining tasks in task queue No. 2 are 3, and the remaining tasks in task queue No. 3 are 5, then the average value of the total remaining tasks is 4, and accordingly, one of the remaining tasks in task queue No. 3 is transferred to task queue No. 2.
[0108] The method further comprises:
[0109] Periodically monitoring the task queue indicator parameters of the first type of task queue;
[0110] If it is determined that at least one type of task queue indicator parameter is abnormal, the task queue parameters of the first type of task queue are optimized according to the abnormal indicator type and the remaining resources. The task queue indicator parameters include queue length and task processing speed.
[0111] Queue length: Indicates the number of tasks to be processed in the queue. It can be used to measure the load of the system. A long queue may mean that the system processing capacity is insufficient or the task generation speed is too fast.
[0112] Task processing speed: refers to the number of tasks processed per unit time, which is used to evaluate the processing capacity and performance of the system.
[0113] Taking the queue length as an example, the queue length value should not be too large. If the queue length value is too large, the tasks that have timed out from joining the queue will be added to the second type of task queue, which will cause the resources at the end of the queue to be idle and unused.
[0114] The queue length value should not be too small. If the queue length value is too small, tasks that should have been processed in the first type of task queue will be automatically added to the second type of task queue because the queue is full, which makes it impossible to fully utilize the advantage of the first type of task queue's fast task processing speed.
[0115] Therefore, if the queue length is not within the preset queue length value range, it means that the queue length is abnormal. According to the queue length abnormality type (queue length value is too large or too small), the remaining resources are deployed to automatically adjust the queue length to the preset queue length value range.
[0116] The task processing method provided by the embodiment of the present invention pre-calls a preset number of resources, and evenly distributes the preset number of resources to each task queue, and allocates the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue; obtains the queue waiting time for the task to join the first type of task queue; if it is determined that the queue waiting time exceeds the preset timeout threshold, the task is added to the second type of task queue; wherein the first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources; if it is monitored that there are no tasks to be processed in the first type of task queue, the target task that has not been processed by the second type of task queue is retrieved from the second type of task queue, and the target task is added to the first type of task queue, which can improve the task processing efficiency.
[0117] Furthermore, if it is determined that the queue waiting time exceeds a preset timeout threshold, adding the task to the second type task queue includes:
[0118] For each task whose waiting time for entering the queue exceeds the preset timeout threshold, a task number is assigned in chronological order, and according to the mapping relationship between the pre-configured preset task number and the preset task queue number, the task corresponding to the current task number is added to a task queue with a corresponding number. This can be described with reference to the above embodiment, and will not be repeated here.
[0119] The task processing method provided by the embodiment of the present invention can realize the even distribution of tasks among multiple task queues and improve the task processing efficiency.
[0120] Further, the retrieving from the second type task queue a target task that has not been processed by the second type task queue includes:
[0121] The currently processed task in each task queue is obtained, and a preset number of batch tasks after each currently processed task are used as the target task. The above description can be referred to in the above embodiment, which will not be repeated here.
[0122] The task processing method provided by the embodiment of the present invention can realize autonomous and flexible batch retrieval of tasks from a task queue, thereby improving task processing efficiency.
[0123] Furthermore, the method further comprises:
[0124] The queue status of each task queue is periodically obtained; please refer to the above embodiment for description and will not be repeated here.
[0125] According to the queue state of each task queue and the resources allocated to each task queue, resources are reallocated to each task queue.
[0126] The task processing method provided by the embodiment of the present invention optimizes each task queue by reallocating resources, thereby improving the efficiency of task queues in processing tasks.
[0127] Furthermore, the reallocating of resources to each task queue according to the queue state of each task queue and the resources allocated to each task queue includes:
[0128] The average time taken to process the tasks corresponding to each task queue is determined according to the queue status of each task queue; the above-mentioned embodiment can be referred to for description and will not be repeated here.
[0129] The amount of resources to be reallocated to each task queue is determined based on the comparison result of the average task processing time of all task queues and the average task processing time corresponding to each task queue.
[0130] The task processing method provided by the embodiment of the present invention further optimizes the overall task processing efficiency of the task queue by reasonably allocating resources.
[0131] Furthermore, the method further comprises:
[0132] Periodically obtain the corresponding remaining task amount in each task queue; refer to the above embodiment for description and no further details will be given.
[0133] The amount of tasks to be reallocated to each task queue is determined based on the comparison result of the average value of the total remaining task amounts of all task queues and the remaining task amounts corresponding to each task queue.
[0134] The task processing method provided by the embodiment of the present invention optimizes each task queue by reallocating the task amount, thereby improving the efficiency of the task queue in processing tasks.
[0135] Furthermore, the method further comprises:
[0136] The task queue indicator parameters of the first type of task queue are periodically monitored; the description may refer to the above embodiment and will not be repeated here.
[0137] If it is determined that at least one type of task queue indicator parameter is abnormal, the task queue parameters of the first type of task queue are optimized according to the abnormal indicator type and the remaining resources.
[0138] The task processing method provided by the embodiment of the present invention can further improve the efficiency of the first type of task queue in processing tasks by optimizing the task queue parameters of the first type of task queue.
[0139] It should be noted that the task processing method provided in the embodiment of the present invention can be used in the financial field, and can also be used in any technical field other than the financial field. The embodiment of the present invention does not limit the application field of the task processing method.
[0140] The present invention also provides a task processing device in the following embodiments. Since the principle of solving the problem by the device is similar to that of the task processing method, the implementation of the device can refer to the implementation of the task processing method, and the repeated parts will not be repeated.
[0141] Figure 3 is a schematic diagram of the structure of a task processing device provided by an embodiment of the present invention. Figure 3 As shown, the task processing device provided by the embodiment of the present invention includes an allocating unit 301, an acquiring unit 302, an adding unit 303 and a processing unit 304, wherein:
[0142] The allocation unit 301 is used to pre-call a preset number of resources, and divide the preset number of resources equally into each task queue, and allocate the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue; the acquisition unit 302 is used to obtain the waiting time for the task to join the first type of task queue; the adding unit 303 is used to add the task to the second type of task queue if it is determined that the waiting time for the task to join the first type of task queue exceeds the preset timeout threshold; wherein the first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources; the processing unit 304 is used to retrieve the target task that has not been processed by the second type of task queue from the second type of task queue if it is detected that there is no task to be processed in the first type of task queue, and add the target task to the first type of task queue.
[0143] Specifically, the allocation unit 301 in the device is used to pre-call a preset number of resources, and evenly distribute the preset number of resources to each task queue, and allocate the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue; the acquisition unit 302 is used to obtain the waiting time for the task to join the first type of task queue; the adding unit 303 is used to add the task to the second type of task queue if it is determined that the waiting time for the task to join the first type of task queue exceeds the preset timeout threshold; wherein the first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources; the processing unit 304 is used to retrieve the target task that has not been processed by the second type of task queue from the second type of task queue if it is monitored that there is no task to be processed in the first type of task queue, and add the target task to the first type of task queue.
[0144] The task processing device provided by the embodiment of the present invention pre-calls a preset number of resources, and evenly distributes the preset number of resources to each task queue, and allocates the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue; obtains the queue waiting time for the task to join the first type of task queue; if it is determined that the queue waiting time exceeds the preset timeout threshold, the task is added to the second type of task queue; wherein the first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources; if it is monitored that there is no task to be processed in the first type of task queue, the target task that has not been processed by the second type of task queue is retrieved from the second type of task queue, and the target task is added to the first type of task queue, which can improve the task processing efficiency.
[0145] Furthermore, the adding unit 302 is specifically used for:
[0146] For each task whose waiting time for joining the queue exceeds the preset timeout threshold, a task number is assigned in chronological order. According to the mapping relationship between the pre-configured preset task number and the preset task queue number, the task corresponding to the current task number is added to a task queue with the corresponding number.
[0147] The task processing device provided by the embodiment of the present invention can realize even distribution of tasks among multiple task queues, thereby improving task processing efficiency.
[0148] Furthermore, the processing unit 303 is specifically configured to:
[0149] The currently processed tasks in each task queue are obtained, and a preset number of batch tasks after each currently processed task are used as the target tasks.
[0150] The task processing device provided by the embodiment of the present invention can realize autonomous and flexible batch retrieval of tasks from a task queue, thereby improving task processing efficiency.
[0151] Furthermore, the device is also used for:
[0152] Periodically obtain the queue status of each task queue;
[0153] Resources are reallocated to each task queue according to the queue status of each task queue and the resources allocated to each task queue.
[0154] The task processing device provided by the embodiment of the present invention optimizes each task queue by reallocating resources, thereby improving the efficiency of task queues in processing tasks.
[0155] Furthermore, the device is also specifically used for:
[0156] Determine the average processing time of tasks corresponding to each task queue according to the queue status of each task queue;
[0157] The amount of resources to be reallocated to each task queue is determined based on a comparison result of an average of the average task processing time durations of all task queues and an average task processing time duration corresponding to each task queue.
[0158] The task processing device provided by the embodiment of the present invention further optimizes the overall task processing efficiency of the task queue by reasonably allocating resources.
[0159] Furthermore, the device is also used for:
[0160] Periodically obtain the corresponding remaining tasks in each task queue;
[0161] The amount of tasks to be reallocated to each task queue is determined based on a comparison result between an average value of the total remaining task amounts of all task queues and the remaining task amounts corresponding to each task queue.
[0162] The task processing device provided by the embodiment of the present invention optimizes each task queue by reallocating the task amount, thereby improving the efficiency of the task queue in processing tasks.
[0163] Furthermore, the device is also used for:
[0164] Periodically monitoring the task queue indicator parameters of the first type of task queue;
[0165] If it is determined that at least one type of task queue indicator parameter is abnormal, the task queue parameters of the first type of task queue are optimized according to the abnormal indicator type and the remaining resources.
[0166] The task processing device provided by the embodiment of the present invention can further improve the efficiency of processing tasks by the first type of task queue by optimizing the task queue parameters of the first type of task queue.
[0167] Figure 4 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present invention, such as Figure 4 As shown, the electronic device includes: a processor (processor) 401, a memory (memory) 402 and a bus 403.
[0168] The processor 401 and the memory 402 communicate with each other via a bus 403 .
[0169] The processor 401 is used to call the program instructions in the memory 402 to execute the methods provided by the above method embodiments, for example, including:
[0170] Pre-calling a preset number of resources, and evenly distributing the preset number of resources to each task queue, and allocating the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue;
[0171] Get the waiting time for a task to join the first type of task queue;
[0172] If it is determined that the queue waiting time exceeds a preset timeout threshold, the task is added to a second type task queue;
[0173] The first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources;
[0174] If it is monitored that there is no to-be-processed task in the first type task queue, a target task that has not been processed by the second type task queue is retrieved from the second type task queue, and the target task is added to the first type task queue.
[0175] The embodiment of the present invention further 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 above method is implemented, for example, including:
[0176] Pre-calling a preset number of resources, and evenly distributing the preset number of resources to each task queue, and allocating the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue;
[0177] Get the waiting time for a task to join the first type of task queue;
[0178] If it is determined that the queue waiting time exceeds a preset timeout threshold, the task is added to a second type task queue;
[0179] The first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources;
[0180] If it is monitored that there is no to-be-processed task in the first type task queue, a target task that has not been processed by the second type task queue is retrieved from the second type task queue, and the target task is added to the first type task queue.
[0181] The embodiment of the present invention further provides a computer program product, the computer program product comprising a computer program, and the computer program implements the above method when executed by a processor, for example, comprising:
[0182] Pre-calling a preset number of resources, and evenly distributing the preset number of resources to each task queue, and allocating the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue;
[0183] Get the waiting time for a task to join the first type of task queue;
[0184] If it is determined that the queue waiting time exceeds a preset timeout threshold, the task is added to a second type task queue;
[0185] The first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources;
[0186] If it is monitored that there is no to-be-processed task in the first type task queue, a target task that has not been processed by the second type task queue is retrieved from the second type task queue, and the target task is added to the first type task queue.
[0187] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0188] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0189] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0190] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0191] The specific embodiments 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 embodiment 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 task processing method, characterized in that: include: Pre-calling a preset number of resources, and evenly distributing the preset number of resources to each task queue, and allocating the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue; Get the waiting time for a task to join the first type of task queue; If it is determined that the queue waiting time exceeds a preset timeout threshold, the task is added to a second type task queue; The first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources; If it is monitored that there is no to-be-processed task in the first type task queue, a target task that has not been processed by the second type task queue is retrieved from the second type task queue, and the target task is added to the first type task queue.
2. The method according to claim 1, characterized in that If it is determined that the queue waiting time exceeds a preset timeout threshold, adding the task to the second type task queue comprises: For each task whose waiting time for joining the queue exceeds the preset timeout threshold, a task number is assigned in chronological order. According to the mapping relationship between the pre-configured preset task number and the preset task queue number, the task corresponding to the current task number is added to a task queue with the corresponding number.
3. The method according to claim 1, characterized in that The retrieving, from the second type task queue, a target task that has not been processed by the second type task queue, comprises: The currently processed tasks in each task queue are obtained, and a preset number of batch tasks after each currently processed task are used as the target tasks.
4. The method according to claim 1, characterized in that The method further comprises: Periodically obtain the queue status of each task queue; Resources are reallocated to each task queue according to the queue status of each task queue and the resources allocated to each task queue.
5. The method according to claim 4, characterized in that The reallocating resources to each task queue according to the queue status of each task queue and the resources allocated to each task queue includes: Determine the average processing time of tasks corresponding to each task queue according to the queue status of each task queue; The amount of resources to be reallocated to each task queue is determined based on a comparison result of an average of the average task processing time durations of all task queues and an average task processing time duration corresponding to each task queue.
6. The method according to claim 1, characterized in that The method further comprises: Periodically obtain the corresponding remaining tasks in each task queue; The amount of tasks to be reallocated to each task queue is determined based on a comparison result between an average value of the total remaining task amounts of all task queues and the remaining task amounts corresponding to each task queue.
7. The method according to claim 1, characterized in that The method further comprises: Periodically monitoring the task queue indicator parameters of the first type of task queue; If it is determined that at least one type of task queue indicator parameter is abnormal, the task queue parameters of the first type of task queue are optimized according to the abnormal indicator type and the remaining resources.
8. A task processing device, characterized in that: include: An allocation unit, configured to pre-call a preset number of resources, and evenly allocate the preset number of resources to each task queue, and allocate the remaining resources in the resource pool after removing the preset number of resources to the first type of task queue; An acquisition unit, used for acquiring the waiting time for a task to join a first type of task queue; An adding unit, configured to add the task to a second type task queue if it is determined that the queue waiting time exceeds a preset timeout threshold; The first type of task queue processes tasks faster than the second type of task queue, the second type of task queue is a plurality of task queues set in parallel, the first type of task queue is allocated with dynamically changing resources, and the second type of task queue is allocated with fixed static resources; The processing unit is configured to retrieve a target task that has not been processed by the second type of task queue from the second type of task queue and add the target task to the first type of task queue if it is detected that there is no to-be-processed task in the first type of task queue.
9. The device according to claim 8, characterized in that The adding unit is specifically used for: For each task whose waiting time for joining the queue exceeds the preset timeout threshold, a task number is assigned in chronological order. According to the mapping relationship between the pre-configured preset task number and the preset task queue number, the task corresponding to the current task number is added to a task queue with the corresponding number.
10. The device according to claim 8, characterized in that The processing unit is specifically used for: The currently processed tasks in each task queue are obtained, and a preset number of batch tasks after each currently processed task are used as the target tasks.
11. The device according to claim 8, characterized in that The device is also used for: Periodically obtain the queue status of each task queue; According to the queue state of each task queue and the resources allocated to each task queue, the resources are reallocated to each task queue, and the remaining resources in the resource pool after removing the preset number of resources are allocated to the first type of task queue.
12. The device according to claim 11, characterized in that The device is also specifically used for: Determine the average processing time of tasks corresponding to each task queue according to the queue status of each task queue; The amount of resources to be reallocated to each task queue is determined based on a comparison result of an average of the average task processing time durations of all task queues and an average task processing time duration corresponding to each task queue.
13. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
14. 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.
15. A computer program product, characterized in that The computer program product comprises 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.