Task processing method and device, electronic equipment and storage medium
By breaking down business file data processing tasks into subtasks and establishing thread pool groups, and dynamically adjusting thread pool parameters, the problem of large fluctuations in CPU usage in a single thread pool solution was solved, achieving dynamic balance of CPU usage and system stability.
Patent Information
- Application Number
- CN202510967552.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-14
- Publication Date
- 2025-10-28
AI Technical Summary
In the prior art, when a single thread pool solution is used to process business archive data, the CPU usage fluctuates greatly and has obvious peaks, which affects the stability of the system.
The task to be processed is divided into multiple subtasks, and thread pool groups are established according to task type and processing order. The thread pools are connected by a message queue, and the number of threads in the thread pool is dynamically adjusted to maintain CPU usage balance.
By breaking down tasks into subtasks and dynamically adjusting thread pool parameters, dynamic balancing of CPU utilization is achieved, and peak CPU usage is automatically controlled, thus improving system stability.
Smart Images

Figure CN120849050A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a task processing method, apparatus, electronic device, and storage medium. Background Technology
[0002] In the field of business data processing, the business archive data receiving system needs to receive business archive data from upstream systems. The archive data is characterized by large increments and concentrated transmission time. The specific business archive data receiving process is as follows: (1) Verify the signature of the archive package to ensure the reliability of the file source. (2) Decompress and parse the archive package, and perform content verification to ensure the integrity and accuracy of the data. (3) Upload the corresponding attachments to the object storage platform. (4) Store the parsed structured information in the database. Each process needs to be executed in sequence.
[0003] Based on business requirements, the above-mentioned business file data receiving process typically uses a single thread pool to run the file receiving program code, making the most of system resources and improving the receiving speed. Figure 1 , Figure 2 and Figure 3 As shown, this paper compares the CPU usage of a single-threaded pool scheme with different numbers of threads. The more threads, the higher the CPU usage. Since threads in a thread pool often start at almost the same time, and each thread executes roughly the same task flow, a large number of CPU-intensive or I / O-intensive tasks are executed simultaneously. This results in alternating periods of high and low CPU usage, causing significant CPU fluctuations and negatively impacting the stable response of other services. Figure 4 As shown, threads either run or sleep almost simultaneously. Summary of the Invention
[0004] The present invention provides a task processing method, apparatus, electronic device and storage medium to maintain a dynamic balance of CPU usage and automatically regulate the peak CPU usage.
[0005] According to one aspect of the present invention, a task processing method is provided, the method comprising:
[0006] Obtain the current business data stream, which includes a batch of tasks to be processed;
[0007] The current task to be processed is split into multiple sub-tasks to be processed, and the processing order and task type of the multiple sub-tasks to be processed are obtained;
[0008] Based on the task type and the processing order, a thread pool group is established for multiple subtasks corresponding to the batch of tasks to be processed; the thread pools in the thread pool group are connected through a message queue and the thread pools have a sequential relationship.
[0009] The number of threads in the backend thread pool of the message queue is adjusted according to the number of real-time messages in the message queue to process tasks.
[0010] According to another aspect of the present invention, a task processing apparatus is provided, the apparatus comprising:
[0011] The data stream acquisition module is used to acquire the current business data stream, which includes a batch of tasks to be processed.
[0012] The subtask information acquisition module is used to split the current task to be processed into multiple subtasks to be processed, and to acquire the processing order and task type of the multiple subtasks to be processed.
[0013] The thread pool group creation module is used to create a thread pool group for multiple subtasks to be processed corresponding to the batch of tasks to be processed, based on the task type and the processing order; the thread pools in the thread pool group are connected in series through a message queue and the thread pools have a sequential relationship.
[0014] The first thread number adjustment module is used to adjust the number of threads in the backend thread pool of the message queue according to the number of real-time messages in the message queue for task processing.
[0015] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0016] At least one processor; and
[0017] A memory communicatively connected to the at least one processor; wherein,
[0018] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the task processing method described in any embodiment of the present invention.
[0019] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the task processing method described in any embodiment of the present invention.
[0020] The technical solution of this invention addresses the problem of large CPU usage fluctuations and significant peaks caused by using a single thread pool in existing solutions. This is achieved by acquiring the current business data stream including a batch of tasks to be processed; splitting the current tasks into multiple sub-tasks and obtaining their processing order and task type; establishing thread pool groups for the multiple sub-tasks corresponding to the batch tasks based on their task type and processing order; connecting the thread pools in the thread pool group via message queues and ensuring a sequential relationship between them; and adjusting the number of threads in the backend thread pool of the message queue based on the real-time message count in the message queue. By splitting the overall task into sub-tasks and utilizing multiple thread pools to process sub-tasks of different task types, and dynamically adjusting the thread pool parameter configuration, the solution resolves the issue of large CPU usage fluctuations and significant peaks caused by using a single thread pool in existing technologies. This allows for dynamic balance of CPU usage and automatic control of peak CPU usage.
[0021] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 An example diagram illustrating CPU usage in a single-threaded pool scheme with 2 threads, provided by existing technology;
[0024] Figure 2 An example diagram illustrating CPU usage in a single-threaded pool scheme with 4 threads, provided by existing technology;
[0025] Figure 3 An example diagram illustrating CPU usage in a single-threaded pool scheme with 6 threads, provided by existing technology;
[0026] Figure 4 An example diagram of thread states in a single-threaded pool scheme provided for the present technology;
[0027] Figure 5 A flowchart of a task processing method provided in Embodiment 1 of the present invention;
[0028] Figure 6 This is a schematic diagram of a thread pool group arrangement provided in this embodiment;
[0029] Figure 7This is a schematic diagram of the structure of a task processing device provided in Embodiment 2 of the present invention;
[0030] Figure 8 This is a schematic diagram of the structure of an electronic device that implements the task processing method of the present invention. Detailed Implementation
[0031] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0032] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0033] Example 1
[0034] Figure 5 This is a flowchart of a task processing method provided in Embodiment 1 of the present invention. This embodiment is applicable to the situation of receiving and storing business file data. The method can be executed by a task processing device, which can be implemented in hardware and / or software, and can be configured in a server. Figure 5 As shown, the method includes:
[0035] S110. Obtain the current business data stream, which includes a batch of pending tasks.
[0036] Here, "current business data stream" can refer to the current business archive data stream. "Tasks to be processed" can refer to business data processing tasks.
[0037] In this embodiment, a current business data stream containing a batch of tasks to be processed can be received from the upstream system.
[0038] S120. Divide the current pending task into multiple pending sub-tasks, and obtain the processing order and task type of the multiple pending sub-tasks.
[0039] Here, "current pending task" can refer to a specific task selected from the batch of pending tasks. "Pending subtask" can refer to a simple, independent unit task obtained by breaking down a single pending task. "Processing order of pending subtasks" refers to the order in which subtasks are processed to complete the overall pending task. The task type of a pending subtask can be determined by judging CPU usage; therefore, the task type of a pending subtask can be a CPU-intensive task or a non-CPU-intensive task (such as an I / O-intensive task).
[0040] In this embodiment, a task can be selected from the batch of tasks to be processed as the current task to be processed, the current task to be processed can be split into multiple sub-tasks, and the processing order of the multiple sub-tasks and the task type of each sub-task can be obtained.
[0041] In one optional implementation, the current task to be processed is split into multiple sub-tasks to be processed, and the processing order and task type of the multiple sub-tasks to be processed are obtained. This may include: determining the current task to be processed sequentially from a batch of tasks to be processed; analyzing the processing logic of the current task to be processed, splitting the current task to be processed into multiple sub-tasks to be processed according to the processing logic and determining the processing order of the multiple sub-tasks to be processed; determining the task type of the multiple sub-tasks to be processed according to the CPU usage of the multiple sub-tasks during processing; the task type includes CPU-intensive tasks and non-CPU-intensive tasks.
[0042] In this embodiment, the current task to be processed is determined, and its processing logic (or processing flow) is analyzed, such as the operations of the first step, the second step, the third step, ... and the nth step. Based on this processing flow, the current task to be processed is divided into multiple unit tasks (i.e., multiple sub-tasks to be processed), and the processing order of these multiple unit tasks is obtained. Further analysis is performed on the CPU usage of each of these multiple unit tasks to determine whether they are CPU-intensive or non-CPU-intensive tasks.
[0043] S130. Based on the task type and processing order, establish a thread pool group for multiple subtasks to be processed corresponding to the batch of tasks to be processed; the thread pools in the thread pool group are connected through a message queue and the thread pools have a sequential relationship.
[0044] In this context, a thread pool group can refer to a collection of multiple thread pools, where the same thread pool can be used to process subtasks of the same task type. A message queue can be a blocking queue that follows the "first-in, first-out" principle and can be used to coordinate the flow of tasks between different thread pools.
[0045] In one optional implementation, establishing a thread pool group for multiple subtasks corresponding to a batch of pending tasks based on task type and processing order may include: obtaining multiple subtasks corresponding to each pending task, and obtaining the task type and processing order of each subtask; dividing the multiple subtasks into at least two subtask sets according to task type and processing order; and establishing a thread pool group for multiple subtasks corresponding to a batch of pending tasks based on the at least two subtask sets corresponding to each pending task.
[0046] In this embodiment, the processing logic of each task in the batch of pending tasks is basically the same. For example, if pending task 1 is divided into subtask 1, subtask 2, subtask 3, subtask 4, and subtask 5 according to the processing order, where subtask 1 is a CPU-intensive task, subtask 2 is a CPU-intensive task, subtask 3 is an I / O-intensive task, subtask 4 is a CPU-intensive task, and subtask 5 is an I / O-intensive task, then pending task 1 can be divided into subtask set 1 (including subtask 1 and subtask 2), subtask set 2 (including subtask 3), subtask set 3 (including subtask 4), and subtask set 4 (including subtask 5).
[0047] Based on the set of subtasks corresponding to each task to be processed, four thread pools can be established: thread pool 1 for subtask set 1, thread pool 2 for subtask set 2, thread pool 3 for subtask set 3, and thread pool 4 for subtask set 4. Thread pool 1 and thread pool 2 are linked together via message queue 1, thread pool 2 and thread pool 3 are linked together via message queue 2, and thread pool 3 and thread pool 4 are linked together via message queue 3.
[0048] This setup utilizes thread pools to process tasks and uses queues to connect different thread pools. Each thread pool is divided into CPU-intensive and I / O-intensive tasks, executing only fixed logic. Each thread pool provides processing results to subsequent thread pools, forming a pipeline. Once all thread pools are running, at any given time, there are CPU-intensive and I / O-intensive tasks executing, thus maintaining a dynamic balance in system CPU usage.
[0049] S140. Adjust the number of threads in the backend thread pool of the message queue according to the number of real-time messages in the message queue to process tasks.
[0050] In this embodiment, it is desirable to keep the average CPU usage stable during task processing. The running speed of each thread pool needs to cooperate with each other. Therefore, the configuration of the thread pool can be dynamically adjusted to achieve dynamic balance in the program execution of each thread pool.
[0051] In one optional implementation, adjusting the number of threads in the message queue backend thread pool for task processing based on the number of real-time messages in the message queue may include: obtaining a first occupancy of messages in the current message queue; if the first occupancy exceeds a first occupancy limit, gradually increasing the number of threads in the current message queue backend thread pool by a first preset step size until the upper limit of the number of threads in the backend thread pool is reached; if the first occupancy is lower than a second occupancy limit, gradually decreasing the number of threads in the current message queue backend thread pool by a first preset step size until the lower limit of the number of threads in the backend thread pool is reached.
[0052] Continuing the example in S130, for thread pools 2, 3, and 4, thread pool expansion can be triggered when the number of messages in their preceding message queues exceeds 80% of the preset capacity (equivalent to the first occupancy limit). For example, if the queue capacity is 100, and 80 tasks accumulate, the number of threads is gradually increased by a step size of 1 (equivalent to the first preset step size) until the upper limit of the number of threads is reached. When the number of messages in the queue is less than 20% of the preset capacity (equivalent to the second occupancy limit), thread pool shrinkage can be triggered, and the number of threads is gradually decreased by a step size of 1 until the lower limit of the number of threads is reached. This strategy allows thread pools 2, 3, and 4 to match the production speed of thread pool 1.
[0053] Optionally, the task processing method of this embodiment may further include: real-time monitoring of the second CPU usage during the operation of the thread pool group; if the second usage exceeds a third usage limit, gradually reducing the number of threads in the first thread pool in the thread pool group by a second preset step size until the lower limit of the number of threads in the first thread pool is reached; if the second usage is lower than a fourth usage limit, gradually increasing the number of threads in the first thread pool in the thread pool group by a second preset step size until the upper limit of the number of threads in the first thread pool is reached.
[0054] Continuing the previous example, thread pool 1 is the starting point for the entire current data stream processing task. Thread pools 2, 3, and 4 use automatic scaling technology to match the production speed of thread pool 1. Therefore, the configuration of thread pool 1 determines the overall task speed limit and CPU usage limit. Thus, in this embodiment, the CPU usage of the entire system can be monitored in real time. When the CPU usage exceeds 50% (equivalent to the third usage threshold), the number of threads is gradually reduced by a step size of 1 (equivalent to the second preset step size; the first and second preset step sizes in this embodiment can be the same or different, and this embodiment does not impose any limitations). When the CPU usage is below 30% (equivalent to the fourth usage threshold), the number of threads is gradually increased by a step size of 1 to maintain the overall stability of the system's CPU usage.
[0055] Optionally, the maximum number of threads in a thread pool used for handling CPU-intensive tasks can be set to the sum of the number of CPUs and a specified value; the maximum number of threads in a thread pool used for handling non-CPU-intensive tasks can be set to a specified multiple of the number of CPUs.
[0056] In this embodiment, CPU-intensive tasks refer to tasks that require a large amount of computation and have relatively few I / O operations. These tasks are characterized by high CPU utilization, with threads spending most of their time performing computations. For CPU-intensive tasks, the number of threads should be configured to be as small as possible, typically the number of CPUs plus one (equivalent to a specified value). This is because too many threads lead to frequent context switching, which reduces efficiency.
[0057] I / O-intensive tasks refer to tasks involving a large number of I / O operations (such as network communication, file reading and writing, etc.). These tasks are characterized by threads spending most of their time waiting for I / O operations to complete. For I / O-intensive tasks, a larger number of threads can be configured, typically twice the number of CPUs (equivalent to a specified multiple).
[0058] Optionally, the thread pools in this embodiment can be arranged intermittently according to the type of task they process, for example, thread pool 1 for CPU-intensive tasks, thread pool 2 for I / O-intensive tasks, and thread pool 3 for CPU-intensive tasks. Figure 6 This is a schematic diagram of a thread pool group arrangement provided in this embodiment.
[0059] The technical solution of this invention addresses the problem of large CPU usage fluctuations and significant peaks caused by using a single thread pool in existing solutions. This is achieved by acquiring the current business data stream including a batch of tasks to be processed; splitting the current tasks into multiple sub-tasks and obtaining their processing order and task type; establishing thread pool groups for the multiple sub-tasks corresponding to the batch tasks based on their task type and processing order; connecting the thread pools in the thread pool group via message queues and ensuring a sequential relationship between them; and adjusting the number of threads in the backend thread pool of the message queue based on the real-time message count in the message queue. By splitting the overall task into sub-tasks and utilizing multiple thread pools to process sub-tasks of different task types, and dynamically adjusting the thread pool parameter configuration, the solution resolves the issue of large CPU usage fluctuations and significant peaks caused by using a single thread pool in existing technologies. This allows for dynamic balance of CPU usage and automatic control of peak CPU usage.
[0060] Example 2
[0061] Figure 7 This is a schematic diagram of a task processing device provided in Embodiment 2 of the present invention. Figure 7 As shown, the device includes: a data stream acquisition module 210, a subtask information acquisition module 220, a thread pool group establishment module 230, and a thread count first adjustment module 240. Wherein:
[0062] Data stream acquisition module 210 is used to acquire the current business data stream, which includes a batch of tasks to be processed;
[0063] The subtask information acquisition module 220 is used to split the current task to be processed into multiple subtasks to be processed, and to acquire the processing order and task type of the multiple subtasks to be processed;
[0064] The thread pool group creation module 230 is used to create a thread pool group for multiple subtasks to be processed corresponding to the batch of tasks to be processed, according to the task type and the processing order; the thread pools in the thread pool group are connected through a message queue and the thread pools have a sequential relationship.
[0065] The first thread number adjustment module 240 is used to adjust the number of threads in the backend thread pool of the message queue according to the number of real-time messages in the message queue for task processing.
[0066] The technical solution of this invention addresses the problem of large CPU usage fluctuations and significant peaks caused by using a single thread pool in existing solutions. This is achieved by acquiring the current business data stream including a batch of tasks to be processed; splitting the current tasks into multiple sub-tasks and obtaining their processing order and task type; establishing thread pool groups for the multiple sub-tasks corresponding to the batch tasks based on their task type and processing order; connecting the thread pools in the thread pool group via message queues and ensuring a sequential relationship between them; and adjusting the number of threads in the backend thread pool of the message queue based on the real-time message count in the message queue. By splitting the overall task into sub-tasks and utilizing multiple thread pools to process sub-tasks of different task types, and dynamically adjusting the thread pool parameter configuration, the solution resolves the issue of large CPU usage fluctuations and significant peaks caused by using a single thread pool in existing technologies. This allows for dynamic balance of CPU usage and automatic control of peak CPU usage.
[0067] Optionally, the subtask information acquisition module 220 can be used for:
[0068] The current task to be processed is determined sequentially from the batch of tasks to be processed;
[0069] Analyze the processing logic of the current task to be processed, and divide the current task to be processed into multiple sub-tasks to be processed according to the processing logic and determine the processing order of the multiple sub-tasks to be processed.
[0070] Based on the CPU usage of the multiple subtasks during processing, the task types of the multiple subtasks are determined; the task types include CPU-intensive tasks and non-CPU-intensive tasks.
[0071] Optionally, the thread pool group creation module 230 can be used for:
[0072] Retrieve multiple subtasks corresponding to each pending task, and obtain the task type and processing order of each subtask;
[0073] According to the task type, the multiple sub-tasks to be processed are divided into at least two sub-task sets according to the processing order;
[0074] Based on the at least two subtask sets corresponding to each pending task, a thread pool group is established for the multiple pending subtasks corresponding to the batch pending tasks.
[0075] Optionally, the first thread count adjustment module is 240, which can be used for:
[0076] Get the initial occupancy of the message queue currently in use;
[0077] If the first occupancy exceeds the first occupancy limit, the number of threads in the current message queue backend thread pool is gradually increased by a first preset step size until the upper limit of the number of threads in the backend thread pool is reached.
[0078] If the first occupancy is lower than the second occupancy limit, the number of threads in the current message queue backend thread pool is gradually reduced according to the first preset step size until the lower limit of the number of threads in the backend thread pool is reached.
[0079] Optionally, the task processing device further includes a second thread number adjustment module, used for:
[0080] Real-time monitoring of the CPU's second utilization during the operation of the thread pool group;
[0081] If the second occupancy exceeds the third occupancy limit, the number of threads in the first thread pool in the thread pool group will be gradually reduced by a second preset step size until the lower limit of the number of threads in the first thread pool is reached.
[0082] When the second occupancy is lower than the fourth occupancy limit, the number of threads in the first thread pool of the thread pool group is gradually increased according to the second preset step size until the upper limit of the number of threads in the first thread pool is reached.
[0083] Optionally, the task processing device further includes a thread count setting module, used for:
[0084] Set the maximum number of threads in the thread pool used to process the CPU-intensive task to the sum of the number of CPUs and a specified value;
[0085] Set the maximum number of threads in the thread pool used to process the non-CPU-intensive tasks to a specified multiple of the number of CPUs.
[0086] Optionally, the thread pools are arranged at intervals according to the types of tasks they process.
[0087] The task processing device provided in the embodiments of the present invention can execute the task processing method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the method execution.
[0088] Example 3
[0089] Figure 8 A schematic diagram of an electronic device 300 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers or various forms of mobile devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0090] like Figure 8 As shown, the electronic device 300 includes at least one processor 301 and a memory, such as a read-only memory (ROM) 302 or a random access memory (RAM) 303, communicatively connected to the at least one processor 301. The memory stores computer programs executable by the at least one processor. The processor 301 can perform various appropriate actions and processes based on the computer program stored in the ROM 302 or loaded into the RAM 303 from storage unit 308. The RAM 303 can also store various programs and data required for the operation of the electronic device 300. The processor 301, ROM 302, and RAM 303 are interconnected via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0091] Multiple components in electronic device 300 are connected to I / O interface 305, including: input unit 306, such as keyboard, mouse, etc.; output unit 307, such as various types of displays, speakers, etc.; storage unit 308, such as disk, optical disk, etc.; and communication unit 309, such as network card, modem, wireless transceiver, etc. Communication unit 309 allows electronic device 300 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0092] Processor 301 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 301 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. Processor 301 performs the various methods and processes described above, such as task processing methods.
[0093] In some embodiments, the task processing method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 308. In some embodiments, part or all of the computer program may be loaded and / or mounted on electronic device 300 via ROM 302 and / or communication unit 309. When the computer program is loaded into RAM 303 and executed by processor 301, one or more steps of the task processing method described above may be performed. Alternatively, in other embodiments, processor 301 may be configured to perform the task processing method by any other suitable means (e.g., by means of firmware).
[0094] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0095] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0096] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0097] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0098] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0099] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0100] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0101] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A task processing method, characterized in that, include: Obtain the current business data stream, which includes a batch of tasks to be processed; The current task to be processed is split into multiple sub-tasks to be processed, and the processing order and task type of the multiple sub-tasks to be processed are obtained; Based on the task type and the processing order, a thread pool group is established for multiple subtasks corresponding to the batch of tasks to be processed; the thread pools in the thread pool group are connected through a message queue and the thread pools have a sequential relationship. The number of threads in the backend thread pool of the message queue is adjusted according to the number of real-time messages in the message queue to process tasks.
2. The method according to claim 1, characterized in that, The current task to be processed is split into multiple sub-tasks to be processed, and the processing order and task type of the multiple sub-tasks to be processed are obtained, including: The current task to be processed is determined sequentially from the batch of tasks to be processed; Analyze the processing logic of the current task to be processed, and divide the current task to be processed into multiple sub-tasks to be processed according to the processing logic and determine the processing order of the multiple sub-tasks to be processed. Based on the CPU usage of the multiple subtasks during processing, the task types of the multiple subtasks are determined; the task types include CPU-intensive tasks and non-CPU-intensive tasks.
3. The method according to claim 1, characterized in that, Based on the task type and the processing order, a thread pool group is established for the multiple subtasks corresponding to the batch of tasks to be processed, including: Retrieve multiple subtasks corresponding to each pending task, and obtain the task type and processing order of each subtask; According to the task type, the multiple sub-tasks to be processed are divided into at least two sub-task sets according to the processing order; Based on the at least two subtask sets corresponding to each pending task, a thread pool group is established for the multiple pending subtasks corresponding to the batch pending tasks.
4. The method according to claim 1, characterized in that, Based on the number of real-time messages in the message queue, adjust the number of threads in the message queue backend thread pool to process tasks, including: Get the initial occupancy of the message queue currently in use; If the first occupancy exceeds the first occupancy limit, the number of threads in the current message queue backend thread pool is gradually increased by a first preset step size until the upper limit of the number of threads in the backend thread pool is reached. If the first occupancy is lower than the second occupancy limit, the number of threads in the current message queue backend thread pool is gradually reduced according to the first preset step size until the lower limit of the number of threads in the backend thread pool is reached.
5. The method according to claim 1, characterized in that, Also includes: Real-time monitoring of the CPU's second utilization during the operation of the thread pool group; If the second occupancy exceeds the third occupancy limit, the number of threads in the first thread pool in the thread pool group will be gradually reduced by a second preset step size until the lower limit of the number of threads in the first thread pool is reached. When the second occupancy is lower than the fourth occupancy limit, the number of threads in the first thread pool of the thread pool group is gradually increased according to the second preset step size until the upper limit of the number of threads in the first thread pool is reached.
6. The method according to claim 2, characterized in that, Also includes: Set the maximum number of threads in the thread pool used to process the CPU-intensive task to the sum of the number of CPUs and a specified value; Set the maximum number of threads in the thread pool used to process the non-CPU-intensive tasks to a specified multiple of the number of CPUs.
7. The method according to any one of claims 1-5, characterized in that, The thread pools are arranged at intervals according to the types of tasks they process.
8. A task processing device, characterized in that, include: The data stream acquisition module is used to acquire the current business data stream, which includes a batch of tasks to be processed. The subtask information acquisition module is used to split the current task to be processed into multiple subtasks to be processed, and to acquire the processing order and task type of the multiple subtasks to be processed. The thread pool group creation module is used to create a thread pool group for multiple subtasks to be processed corresponding to the batch of tasks to be processed, based on the task type and the processing order; the thread pools in the thread pool group are connected in series through a message queue and the thread pools have a sequential relationship. The first thread number adjustment module is used to adjust the number of threads in the backend thread pool of the message queue according to the number of real-time messages in the message queue for task processing.
9. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the task processing method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the task processing method according to any one of claims 1-7.