Task processing method, service system and storage medium

By updating the correspondence between thread names and task names in the thread pool, and determining task monitoring data based on the running data of the target thread, the problem of impossible to quickly locate task exceptions in the thread pool in the existing technology is solved, and rapid troubleshooting is achieved, improving the operating efficiency and stability of the server.

CN120429080APending Publication Date: 2025-08-05ANT BLOCKCHAIN TECHNOLOGY (SHANGHAI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510530276.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-24
Publication Date
2025-08-05

AI Technical Summary

Technical Problem

The existing technology cannot quickly locate the cause of task abnormalities in thread pools, which makes troubleshooting difficult and inefficient, affecting the stability and efficiency of the server.

Method used

By updating the correspondence between thread names and task names in the thread pool, the task monitoring data is determined based on the running data of the target thread, task-level monitoring is realized, and abnormal tasks and threads are quickly located.

Benefits of technology

It reduces the difficulty of troubleshooting, shortens the troubleshooting time, and improves the operation efficiency and stability of the server.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120429080A_ABST
    Figure CN120429080A_ABST
Patent Text Reader

Abstract

The invention provides a task processing method, service equipment and a storage medium. The task processing method comprises the steps that after a server receives a plurality of tasks to be processed, the plurality of tasks are executed through a thread pool. When a server executes any target task in a plurality of tasks, a target thread used for executing the target task can be determined in a thread pool, and the thread name of the target thread is updated based on the task name of the target task, so that the updated thread name has a corresponding relation with the task name. And when the target task is executed through the target thread, task monitoring data corresponding to the target task is determined based on the operation data of the target thread in the execution process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of Internet technology, and in particular to a task processing method, service system, and storage medium. Background Art

[0002] To cope with high-concurrency scenarios, thread pool technology has become an important means of improving server throughput and resource utilization efficiency. By allocating and managing thread resources through a thread pool, the performance loss caused by frequent thread creation and destruction can be effectively reduced, thereby ensuring server responsiveness under high load.

[0003] Current solutions primarily monitor thread pools based on their overall operational status, such as overall thread pool load, number of active threads, task queue length, and number of rejected tasks, to assess the health and stability of the thread pool. Some solutions also incorporate logging or performance analysis tools to generate alerts for abnormal thread pool behavior.

[0004] However, the existing solution can only monitor the overall operating status of the thread pool. When an exception occurs in a task executed in the thread pool, it is impossible to quickly locate the cause of the exception. Manual log checking or reproduction of the scenario is required to determine the cause of the exception. Troubleshooting is difficult and inefficient, which seriously affects the stability of the server.

[0005] The content of the background technology section is merely information known to the inventor personally, and does not mean that the above information has entered the public domain before the application date of this disclosure, nor does it mean that it can become the prior art of the present disclosure. Summary of the Invention

[0006] This specification provides a task processing method, service system and storage medium, which can realize task-level monitoring of thread pool.

[0007] In order to achieve the above objectives, the embodiments of this specification adopt the following technical solutions:

[0008] In the first aspect, the present specification provides a task processing method, which is applied to a server configured with a thread pool, the method comprising: obtaining multiple tasks to be processed; and executing the multiple tasks through the thread pool, wherein, for any target task among the multiple tasks, the execution process of the target task comprises: determining a target thread to execute the target task in the thread pool, updating the thread name of the target thread based on the task name of the target task so that the updated thread name has a corresponding relationship with the task name, and executing the target task through the target thread, and during the execution of the target task, determining the task monitoring data corresponding to the target task based on the running data of the target thread.

[0009] In some embodiments, the code of the thread pool includes burying code corresponding to the burying event, and determines the task monitoring data corresponding to the target task based on the running data of the target thread, including: when it is detected that the target thread triggers a preset burying event, executing the burying code corresponding to the burying event to collect the running data of the target thread; and determining the task monitoring data corresponding to the target task based on the running data of the target thread.

[0010] In some embodiments, the task monitoring data corresponding to the target task includes at least one of the following: the start execution time of the target task; the end execution time of the target task; the processing time of the target task; or abnormal information during the execution of the target task.

[0011] In some embodiments, the updated thread name is the same as the task name, or a substring in the updated thread name is the same as the task name.

[0012] In some embodiments, each thread in the thread pool corresponds to a task type, and determining the target thread to execute the target task in the thread pool includes: determining the target thread in the thread pool according to the task type to which the target task belongs, and the task type corresponding to the target thread is the same as the task type to which the target task belongs.

[0013] In some embodiments, determining the target thread in the thread pool includes: matching in the thread pool according to the task type corresponding to the target task, and when a thread with the same task type and being idle is matched, determining the thread with the same task type and being idle as the target thread; when a thread with the same task type and being idle is not matched, updating the task type of the idle thread in the thread pool according to the task type corresponding to the target task, and determining the updated thread as the target thread; and when there is no idle thread in the thread pool, if the number of threads in the thread pool is less than the maximum number of threads, creating the target thread in the thread pool according to the task type corresponding to the target task.

[0014] In some embodiments, before executing the multiple tasks through the thread pool, it also includes: determining the predicted amount of resources required to be consumed by the multiple tasks, and updating the thread pool parameters corresponding to the thread pool based on the predicted amount of resources and the amount of idle resources of the thread pool; and during the execution of the multiple tasks, the method also includes: expanding or shrinking the thread pool based on the updated thread pool parameters.

[0015] In some embodiments, determining the predicted amount of resources required to be consumed by the multiple tasks includes: obtaining the task type corresponding to each of the multiple tasks; according to the task type of each task, obtaining the historical amount of resources consumed by at least one historical task of the same task type, and determining the predicted amount of resources corresponding to the task based on the historical amount of resources corresponding to the at least one historical task; and taking the sum of the predicted amount of resources for the multiple tasks as the predicted amount of resources required to be consumed by the multiple tasks.

[0016] In some embodiments, determining the predicted resource amount corresponding to the task based on the historical resource amount corresponding to the at least one historical task includes: determining the predicted resource amount corresponding to the task based on the mean of the historical resource amounts corresponding to the at least one historical task; or using the historical resource amount corresponding to the at least one historical task as an example sample, guiding the target model to perform example learning based on the example sample to determine the predicted resource amount corresponding to the task.

[0017] In some embodiments, the thread pool parameters corresponding to the thread pool are updated based on the predicted resource amount and the idle resource amount of the thread pool, including: when the predicted resource amount is greater than the idle resource amount of the thread pool, increasing the upper limit of the number of core threads corresponding to the thread pool, or increasing the maximum number of threads corresponding to the thread pool; when the predicted resource amount is less than the idle resource amount of the thread pool, reducing the upper limit of the number of core threads corresponding to the thread pool, or reducing the maximum number of threads corresponding to the thread pool.

[0018] In some embodiments, the threads in the thread pool include core threads and non-core threads, and the thread pool is expanded or reduced based on the updated thread pool parameters, including: when the load of the thread pool meets the preset expansion conditions, at least one thread is created in the thread pool based on the updated thread pool parameters to expand the thread pool; when the load of the thread pool meets the preset reduction conditions, at least one thread in the thread pool is destroyed based on the updated thread pool parameters to reduce the thread pool.

[0019] In some embodiments, at least one thread is created in the thread pool based on the updated thread pool parameters, including: creating at least one thread in the thread pool when the number of core threads in the thread pool is less than the upper limit of the number of core threads corresponding to the thread pool, or when the number of core threads in the thread pool is equal to the upper limit of the number of core threads but less than the maximum number of threads corresponding to the thread pool.

[0020] In some embodiments, the load of the thread pool includes: the corresponding processor usage of the thread pool and the idle time of the threads in the thread pool; the preset shrinkage condition includes at least one of the following preset shrinkage conditions: the number of threads in the thread pool is greater than a preset thread number threshold, and the corresponding processor usage of the thread pool is less than or equal to the preset usage threshold, or there are threads in the thread pool whose idle time is greater than or equal to the preset time threshold.

[0021] In some embodiments, the load of the thread pool includes: the number of tasks in the task queue of the thread pool; and satisfying the preset expansion condition includes: the number of tasks being greater than a preset task number threshold.

[0022] In some embodiments, destroying at least one thread in the thread pool based on the updated thread pool parameters includes: destroying at least one non-core thread when the number of threads in the thread pool is greater than the upper limit of the number of core threads corresponding to the thread pool.

[0023] In some embodiments, obtaining multiple tasks to be processed includes: receiving an original task and decomposing the original task according to a preset task decomposition strategy to obtain the multiple tasks; after executing the multiple tasks through the thread pool, it also includes: obtaining the execution results corresponding to each of the multiple tasks; and aggregating the execution results corresponding to each of the multiple tasks to obtain the processing results of the original task.

[0024] In a second aspect, this specification also provides a service system, comprising: at least one storage medium storing at least one instruction set for processing received tasks; and at least one processor communicatively connected to the at least one storage medium, wherein when the service system is running, the at least one processor reads the at least one instruction set and implements the method provided in the first aspect according to the instructions of the at least one instruction set.

[0025] In a third aspect, this specification also provides a computer-readable non-volatile storage medium, wherein the computer-readable non-volatile storage medium stores at least one instruction set, and when the at least one instruction set is executed by at least one processor, the method provided in the first aspect is implemented.

[0026] Other functions of the task processing method, service system, and storage medium provided in this specification are partially listed in the following description. The creative aspects of the task processing method, service system, and storage medium provided in this specification can be fully explained by practicing or using the methods, devices, and combinations described in the following detailed examples. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the technical solutions in the embodiments of this specification, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0028] Figure 1 A schematic diagram of an application scenario of a task processing method provided according to an embodiment of this specification is shown;

[0029] Figure 2 A hardware structure diagram of a computing device provided according to an embodiment of this specification is shown;

[0030] Figure 3 A flowchart of a task processing method provided according to an embodiment of this specification is shown;

[0031] Figure 4 A schematic diagram of adjusting thread pool parameters according to an embodiment of this specification is shown;

[0032] Figure 5 A schematic diagram of determining a target thread according to a target task provided in an embodiment of this specification is shown; and

[0033] Figure 6 A schematic diagram of executing a target task through a thread pool according to an embodiment of this specification is shown. DETAILED DESCRIPTION

[0034] The following description provides specific application scenarios and requirements for this specification, with the goal of enabling those skilled in the art to make and use the contents of this specification. Various modifications to the disclosed embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other embodiments and applications without departing from the spirit and scope of this specification. Therefore, this specification is not limited to the embodiments shown, but is intended to be accorded the broadest scope consistent with the claims.

[0035] The terms used herein are for the purpose of describing specific example embodiments only and are not intended to be limiting. For example, as used herein, the singular forms "a," "an," and "the" may also include the plural forms unless the context clearly indicates otherwise. When used in this specification, the terms "comprise," "include," and / or "contain" are intended to refer to the presence of the associated integers, steps, operations, elements, and / or components, but do not preclude the presence of one or more other features, integers, steps, operations, elements, components, and / or groups or the addition of other features, integers, steps, operations, elements, components, and / or groups in the system / method.

[0036] These and other features of this specification, as well as the operation and function of the associated elements of the structure, and the economical assembly and manufacture of the components, can be significantly improved with consideration of the following description. Reference is made to the accompanying drawings, all of which form a part of this specification. However, it should be expressly understood that the drawings are for illustration and description purposes only and are not intended to limit the scope of this specification. It should also be understood that the drawings are not drawn to scale.

[0037] The flowcharts used in this specification illustrate operations implemented by systems according to some embodiments of the present specification. It should be clearly understood that the operations of the flowcharts may not be implemented in sequence. Rather, the operations may be implemented in reverse order or simultaneously. Furthermore, one or more additional operations may be added to the flowcharts. One or more operations may be removed from the flowcharts.

[0038] The following is an introduction to the application scenarios of this manual.

[0039] The technical solution provided in this specification is applicable to scenarios where a server equipped with a thread pool executes concurrent tasks. For example, the task processing method can be applied to a server corresponding to each service in a microservices architecture. In this scenario, a service in the microservices architecture is equipped with at least one thread pool on the server. The server can receive multiple concurrent requests from clients and process them based on the thread pool.

[0040] Currently, when a server processes multiple concurrent requests based on a thread pool, it can only monitor the overall operating status of the thread pool. For example, the server can monitor parameters such as the overall load of the thread pool, the number of active threads, the length of the task queue, and the number of rejected tasks to assess the health and stability of the thread pool. During this process, the server can combine logging or third-party performance analysis tools to issue an alarm when an abnormality occurs in a task executed by the thread pool. However, the existing solution is unable to quickly locate the cause of the abnormality when an abnormality alarm occurs. It is necessary to manually check the logs or reproduce the scene where the abnormality occurs to determine the cause of the abnormality. Troubleshooting is difficult and inefficient, resulting in serious impact on the operating efficiency and stability of the server.

[0041] This specification provides a task processing method that can be executed by a server configured with a thread pool. First, after receiving multiple tasks to be processed, the server can execute the multiple tasks through the thread pool. When executing any target task among the multiple tasks, the server can first determine the target thread for executing the target task, and then update the thread name of the target thread based on the task name of the target task, so that the updated thread name has a corresponding relationship with the task name. Finally, when executing the target task through the target thread, the task monitoring data corresponding to the target task is determined based on the running data of the target thread.

[0042] In the solution provided in this specification, when executing the target task through the target thread, the thread name is updated according to the task name of the target task, so that the target thread can have a corresponding relationship with the target task, and then the task monitoring data corresponding to the target task is obtained by obtaining the running data of the target thread. Task-level monitoring of the thread pool is realized, and fine-grained and traceable task monitoring is provided during the execution of the target task. When an exception occurs in the execution of the target task, the operation and maintenance personnel can quickly locate the target task and the corresponding target thread with the exception through the thread name, without the need to manually screen log records or reproduce the scene where the exception occurs, which greatly reduces the difficulty of troubleshooting, shortens the troubleshooting time, and improves the operating efficiency and stability of the server.

[0043] Figure 1 FIG1 shows a schematic diagram of an application scenario of a task processing method provided according to an embodiment of this specification. Figure 1 As shown, the application scenario 100 may include a service device 11 and N user devices 12, where N is an integer greater than or equal to 1. The service device 11 may be a server corresponding to the service end. The service device 11 deploys at least one service, for example, Figure 1 In the illustrated scenario, service A is deployed in the service device 11 , a thread pool is configured in service A, and the service device 11 is the server corresponding to service A.

[0044] Continue to see Figure 1 Each user device 12 can respond to the user's target operation and initiate a task related to service A to the service device 11. The service device 11 can execute the task processing method provided in this specification and process the multiple tasks received through the thread pool configured in service A. As an example, the task related to service A initiated by the user device 12 to the service device 11 in response to the user's target operation can be a network request, a computing task, a file processing and conversion task, or a decomposable original task.

[0045] In some embodiments, the service device 11 may be an independent server, a server cluster, a cloud server, etc. The service device 11 may start and run at least one service deployed therein. Figure 1 Service A is a service that is started and running. Service A can be an application, microservice or any other type of service developed based on the Spring framework. At least one thread pool is configured in service A. The thread pool includes at least one thread. The threads in the thread pool can be used to process tasks received by the service device 11.

[0046] In some embodiments, the task processing methods provided herein can be executed on a service device 11. In this case, the service device 11 may store data or instructions for executing the task processing methods described herein and may execute or be used to execute such data or instructions. In some embodiments, the service device 11 may include hardware devices capable of data and information processing and the necessary programs to operate the hardware devices.

[0047] In some embodiments, the user device 12 may include a mobile device, a tablet computer, a laptop computer, a built-in device of a motor vehicle, or the like, or any combination thereof. In some embodiments, the mobile device may include a smart home device, a smart mobile device, a virtual reality device, an augmented reality device, or the like, or any combination thereof. In some embodiments, the smart home device may include a smart TV, a desktop computer, or the like, or any combination thereof. In some embodiments, the smart mobile device may include a smartphone, a personal digital assistant, a gaming device, a navigation device, or the like, or any combination thereof. In some embodiments, the virtual reality device or the augmented reality device may include a virtual reality helmet, virtual reality glasses, a virtual reality patch, an augmented reality helmet, augmented reality glasses, an augmented reality patch, or the like, or any combination thereof. For example, the virtual reality device or the augmented reality device may include Google Glass, a head-mounted display, VR, or the like. In some embodiments, the built-in device in the motor vehicle may include an onboard computer, an onboard TV, or the like.

[0048] In some embodiments, the user device 12 may be installed with one or more application programs (APPs). The APPs can provide capabilities and interfaces for human-computer interaction. The APPs include, but are not limited to, web browser APPs, search APPs, chat APPs, shopping APPs, video APPs, financial management APPs, instant messaging tools, email clients, social platform software, and the like. In some embodiments, a target APP may be installed on the user device 12. The target APP may be any type of APP or a collection of multiple types of APPs. The target APP is the client corresponding to service A. The target APP can respond to the user's target operation and initiate tasks related to service A to the service device 11.

[0049] It should be understood that Figure 1 The number of service devices 11 and user devices 12 in FIG. 1 is merely illustrative. Any number of service devices 11 and user devices 12 may be provided according to implementation requirements.

[0050] Figure 2 FIG2 shows a hardware structure diagram of a computing device provided according to an embodiment of this specification. The computing device 200 can be used as Figure 1The service device 11 in the embodiment executes the task processing method described in this specification.

[0051] like Figure 2 As shown, computing device 200 may include at least one storage medium 230 and at least one processor 220. In some embodiments, computing device 200 may further include communication port 250 and internal communication bus 210. Computing device 200 may also include I / O component 260.

[0052] The internal communication bus 210 can connect various system components, such as the storage medium 230 , the processor 220 , the communication port 250 , and the I / O component 260 .

[0053] I / O components 260 support input / output between computing device 200 and other components.

[0054] The communication port 250 is used for data communication between the computing device 200 and the outside world. For example, the communication port 250 can be used for data communication between the computing device 200 and a network. The communication port 250 can be a wired communication port or a wireless communication port.

[0055] Storage medium 230 may include a data storage device. The data storage device may be a non-transitory storage medium or a temporary storage medium. For example, the data storage device may include one or more of a disk 232, a read-only storage medium (ROM) 234, or a random access storage medium (RAM) 235. Storage medium 230 also includes at least one instruction set stored in the data storage device. The instruction set may include computer program code, which may include a program, routine, object, component, data structure, procedure, module, etc.

[0056] At least one processor 220 may be communicatively connected to at least one storage medium 230. When the computing device 200 is running, the at least one processor 220 reads the at least one instruction set and, according to the instructions of the at least one instruction set, executes the task processing method provided in this specification. The processor 220 may execute the steps included in the task processing method. The processor 220 may be in the form of one or more processors. In some embodiments, the processor 220 may include one or more hardware processors, such as a microcontroller, a microprocessor, a reduced instruction set computer (RISC), an application-specific integrated circuit (ASIC), an application-specific instruction set processor (ASIP), a central processing unit (CPU), a graphics processing unit (GPU), a physical processing unit (PPU), a microcontroller unit, a digital signal processor (DSP), a field programmable gate array (FPGA), an advanced RISC machine (ARM), a programmable logic device (PLD), any circuit or processor capable of performing one or more functions, or any combination thereof.

[0057] For illustrative purposes only, the computing device 200 shown in the accompanying drawings only has one processor 220. However, it should be noted that the computing device 200 described herein may also include multiple processors. Therefore, the operations and / or method steps disclosed herein may be performed by a single processor or jointly by multiple processors. For example, if the processor 220 of the computing device 200 is described herein as performing steps A and B, it should be understood that steps A and B may also be performed jointly or separately by two different processors 220 (e.g., a first processor performing step A and a second processor performing step B, or a first and a second processor performing steps A and B together).

[0058] Figure 3 FIG2 is a flowchart of a task processing method provided in accordance with an embodiment of the present specification. As mentioned above, the service device 11 can execute the task processing method provided in the present specification.

[0059] like Figure 3 As shown, the task processing method may include:

[0060] S310: Obtain multiple tasks to be processed.

[0061] In some embodiments, the multiple tasks to be processed may come from one user device or from multiple user devices. Figure 1 , user device 1, user device 2, and user device N can all respond to user operations and send tasks to the service device. The tasks sent by the user devices may include concurrent network requests, computing tasks, file processing and conversion tasks, or decomposable original tasks.

[0062] For example, a user device may access a target page in response to a user action and send a task to a service device via an interactive component on the target page. For example, some interactive components on the target page may provide the ability to claim or extract multiple electronic certificates. When the user device, in response to a user action, uses the interactive components on these target pages to claim or extract multiple electronic certificates, the user device may send multiple parallel network request tasks to the service device, each for claiming or extracting a single electronic certificate.

[0063] Alternatively, some interactive components on the target page can be used to upload files. In response to user operations, the user device can upload files (such as image files or text files) on the user device to the service device through the interactive component, and the service device can perform computing tasks on these files. For example, computing tasks may include image processing on image files, performing optical character recognition (OCR) on image files, or feature extraction based on text files.

[0064] In some embodiments, a service device may receive an original task from a user device and decompose the original task according to a preset task decomposition strategy to obtain multiple tasks to be processed. For example, after receiving the original task, the service device may first determine the task type corresponding to the original task, and then decompose the original task according to the decomposition strategy corresponding to the task type to obtain multiple tasks to be processed.

[0065] For example, when a user device responds to a user action and collects or extracts an electronic voucher through an interactive component on a target page, the user device can send an original task to the service device. The original task can be used to instruct the random collection of a specified number of electronic vouchers. Alternatively, the original task can be used to instruct the collection of a specified number of target electronic vouchers. In this case, the original task corresponds to a concurrent request type task. The service device can disassemble the original task based on the disassembly strategy corresponding to the concurrent request type task to obtain multiple tasks. Each task can collect or extract an electronic voucher when executed.

[0066] For example, when a user device responds to a user action by uploading an image file through an interactive component on a target page and then has the service device perform OCR on the image file, the original task can be used to instruct the service device to perform OCR on the image file. In this case, the original task corresponds to a computational task. The service device can split the image file into multiple sub-images at a preset granularity and, based on the decomposition rules corresponding to computational tasks, decompose the original task into multiple tasks, each corresponding to the OCR of a sub-image.

[0067] S320: Execute multiple tasks through the thread pool, wherein, for any target task among the multiple tasks, the execution process of the target task includes: determining a target thread for the target task to be executed in the thread pool, updating the thread name of the target thread based on the task name of the target task so that the updated thread name has a corresponding relationship with the task name, and executing the target task through the target thread, and during the execution of the target task, determining the task monitoring data corresponding to the target task based on the running data of the target thread.

[0068] In some embodiments, the thread pool is an elastic thread pool, that is, the thread pool parameters corresponding to the thread pool can be adjusted according to actual needs. For example, the thread pool parameters may include the maximum number of threads in the thread pool and the upper limit of the number of core threads. The service device can predict the amount of resources that may be consumed by executing multiple tasks and adjust these two parameters based on the predicted amount of resources before executing multiple tasks through the thread pool; or, the service device can also adjust these two parameters according to the actual load when executing multiple tasks through the thread pool.

[0069] In some embodiments, the service device may first determine the predicted amount of resources required for multiple tasks and update thread pool parameters corresponding to the thread pool based on the predicted amount of resources and the amount of idle resources in the thread pool. The service device may then scale the thread pool based on the updated thread pool parameters during the execution of the multiple tasks.

[0070] In some embodiments, because tasks of the same type consume similar amounts of resources when executed, the service system can predict the amount of resources that may be consumed when processing multiple tasks based on the amount of system resources consumed when processing historical tasks corresponding to each task type. Task types may include CPU-intensive tasks, memory-intensive tasks, and network-intensive tasks. Alternatively, the service device may classify tasks based on other dimensions, which is not limited in this specification.

[0071] In some embodiments, the service device may first obtain the task types corresponding to each of the multiple tasks. Then, based on the task type of each task, the service device may obtain the historical resource consumption of at least one historical task of the same task type, and determine the predicted resource consumption corresponding to the task based on the historical resource consumption corresponding to the at least one historical task. Finally, the service device may use the sum of the predicted resource consumption of the multiple tasks as the predicted resource consumption required by the multiple tasks.

[0072] In some embodiments, when the service device executes each historical task, it can record and save the environmental parameters of the service device before the historical task is executed, the operating parameters of the service device when the historical task is executed, and the parameters of the thread pool when executing the task as corresponding historical monitoring data, and calculate the historical resource consumption of the historical task based on the historical monitoring data. Among them, the environmental parameters of the service device before the historical task is executed may include the idle rate of CPU resources, the idle amount of memory resources, the idle amount of network resources (such as the number of concurrent connections), etc.; the operating parameters of the service device when the historical task is executed may include the amount of CPU resources used when executing the historical task (i.e., the CPU usage of the task), the amount of memory resources used (i.e., the memory usage of the task), the number of concurrent connections used (i.e., the network usage of the task), etc.; the parameters when the thread pool executes the task may include the task execution time, task type, task priority, the thread type corresponding to the task, etc. As an example, the historical resource consumption of the historical task can be determined based on at least one parameter in the historical monitoring data. For example, the service device can use parameters such as CPU usage, memory usage, network usage, or task execution time alone to characterize the historical resource consumption of the historical task. Alternatively, the service device may also perform normalization based on CPU usage, memory usage, and network usage, and use the normalized parameters to represent the historical resource consumption of the historical tasks.

[0073] In some embodiments, the historical resource amount corresponding to the historical task can be calculated according to the following formula, namely:

[0074]

[0075] Among them, Res cost Cost is the amount of historical resources consumed by historical tasks. i is the usage of the i-th type of resource when executing the task, α i is the normalized weight coefficient of the i-th resource. For example, when i=1, it can represent CPU usage, when i=2, it can represent memory usage, and when i=3, it can represent network usage. i It can be configured according to the task type. For example, for CPU-intensive tasks, it can be set as follows: α1 = 0.6, α2 = 0.2, α3 = 0.2; for memory-intensive tasks, it can be set as follows: α1 = 0.2, α2 = 0.6, α3 = 0.2; for network-intensive tasks, it can be set as follows: α1 = 0.2, α2 = 0.2, α3 = 0.6.

[0076] In some embodiments, for each task, the predicted amount of resources required to be consumed by the task is obtained through any of the following operations: the service device determines the predicted amount of resources corresponding to the task based on the average of the historical amounts of resources corresponding to at least one historical task; or the service device uses the historical amount of resources corresponding to at least one historical task as an example sample, and guides the target model to perform example learning based on the example sample to determine the predicted amount of resources corresponding to the task.

[0077] As an example, for a task to be processed, the service device can obtain the historical monitoring data corresponding to each of the corresponding multiple historical tasks according to the task type corresponding to the task to be processed. The service device can normalize the CPU usage, memory usage, and network usage in each historical monitoring data to obtain the amount of resources consumed by the historical task. Finally, the service device can determine the average of the amount of resources consumed by each of the multiple historical tasks as the predicted amount of resources required for the task to be processed.

[0078] In some embodiments, the service device can predict the resource consumption required for a pending task by guiding the target model to perform case learning based on the resource consumption corresponding to multiple historical tasks. As an example, referring to the above example, the service device can use the resource consumption of the task as the target (i.e., the output of the model), and the environmental parameters of the service device before the task is executed as the condition (i.e., the input of the model), and generate multiple example samples based on multiple historical monitoring data.

[0079] For example, the service device can first normalize the CPU usage, memory usage, and network usage in historical monitoring data to obtain the historical resource consumption of the historical task. The service device can then generate an example sample based on the historical resource consumption of the historical task and the environmental parameters of the service device before the historical task was executed. Finally, the service device can input multiple example samples and the environmental parameters of the service device before the execution of the pending task into the target model, and guide the target model to perform example learning based on the multiple example samples and make predictions based on the environmental parameters of the service device before the execution of the pending task, to obtain the predicted resource consumption required for the pending task.

[0080] In this embodiment, the service device can predict the amount of resources required for multiple tasks to be processed based on historical monitoring data, and can more accurately determine the amount of resources that may be consumed by multiple tasks to be processed during execution, and then accurately expand or shrink the thread pool, accurately allocate thread pool resources, alleviate sudden load pressure, and avoid system jitter.

[0081] In some embodiments, based on the predicted amount of resources and the amount of idle resources in the thread pool, the thread pool parameters corresponding to the thread pool are updated, including: when the predicted amount of resources is greater than the amount of idle resources in the thread pool, increasing the number of core threads, or increasing the maximum number of threads in the thread pool; when the predicted amount of resources is less than the amount of idle resources in the thread pool, reducing the number of core threads, or reducing the maximum number of threads in the thread pool.

[0082] Among them, the thread pool can include multiple pre-created core threads, which will continuously process tasks received by the service device. When the core threads are fully loaded (that is, each core thread is executing tasks), the service device can add the newly received tasks to the task queue of the thread pool and wait for execution.

[0083] As an example, referring to the method of calculating the amount of resources consumed by a task, the amount of idle resources in the thread pool can be calculated according to the following formula, namely:

[0084]

[0085] Among them, Res available The amount of idle resources in the thread pool, Thread ij is the idle resource amount of the i-th type of resource corresponding to core thread j, α ij is the normalized weight coefficient of the i-th resource corresponding to core thread j. The configuration method of α is the same as that used to calculate the amount of resources consumed by the task, and will not be repeated here.

[0086] Figure 4 A schematic diagram of adjusting thread pool parameters according to an embodiment of this specification is shown.

[0087] In some embodiments, reference Figure 4 The service device can compare the amount of idle resources in the thread pool with the predicted amount of resources required for multiple tasks. When the amount of idle resources in the thread pool is less than the predicted amount (i.e., expansion is required), the service device can first obtain the number of core threads and determine whether the number of core threads corresponding to the thread pool has reached the maximum value. If not, the service device can increase the upper limit of the number of core threads corresponding to the thread pool; if it has been reached, the service device can increase the maximum number of threads corresponding to the thread pool. The maximum number of core threads is set when the service device creates the thread pool, and the maximum number of core threads can be determined based on the number of cores in the service device's CPU.

[0088] When the amount of idle resources in the thread pool is greater than the predicted amount of resources (i.e., it needs to be scaled down), the service device can determine whether there are non-core threads in the thread pool. If so, the service device can reduce the maximum number of threads corresponding to the thread pool when the number of idle threads is greater than the first preset threshold, so that the thread pool automatically destroys non-core threads. If not, the service device can destroy the core threads whose life cycle has timed out when the number of idle threads is greater than the second preset threshold, and reduce the upper limit of the number of core threads corresponding to the thread pool. Among them, the first preset threshold and the second preset threshold are set when the service device creates the thread pool. The values of these two parameters can be adjusted according to the needs of actual applications, and this manual does not impose any restrictions on this.

[0089] In this embodiment, the service device obtains the predicted amount of resources required for multiple tasks, and then dynamically updates the thread pool parameters based on the real-time idle resources in the thread pool, and adaptively scales the thread pool before executing the task. By adaptively scaling the thread pool in advance based on the predicted amount of resources that may be consumed, the thread pool resource allocation can be accurately matched to task requirements, reducing resource vacancy or competition and improving throughput efficiency. Through the elastic scaling mechanism, the service device can alleviate sudden load pressure and avoid system jitter, thereby significantly improving the stability of the service device in high-concurrency scenarios, while reducing manual intervention and operation and maintenance costs through automated resource management.

[0090] In some embodiments, each thread in the thread pool corresponds to a task type. For example, the service device may divide the threads in the thread pool into multiple thread groups, with the threads in each thread group corresponding to a task type. The service device may determine a target thread in the thread pool based on the task type to which the target task belongs, where the task type corresponding to the target thread is the same as the task type to which the target task belongs.

[0091] In some embodiments, the service device can match in the thread pool according to the task type corresponding to the target task, and when a thread with the same task type and being idle is matched, the thread with the same task type and being idle is determined to be the target thread; when a thread with the same task type and being idle is not matched, the task type of the idle thread in the thread pool is updated according to the task type corresponding to the target task, and the updated thread is determined to be the target thread; and when there is no idle thread in the thread pool, if the number of threads in the thread pool is less than the maximum number of threads, a target thread is created in the thread pool according to the task type corresponding to the target task.

[0092] In some embodiments, the service device may determine the corresponding thread group based on the task type to which the target task belongs, and when there are idle threads in the thread group, determine any one of the idle threads as the target thread. Alternatively, when there are no idle threads in the thread group, the service device may update the task type (i.e., thread group) of the idle threads in other thread groups to the task type (i.e., thread group) corresponding to the target task, and then determine the updated thread as the target thread. Alternatively, when there are no idle threads in the thread group, if the number of threads in the thread pool is less than the maximum number of threads in the thread pool, the service device may create a target thread in the thread group.

[0093] Figure 5 A schematic diagram of determining a target thread according to a target task provided in an embodiment of this specification is shown.

[0094] refer to Figure 5 When the task type of the target task is task type A, its corresponding thread group is thread group 1, and there is an idle thread (thread 1) in thread group 1, the service device can determine thread 1 as the target thread.

[0095] When the task type of the target task is task type C, its corresponding thread group is thread group 3, and there is no idle thread in thread group 3, then the service device can change the task type of the idle thread (thread 4) in thread group 2 to task type C, that is, move thread 4 from thread group 2 to thread group 3, and then the service device can determine thread 4 as the target thread.

[0096] Alternatively, assuming that all threads in the thread pool are busy, when the task type of the target task is task type A, the service device can create a thread 10 belonging to thread group 1 and having a task type of task type A, and determine thread 10 as the target thread.

[0097] In some embodiments, the updated thread name has a corresponding relationship with the task name, which means that the specific task name can be accurately located through the thread name. As an example, the task name can include the task name and the identifier of the task source. Among them, the task name can be generated according to the preset task naming rules. For example, the task name can reflect the task type, the original task corresponding to the task, and the serial number corresponding to the task. The identifier of the task source can be the identification identifier of the device that initiated the task, the identification identifier of the account logged in on the device that initiated the task, etc.

[0098] In some embodiments, the updated thread name is the same as the task name. For example, the service device may directly use the task name as the updated thread name.

[0099] Alternatively, the updated thread name contains a substring that is identical to the task name. For example, a thread name may include multiple fields, such as a thread pool identifier field, a thread group identifier field, and a thread identification field. The service device updates the task name to the thread identification field and then uses the resulting thread name as the updated thread name.

[0100] Alternatively, the service device may generate a unique identification identifier based on the task name, update the unique identification identifier into the thread identification field, and then use the obtained thread name as the updated thread name.

[0101] Figure 6 A schematic diagram of executing a target task through a thread pool according to an embodiment of this specification is shown.

[0102] refer to Figure 5 and Figure 6 Assuming that the target task's task name is "target task 1" and the service device executes the target task through "thread pool 1", the service device can determine that the target thread is thread 1 in thread group 1 in thread pool 1 based on the task type of the target task. The thread name of the target thread can be: thread pool 1-thread group 1-thread 1-xxxxx, where "thread pool 1" is the thread pool identification field, "thread group 1" is the thread group identification field, and "thread 1-xxxxx" is the thread identification field. The service device can update the thread identification field based on the target task's task name "target task 1", add the target task's task name to the field, and obtain the updated thread identification field "thread 1-target task 1", that is, the updated thread name is: thread pool 1-thread group 1-thread 1-target task 1.

[0103] In some embodiments, the service device can assign the target task to the target thread in the thread pool for execution through the Callable class. The Callable class corresponds to a task that may return a result, and this task may throw an exception. For example, the target task specified and executed through the Callable class can return the execution result of the target task, such as execution failure or execution completion. When an execution failure occurs, the exception information corresponding to the target task will also be thrown. The service device can wrap the Callable through the FutureTask class and implement asynchronous execution of concurrent tasks. That is, the service device can use FutureTask to distribute the multiple tasks received to each thread in the thread pool for execution based on the Callable class, and receive the results returned by the Callable class and the exceptions thrown.

[0104] In some embodiments, to monitor the execution of a target task, the service device needs to obtain task monitoring data corresponding to the target task. To this end, the service device can customize the FutureTask and Callable classes so that they can assign a task name to the target task at runtime and obtain the target thread's running data based on the task name to determine the task monitoring data corresponding to the target task.

[0105] As an example, the name of the customized FutureTask class is FutureWithNameAndTime, and the name of the customized Callable class is CallableWithNameAndTime.

[0106] The following provides a code for creating tasks based on FutureWithNameAndTime and CallableWithNameAndTime:

[0107] public class FutureWithNameAndTime <v>extends FutureTask <v>{

[0108] private String name;

[0109] private CallableWithNameAndTime <v>callable;

[0110] public FutureWithNameAndTime(Callable <v>callable,String name){

[0111] super(callable);

[0112] this.callable=(CallableWithNameAndTime <v>)callable;

[0113] this.name = name;

[0114] }

[0115] Among them, "public class FutureWithNameAndTime <v>extends FutureTask <v>"Used to declare a class and configure a public "FutureWithNameAndTime" custom class. This "FutureWithNameAndTime" is a subclass of "FutureTask" and inherits (extends) all non-private properties and methods of the parent class (FutureTask) and has the same generic parameters as the parent class." <v>”.

[0116] "private String name" is used to define a string that is used to store the task name "name".

[0117] "private CallableWithNameAndTime <v>The "callable" field is defined in "callable", which indicates calling "CallableWithNameAndTime". "CallableWithNameAndTime" is a subclass of "Callable". It adds the function of recording task name and time based on the original Callable.

[0118] "public FutureWithNameAndTime(Callable <v>callable,String name)" indicates that a "FutureWithNameAndTime" method is constructed. The name of the construction method must be consistent with the class name. When this construction method is called, the service device will create a new object of the "FutureWithNameAndTime" class. The "FutureWithNameAndTime" method includes two parameters "Callable <v>"callable" and "Stringname", "Callable" <v>" is a functional interface that can receive a Callable <v>object (i.e. passing in a task), and "String name" is used to record the name of the passed in task.

[0119] "super(callable)" is used to call the parent class FutureTask <v>The constructor of the function passes the pre-defined "callable" to the parent class to execute the task passed in the "callable".

[0120] "this.callable=(CallableWithNameAndTime <v>)callable" is used to receive the Callable <v>Object converted to CallableWithNameAndTime <v>And store it in callable.

[0121] "this.name=name" is used to store the task name of the incoming task into the "name" string.

[0122] In some embodiments, the code of the thread pool includes burying code corresponding to the burying event. When the service device detects that the target thread triggers a preset burying event, it can collect the running data of the target thread by executing the burying code corresponding to the burying event; and determine the task monitoring data corresponding to the target task based on the running data of the target thread.

[0123] In some embodiments, referring to the above code example, when the task in "callable" is executed, the tracking event may include starting to execute the task, the returned result indicating that the task is completed, or the returned result indicating that the task is abnormal. The tracking code corresponding to the tracking event can be the code in "CallableWithNameAndTime" related to obtaining the running data of the target thread. As an example, the running data of the target thread may include the system load of the system to which the target thread belongs and the timestamp related to the tracking event, wherein the system load may include the CPU occupancy rate, the running memory occupancy rate, etc.

[0124] In some embodiments, the service device can record the corresponding task monitoring data of the target task in the operation log based on the mapping relationship between the target task and the target thread according to the operation data of the target thread. The task monitoring data corresponding to the target task includes at least one of the following: the start execution time of the target task, the end execution time of the target task, the processing time of the target task; or abnormal information during the execution of the target task. For example, refer to Figure 6 In the process of executing target task 1 through the target thread, the service device can obtain the running data of the target thread, and then record the task monitoring data corresponding to target task 1 in the running log according to the running data of the target thread.

[0125] As an example, when the tracking event is the start of task execution, the service device can use the tracking code to record the timestamp of the start of the target task; when the tracking event is the returned result indicating task completion, the service device can use the tracking code to record the timestamp of the end of the target task; when the tracking event is the returned result indicating task abnormality, the service device can use the tracking code to record the timestamp of the target task abnormality. Then, the service device can use the time corresponding to the timestamp of the start of the target task as the start execution time of the target task, the time corresponding to the timestamp of the end of the target task as the end execution time of the target task, and the time difference between the start execution time of the target task and the end execution time of the target task as the processing duration of the target task. The abnormal information during the execution of the target task can include the abnormal time and abnormal content. The abnormal time can be determined by the timestamp of the target task abnormality, and the abnormal content can be determined according to CallableWithNameAndTime <v>The content of the exception thrown when an exception occurs in the target task is determined.

[0126] In this embodiment, since the monitoring data corresponding to the target task establishes a mapping relationship between the target task and the target thread according to the name of the target task when recording, when an exception occurs in the execution of the target task, the operation and maintenance personnel can quickly locate the target task and target thread where the exception occurs based on the mapping relationship between the target task and the target thread, which can significantly reduce the complexity and time cost of fault location, improve the efficiency of exception response and diagnostic accuracy, and enhance the fault tolerance and service stability of the distributed system.

[0127] In some embodiments, the threads of the thread pool include core threads and non-core threads. In the process of processing multiple tasks to be processed through the thread pool, when the load of the thread pool meets the preset expansion conditions, the service device can create at least one thread in the thread pool based on the updated thread pool parameters to expand the thread pool; when the load of the thread pool meets the preset reduction conditions, the service device can destroy at least one thread in the thread pool based on the updated thread pool parameters to reduce the thread pool.

[0128] In some embodiments, the load of the thread pool may include the number of tasks in the task queue of the thread pool of the thread pool, or the corresponding processor usage of the thread pool and the idle time of the threads in the thread pool. When the service device processes multiple tasks to be processed through the thread pool, since the number of tasks may change at any time, the load of the thread pool will also change accordingly. When the load of the thread pool is high, the thread pool can be dynamically expanded to increase the processing capacity of the thread pool. When the load of the thread pool is low, the thread pool can be dynamically reduced to reduce the resource consumption of the service device.

[0129] In some embodiments, when the load of the thread pool is the number of tasks in the task queue of the thread pool, satisfying the preset expansion condition includes: the number of tasks being greater than a preset task number threshold. When the number of tasks in the task queue of the thread pool accumulates excessively, indicating a high load on the thread pool, the service device may expand the thread pool, i.e., create at least one new thread in the thread pool.

[0130] In some embodiments, the service device may create at least one thread in the thread pool when the number of core threads in the thread pool is less than the upper limit of the number of core threads corresponding to the thread pool, or the number of core threads in the thread pool is equal to the upper limit of the number of core threads but less than the maximum number of threads corresponding to the thread pool.

[0131] In some embodiments, each task includes a corresponding task priority, and the threads in the thread pool include corresponding thread priorities. The service device can preferentially assign high-priority tasks to threads with higher priorities in the thread pool for execution. Therefore, when the service device creates a new thread in the thread pool, it can also consider preferentially creating the thread with higher priority, so as to give priority to processing high-priority tasks in the task queue.

[0132] In some embodiments, when the number of core threads in the thread pool is less than the upper limit of the number of core threads corresponding to the thread pool, the service device can create at least one core thread based on the task name or task priority of at least one task in the task queue of the thread pool, and the thread name of the created core thread has a corresponding relationship with the task name of the task, or the thread priority of the created core thread is the same as the task priority of the target task.

[0133] As an example, the service device can monitor the number of tasks in the thread pool task queue. When the number of tasks reaches a preset task number threshold, at least one core thread is created when the number of core threads is less than the upper limit of the number of core threads corresponding to the thread pool, wherein the preset task number threshold can be 80%, 90% or 95% of the maximum number of tasks in the task queue. When the service device creates a core thread, it can first obtain the priority corresponding to each task in the task queue. If there is a high-priority task, the service device can create a core thread of the corresponding priority to give priority to the high-priority task. If the priorities of the tasks in the task queue are the same, the service device can create a core thread in order according to the task name of the first task in the task queue, and process the task based on the created core thread.

[0134] In some embodiments, when the number of core threads in the thread pool is equal to the upper limit of the number of core threads but less than the maximum number of threads corresponding to the thread pool, the service device can create at least one non-core thread based on the task name or task priority of at least one task in the task queue of the thread pool, and the thread name of the created non-core thread has a corresponding relationship with the task name of the task, or the thread priority of the created non-core thread is the same as the task priority of the target task.

[0135] Referring to the above example, when the number of tasks in the thread pool task queue reaches the preset task threshold, the service device can create at least one non-core thread if the number of core threads is equal to the upper limit of the core thread number but less than the maximum number of threads in the thread pool. The service device's logic for creating non-core threads is the same as that for creating core threads and is not further explained here.

[0136] In some embodiments, the corresponding processor usage of the thread pool and the idle time of the threads in the thread pool are used as the load of the thread pool. Meeting the preset shrinkage conditions includes: the number of threads in the thread pool is greater than the preset thread number threshold; and the corresponding processor usage of the thread pool is less than or equal to the preset usage threshold, or there are threads in the thread pool whose idle time is greater than or equal to the preset time threshold.

[0137] Among them, the preset thread number threshold is the minimum number of threads that need to be maintained in the thread pool. Since the creation and destruction of threads require a certain amount of resources, a certain number of threads need to be maintained in each thread pool in order to respond to received tasks in a timely manner. When the service device shrinks the thread pool, it also needs to ensure that the number of threads in the thread pool is not less than the preset thread number threshold, that is, when the number of threads in the thread pool is greater than the preset thread number threshold, the service device can perform the shrinking operation. When the number of threads in the thread pool is equal to the preset thread number threshold, the service device will stop the shrinking operation.

[0138] As an example, after determining that the thread pool meets the preset scaling-down condition, the service device may destroy at least one thread in the thread pool. For example, when the number of threads in the thread pool exceeds the upper limit of the number of core threads corresponding to the thread pool, the service device may destroy at least one non-core thread.

[0139] It should be noted that the service device generally does not destroy the core thread. However, when the service device detects the timeout of the core thread, if the core thread is idle, the timed-out idle core thread may be destroyed to further reduce the resource consumption of the service device.

[0140] In this embodiment, the service device can dynamically expand or shrink the thread pool through multi-dimensional load indicators. When expanding, the service device can dynamically adjust the number of core threads and non-core threads according to the load status of the thread pool, thereby achieving elastic resource management and efficient task scheduling in high-concurrency scenarios, further alleviating sudden load pressure, avoiding system jitter, and improving the stability of the service device in high-concurrency scenarios.

[0141] In some embodiments, when the multiple tasks to be processed are obtained by the service device by disassembling the original task, after executing the multiple tasks through the thread pool, the service device can also obtain the execution results corresponding to the multiple tasks, and aggregate the execution results corresponding to the multiple tasks to obtain the processing results of the original task.

[0142] By breaking down the original task into multiple tasks for processing and then aggregating the execution results of each task after processing to obtain the processing result of the original task, the concurrent processing capabilities of the thread pool can be effectively utilized, improving the utilization rate of computing resources. Moreover, when an exception occurs in multiple tasks, the service device can retry only the task with the exception, rather than retrying the entire original task, providing a more efficient means of troubleshooting the exception and providing a more effective and stable task processing method for high-concurrency scenarios such as microservices, distributed computing, and batch processing.

[0143] In some embodiments, an SDK is deployed in the service device, and multiple tasks are executed through a thread pool, including: calling the SDK, and executing multiple tasks through a thread pool based on the SDK; obtaining the execution results corresponding to each of the multiple tasks, including: obtaining the execution results corresponding to each of the multiple tasks based on the SDK.

[0144] As an example, operations such as thread pool configuration, thread pool expansion, and thread pool reduction in the above examples can all be implemented by calling pre-defined classes in the SDK. For example, a service device can customize the thread factory (ThreadFactory) to obtain a custom class "NameableThreadFactory" to implement functions such as creating a target thread with a specific name in the thread pool, changing the name of the target thread, and configuring the target thread's thread group.

[0145] In some embodiments, the service device can also customize the elastic thread pool manager "StandardThreadExecutorWithNameAndTime". The elastic thread pool manager can call "NameableThreadFactory" to manage the thread pool, such as implementing the above-mentioned dynamic expansion and contraction of the thread pool based on the thread pool load.

[0146] In this embodiment, the deployed SDK provides functions such as thread pool configuration, thread pool expansion, thread pool reduction, creation of target threads with specific names, change of target thread names, and configuration of target thread thread groups. It also provides a quick call to the elastic thread pool manager. Developers can quickly deploy corresponding thread pools for concurrent scenarios by calling the SDK, effectively reducing the complexity of thread pool configuration for concurrent scenarios, shortening the development cycle, and improving development efficiency.

[0147] In summary, in the task processing method and service system provided in this specification, the server constructs a mapping relationship between the task and the execution thread by assigning the target task to the target thread for execution, and updating the thread name of the target thread according to the task name during the execution process. Based on this mapping relationship, the server can convert the running status data of the target thread collected in real time into task monitoring data corresponding to the target task. The solution in this specification provides a task dimension monitoring mechanism for the thread pool, through which the refined monitoring capability of the task dimension is realized. When an exception occurs in the execution of the target task, the operation and maintenance personnel can quickly locate the target task and target thread where the exception occurs based on the mapping relationship between the target task and the target thread, which can significantly reduce the complexity and time cost of fault location, improve the efficiency of exception response and diagnostic accuracy, and enhance the fault tolerance and service stability of the distributed system.

[0148] Another aspect of this specification provides a computer-readable, non-transitory storage medium storing at least one instruction set for processing a received task. When the at least one instruction set is executed by a processor, the at least one instruction set directs the processor to implement the steps of the task processing method described in this specification. In some possible implementations, various aspects of this specification may also be implemented in the form of a program product comprising program code. When the program product is executed on a computing device 200, the program code is used to cause the computing device 200 to perform the steps of the task processing method described in this specification. The program product for implementing the above method may include the program code in a portable compact disc read-only memory (CD-ROM) and may be executed on the computing device 200. However, the program product of this specification is not limited to this. In this specification, a readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system. The program product may utilize any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or any combination thereof. More specific examples of computer-readable storage media include: an electrical connection having one or more conductors, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. The computer-readable storage medium may include a data signal propagated in baseband or as part of a carrier wave, which carries readable program code. Such a propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. The computer-readable storage medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing. Program code for performing the operations described herein may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, and conventional procedural programming languages such as C or similar programming languages. The program code may execute entirely on the computing device 200, partially on the computing device 200, as a stand-alone software package, partially on the computing device 200 and partially on a remote computing device, or entirely on the remote computing device.

[0149] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the particular order or sequential order shown to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0150] In summary, after reading this detailed disclosure, those skilled in the art will appreciate that the foregoing detailed disclosure may be presented by way of example only and may not be limiting. Although not expressly stated herein, those skilled in the art will understand that this specification encompasses various reasonable changes, improvements, and modifications to the embodiments. Such changes, improvements, and modifications are intended to be suggested by this specification and are within the spirit and scope of the exemplary embodiments of this specification.

[0151] Furthermore, certain terms in this specification have been used to describe embodiments of this specification. For example, "one embodiment," "an embodiment," and / or "some embodiments" mean that a particular feature, structure, or characteristic described in connection with that embodiment may be included in at least one embodiment of this specification. Therefore, it is emphasized and should be understood that two or more references to "an embodiment," "one embodiment," or "an alternative embodiment" in various parts of this specification do not necessarily refer to the same embodiment. Furthermore, particular features, structures, or characteristics may be appropriately combined in one or more embodiments of this specification.

[0152] It should be understood that in the foregoing descriptions of the embodiments of this specification, to facilitate understanding of a feature and to simplify this specification, various features are combined in a single embodiment, figure, or description thereof. However, this does not necessarily mean that these features are combined. When reading this specification, a person skilled in the art may label some of the devices as separate embodiments. In other words, the embodiments of this specification can also be understood as the integration of multiple sub-embodiments. The content of each sub-embodiment is also valid even when it includes fewer than all the features of a single previously disclosed embodiment.

[0153] Each patent, patent application, patent application publication, and other materials, such as articles, books, specifications, publications, documents, articles, and the like, cited herein, except to the extent that it is inconsistent or conflicting with this document or that it has a limiting effect on the broadest scope of the claims, is hereby incorporated by reference for all purposes now or hereafter connected with this document. In addition, in the event of any inconsistency or conflict between the description, definition, and / or use of a term in any material and the description, definition, and / or use of a term in this document, the term in this document shall control.

[0154] Finally, it should be understood that the embodiments of the application disclosed herein are illustrative of the principles of the embodiments of this specification. Other modified embodiments are also within the scope of this specification. Therefore, the embodiments disclosed in this specification are merely examples and not limitations. Those skilled in the art can adopt alternative configurations based on the embodiments in this specification to implement the application in this specification. Therefore, the embodiments of this specification are not limited to the embodiments precisely described in the application.< / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v> < / v>

Claims

1. A task processing method, applied to a server configured with a thread pool, comprising: Get multiple tasks to be processed; as well as The plurality of tasks are executed by the thread pool, wherein, for any target task among the plurality of tasks, the execution process of the target task includes: Determine a target thread to execute the target task in the thread pool, updating the thread name of the target thread based on the task name of the target task so that the updated thread name corresponds to the task name, and The target task is executed by the target thread, and during the execution of the target task, Task monitoring data corresponding to the target task is determined based on the running data of the target thread.

2. The method according to claim 1, wherein The thread pool code includes the tracking code corresponding to the tracking event, and determines the task monitoring data corresponding to the target task based on the running data of the target thread, including: When detecting that the target thread triggers a preset tracking event, collecting the running data of the target thread by executing the tracking code corresponding to the tracking event; and Task monitoring data corresponding to the target task is determined based on the running data of the target thread.

3. The method according to claim 2, wherein: The task monitoring data corresponding to the target task includes at least one of the following: The start time of execution of the target task; The end execution time of the target task; The processing time of the target task; or Exception information during the execution of the target task.

4. The method according to claim 1, wherein The updated thread name is the same as the task name, or The updated thread name contains a substring that is identical to the task name.

5. The method according to claim 1, wherein Each thread in the thread pool corresponds to a task type, and determining a target thread to execute the target task in the thread pool includes: According to the task type to which the target task belongs, the target thread is determined in the thread pool, and the task type corresponding to the target thread is the same as the task type to which the target task belongs.

6. The method according to claim 5, wherein: Determining the target thread in the thread pool includes: Matching the target task in the thread pool according to the task type corresponding to the target task, and when matching a thread with the same task type and an idle thread, determining the thread with the same task type and an idle thread as the target thread; When no idle thread with the same task type is matched, updating the task type of the idle threads in the thread pool according to the task type corresponding to the target task, and determining the updated thread as the target thread; and When there are no idle threads in the thread pool, if the number of threads in the thread pool is less than the maximum number of threads, the target thread is created in the thread pool according to the task type corresponding to the target task.

7. The method according to claim 1, wherein Before executing the plurality of tasks through the thread pool, the method further includes: determining a predicted amount of resources required to be consumed by the plurality of tasks, and updating thread pool parameters corresponding to the thread pool based on the predicted amount of resources and an amount of idle resources of the thread pool; and During the execution of the multiple tasks, the method further includes: scaling the thread pool based on the updated thread pool parameters.

8. The method according to claim 7, wherein: Determining the predicted amount of resources required to be consumed by the multiple tasks includes: Obtaining the task type corresponding to each of the multiple tasks; According to the task type of each task, obtaining the historical resource amount consumed by at least one historical task of the same task type, and determining the predicted resource amount corresponding to the task based on the historical resource amount corresponding to the at least one historical task; and The sum of the predicted resource amounts corresponding to the multiple tasks is used as the predicted resource amount required to be consumed by the multiple tasks.

9. The method according to claim 8, wherein The determining, based on the historical resource amount corresponding to the at least one historical task, the predicted resource amount corresponding to the task includes: Determining the predicted resource amount corresponding to the task according to the average of the historical resource amounts corresponding to the at least one historical task; or The historical resource amount corresponding to the at least one historical task is used as an example sample, and the target model is guided to perform example learning based on the example sample to determine the predicted resource amount corresponding to the task.

10. The method according to claim 7, wherein: The updating of thread pool parameters corresponding to the thread pool based on the predicted resource amount and the idle resource amount of the thread pool includes: When the predicted resource amount is greater than the idle resource amount of the thread pool, increasing the upper limit of the number of core threads corresponding to the thread pool, or increasing the maximum number of threads corresponding to the thread pool; When the predicted resource amount is less than the idle resource amount of the thread pool, the upper limit of the number of core threads corresponding to the thread pool is reduced, or the maximum number of threads corresponding to the thread pool is reduced.

11. The method according to claim 7, wherein: The threads in the thread pool include core threads and non-core threads, and the thread pool is expanded or reduced based on the updated thread pool parameters, including: When the load of the thread pool meets a preset expansion condition, creating at least one thread in the thread pool based on the updated thread pool parameters to expand the thread pool; or When the load of the thread pool meets a preset shrinking condition, at least one thread in the thread pool is destroyed based on the updated thread pool parameters to shrink the thread pool.

12. The method according to claim 11, creating at least one thread in the thread pool based on the updated thread pool parameters, comprising: When the number of core threads in the thread pool is less than the upper limit of the number of core threads corresponding to the thread pool, or the number of core threads in the thread pool is equal to the upper limit of the number of core threads but less than the maximum number of threads corresponding to the thread pool, at least one thread is created in the thread pool.

13. The method according to claim 11, wherein The load of the thread pool includes: the corresponding processor usage of the thread pool and the idle time of the threads in the thread pool; The preset shrinking condition includes at least one of the following: The number of threads in the thread pool is greater than the preset thread number threshold, The processor usage corresponding to the thread pool is less than or equal to a preset usage threshold, or There are threads in the thread pool whose idle time is greater than or equal to a preset time threshold.

14. The method according to claim 11, wherein The load of the thread pool includes: the number of tasks in the task queue of the thread pool; The preset expansion conditions include: The number of tasks is greater than a preset task number threshold.

15. The method according to claim 11, wherein The destroying at least one thread in the thread pool based on the updated thread pool parameters includes: When the number of threads in the thread pool is greater than an upper limit of the number of core threads corresponding to the thread pool, at least one non-core thread is destroyed.

16. The method according to claim 1, wherein The obtaining of multiple tasks to be processed includes: Receiving an original task and decomposing the original task according to a preset task decomposition strategy to obtain the multiple tasks; After executing the plurality of tasks through the thread pool, the method further includes: Obtaining execution results corresponding to each of the multiple tasks; and Aggregate the execution results corresponding to the multiple tasks to obtain the processing result of the original task.

17. A service system comprising: at least one storage medium storing at least one instruction set for processing the received task; as well as At least one processor is communicatively connected to the at least one storage medium, wherein when the service system is running, the at least one processor reads the at least one instruction set and implements the method according to any one of claims 1-16 according to the instructions of the at least one instruction set.

18. A computer-readable non-volatile storage medium, wherein: The computer-readable non-volatile storage medium stores at least one instruction set, and when the at least one instruction set is executed by at least one processor, the method according to any one of claims 1 to 16 is implemented.