Method for accelerating task execution, electronic device and storage medium

CN122884660APending Publication Date: 2026-10-09KE COM (BEIJING) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610953803.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-29
Publication Date
2026-10-09

AI Technical Summary

Technical Problem

但是,消费系统在处理大量的高并发任务时,存在如下问题:当单线程池阻塞时,所有任务需要在同一线程池内排队执行,这样会导致部分任务处理速度慢,从而降低整体吞吐量

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122884660A_ABST
    Figure CN122884660A_ABST
Patent Text Reader

Abstract

The present disclosure provides a method for accelerating task execution, an electronic device and a storage medium. The method for accelerating task execution comprises: receiving a plurality of tasks to be executed; obtaining a service identifier of each task to be executed; selecting a thread pool for each task to be executed from a plurality of thread pools based on the service identifier of each task to be executed; the thread pools corresponding to the tasks to be executed with the same service identifier are the same; routing each task to be executed to the corresponding thread pool; and executing the corresponding task to be executed in the thread pool.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to a method, electronic device, and storage medium for accelerating task execution. Background Technology

[0002] Currently, in fields such as e-commerce, consumer systems handle a large number of high-concurrency tasks using a single-threaded pool. However, when handling a large number of high-concurrency tasks, consumer systems suffer from the following problems: When the single-threaded pool is blocked, all tasks need to be queued and executed within the same thread pool, which can slow down the processing speed of some tasks, thereby reducing the overall throughput. When different tasks are executed serially, the consumer system cannot fully utilize multi-core and multi-threaded resources. The consumer system cannot automatically adjust and optimize based on real-time operating conditions, thus significantly degrading the user experience. Summary of the Invention

[0003] This disclosure provides a method, electronic device, and storage medium for accelerating task execution.

[0004] According to one aspect of this disclosure, a method for accelerating task execution is provided, comprising: Receive multiple tasks to be executed; obtain the service identifier of each task to be executed; select a thread pool from multiple thread pools for each task to be executed based on the service identifier of each task to be executed; the task to be executed with the same service identifier corresponds to the same thread pool; route each task to be executed to the corresponding thread pool; execute the corresponding task to be executed in the thread pool.

[0005] According to at least one embodiment of this disclosure, the thread pool is coded; the service identifier is an order number or a user identifier; and selecting one thread pool from multiple thread pools for each task to be executed based on the service identifier of each task to be executed includes: For each task to be executed, obtain the hash value corresponding to the task to be executed; determine an intermediate result based on the hash value and the total number of thread pools; the intermediate result is calculated based on the hash value and the total number of thread pools, and the intermediate result is used to select a thread pool for the corresponding task to be executed; find the code that matches the intermediate result; and allocate the thread pool corresponding to the code that matches the intermediate result to the task to be executed.

[0006] According to at least one embodiment of this disclosure, obtaining the hash value corresponding to the task to be executed includes: if the service identifier of the task to be executed is empty, then the hash value of the task to be executed is a preset value; or if the service identifier of the task to be executed is not empty, then the service identifier of the task to be executed is calculated to obtain the hash value.

[0007] According to at least one embodiment of this disclosure, when the hash value is greater than or equal to a preset threshold, the hash value and the total quantity are calculated to obtain the intermediate result; when the hash value is less than the preset threshold, the absolute value of the hash value is obtained, and the absolute value of the hash value and the total quantity are calculated to obtain the intermediate result.

[0008] According to at least one embodiment of this disclosure, when the hash value is greater than or equal to a preset threshold, the intermediate result is obtained by calculating the hash value and the total quantity, including: performing a modulo calculation on the total quantity based on the hash value to obtain the intermediate result.

[0009] According to at least one embodiment of this disclosure, the method further includes: executing multiple tasks to be executed in the same thread pool one by one in a preset order; and executing multiple tasks to be executed in different thread pools in parallel.

[0010] According to at least one embodiment of this disclosure, the method further includes: packaging the task to be executed before execution to obtain a packaged task to be executed; obtaining context information corresponding to the packaged task to be executed and storing the context information in the packaged task to be executed; the context information includes at least a request identifier, a user identifier, and a tracing identifier; restoring the context information to the log of the thread corresponding to the packaged task to be executed when executing the packaged task to be executed; and cleaning up the context information after the packaged task to be executed has finished.

[0011] According to at least one embodiment of this disclosure, the method further includes: for each completed task, collecting a set of parameters for the completed task; the set of parameters includes at least one of execution time, exception frequency, and queue length; adjusting operating parameters or issuing an alarm based on the set of parameters; the operating parameters include at least one of the execution priority of the task to be executed, load balancing, and the number of threads in the thread pool corresponding to the completed task, wherein the business identifier of the task to be executed is the same as the business identifier of the completed task.

[0012] According to at least one embodiment of this disclosure, adjusting the running parameters based on the parameter set includes: when the execution time is greater than a first execution time threshold and the queue length is greater than a first queue length threshold, increasing the number of core threads and the maximum number of threads in the thread pool corresponding to the completed task; or when the exception frequency is greater than a first exception frequency threshold and the queue length is greater than the first queue length threshold, reducing the execution priority of tasks to be executed that have the same business identifier as the completed task; or when the queue length is less than a second queue length threshold and the execution time is less than a second execution time threshold, decreasing the number of core threads in the thread pool corresponding to the completed task.

[0013] According to another aspect of this disclosure, an electronic device is provided, comprising: a memory storing execution instructions; and a processor executing the execution instructions stored in the memory, causing the processor to perform a method for accelerating task execution according to any embodiment of this disclosure.

[0014] According to another aspect of this disclosure, a readable storage medium is provided that stores executable instructions, which, when executed by a processor, are used to implement a method for accelerating task execution according to any embodiment of this disclosure. Attached Figure Description

[0015] The accompanying drawings illustrate exemplary embodiments of the present disclosure and, together with the description thereof, serve to explain the principles of the present disclosure. These drawings are included to provide a further understanding of the present disclosure and are incorporated in and constitute a part of this specification.

[0016] Figure 1 This is a schematic diagram of the overall process of a method for accelerating task execution according to one embodiment of the present disclosure.

[0017] Figure 2 This is a schematic flowchart of step S130 of one embodiment of the present disclosure.

[0018] Figure 3 This is a flowchart illustrating step S131 of one embodiment of the present disclosure.

[0019] Figure 4 This is a flowchart illustrating step S132 of one embodiment of the present disclosure.

[0020] Figure 5 This is a flowchart illustrating the processing of context information according to one embodiment of this disclosure.

[0021] Figure 6 This is a flowchart illustrating the parameter set for the completion of a task in one embodiment of this disclosure.

[0022] Figure 7 This is a schematic structural block diagram of an apparatus for accelerating task execution according to one embodiment of the present disclosure.

[0023] Figure 8 This is a schematic structural block diagram of an electronic device according to one embodiment of the present disclosure. Detailed Implementation

[0024] The present disclosure will now be described in further detail with reference to the accompanying drawings and examples. It should be understood that the specific examples described herein are for illustrative purposes only and are not intended to limit the scope of the disclosure. Furthermore, it should be noted that, for ease of description, only the parts relevant to the present disclosure are shown in the accompanying drawings.

[0025] It should be noted that, where there is no conflict, the embodiments and features described in this disclosure can be combined with each other. The technical solutions of this disclosure will now be described in detail with reference to the accompanying drawings and embodiments.

[0026] In related technologies, in scenarios driven by orders, messages, and events, consumption systems have at least the following problems.

[0027] Firstly, the overall throughput is low, and there is too much serial processing. Secondly, different tasks are executed sequentially, and the consumption system cannot make full use of multi-core and multi-threaded resources.

[0028] Thirdly, the consumption system cannot automatically adjust and optimize based on real-time load, task characteristics, and abnormal situations.

[0029] Fourthly, in distributed or multi-threaded environments, logs and context information are easily lost, which is not conducive to troubleshooting and tracing tasks.

[0030] To address this issue, this disclosure proposes the following technical solution: Multiple thread pools are configured. Based on the business identifier of each task to be executed, a thread pool is selected from these pools. These multiple thread pools execute their respective tasks in parallel, resolving the issue of all tasks queuing within the same thread pool and improving task processing speed and overall throughput. Tasks with the same identifier correspond to the same thread pool, resolving the issue of different tasks being executed serially, thus fully utilizing multi-core and multi-threaded resources. Furthermore, after each task completes its execution, a set of parameters is collected. Based on this parameter set, load balancing, the execution priority of tasks with the same business identifier as the completed task, and the number of threads in the thread pool are automatically adjusted to further improve the execution efficiency of subsequent tasks, thereby enhancing the user experience.

[0031] To facilitate description and make the technical solutions of this disclosure easier to understand, the terminology of this disclosure will be explained before describing the technical solutions of this disclosure.

[0032] 1. MDC (Mapped Diagnostic Context): This is a thread-bound context storage mechanism provided by the logging framework. It is used to attach additional context information to logs, such as request identifiers, user identifiers, and tracing identifiers. MDC is a tool used in the logging framework, primarily for tracing and diagnosing logs in a multi-threaded environment.

[0033] 2. Thread pool: It is a resource pool used to manage and reuse multiple threads, which can avoid the overhead of frequently creating and destroying threads.

[0034] 3. Hash value: A hash function that transforms an input of arbitrary length, such as a string order number, into a fixed-length integer. This integer can be seen as a digital fingerprint of the original data.

[0035] 4. Modulo: A mathematical operation used to calculate the remainder when one integer is divided by another integer.

[0036] 5. Wrapping: A programming technique that involves creating a new object with the original task object as an internal property, allowing additional operations to be added to the new object's runtime methods, such as cleaning up context information.

[0037] Figure 1 This is a schematic diagram of the overall flow of a method for accelerating task execution according to one embodiment of this disclosure. Figure 1 As shown, the method includes the following steps S110 to S150. This method can be executed by a server.

[0038] In step S110, multiple tasks to be executed are received.

[0039] The server receives multiple tasks to be executed from the terminal. This disclosure applies to various types of tasks to be executed in different business scenarios. For example, tasks of order type, tasks of message type, and tasks of event type. A task to be executed can be an order message or a user event. A consumption system can run on the server.

[0040] In step S120, the business identifier of each task to be executed is obtained.

[0041] Each task to be executed has a unique business identifier to facilitate identification and tracking. The business identifier can be an order number or a user identifier. Each order number or user identifier corresponds to at least one task to be executed. Each order number or user identifier may correspond to different tasks at different times. Upon receiving a task, the consumption system parses and retrieves its business identifier.

[0042] In step S130, a thread pool is selected from multiple thread pools for each task to be executed based on the business identifier of each task to be executed.

[0043] This disclosure establishes multiple independent thread pools. Tasks with the same business identifier belong to the same thread pool. Specifically, if two tasks have the same business identifier, they belong to the same thread pool. If two tasks have different business identifiers, they may belong to the same or different thread pools. That is, while multiple business identifiers may exist within the same thread pool, tasks with the same business identifier will only be assigned to the same thread pool.

[0044] In step S140, each task to be executed is routed to the corresponding thread pool.

[0045] In step S150, the corresponding task to be executed is performed in the thread pool.

[0046] When the consumption system starts, it initializes multiple thread pools. The parameters for each thread pool include the number of core threads, the maximum number of threads, the queue capacity, and the thread pool name prefix.

[0047] During the execution of pending tasks, multiple pending tasks from the same thread pool are executed one by one in a preset order, while multiple pending tasks from different thread pools are executed in parallel. When a thread pool is assigned multiple pending tasks, it executes each pending task sequentially according to its routing order, timestamp order, or execution priority. That is, the next pending task will only be executed after the previous one has finished. Furthermore, while one thread pool is executing a pending task, other thread pools are executing their corresponding other pending tasks in parallel. In other words, the same thread pool executes pending tasks serially, while different thread pools execute them in parallel. This not only avoids competition and conflicts between multiple pending tasks with the same business identifier but also maximizes the parallel execution of pending tasks with different business identifiers, fully utilizing multi-core resources and significantly improving overall efficiency. For example, while the first thread pool is executing the first pending task, the second thread pool is simultaneously executing its corresponding first pending task; the two thread pools do not interfere with each other and execute their respective pending tasks concurrently. After the first thread pool finishes executing its first pending task, it begins executing the second pending task. After the first thread pool finishes executing its second pending task, it begins executing the third pending task, and so on, until all pending tasks in the first thread pool have been completed.

[0048] For example, in e-commerce order processing scenarios, order placement and payment events corresponding to different order numbers are processed in parallel, while order placement and payment events corresponding to the same order number are processed serially to improve overall throughput and response speed. In consumer middleware scenarios, different thread pools handle different topics and partitions to achieve high-concurrency consumption. In fulfillment scenarios, order delivery, installation, and payment events are processed in parallel to improve overall fulfillment efficiency.

[0049] This disclosure provides a method to accelerate task execution. It sets up multiple independent thread pools and distributes received tasks to the corresponding thread pools based on their identifiers. Tasks in multiple thread pools are executed in parallel, improving the execution efficiency and overall throughput in high-concurrency scenarios. Furthermore, tasks with the same business identifier are routed to the same thread pool, allowing them to be executed sequentially according to a preset order. This avoids data inconsistencies or logical conflicts caused by the simultaneous execution of multiple tasks corresponding to the same business identifier under high concurrency, thus ensuring the consistency of business data.

[0050] Figure 2 This is a flowchart illustrating step S130 of one embodiment of this disclosure. Figure 2As shown, the method includes the following steps S131 to S134.

[0051] In step S131, for each task to be executed, the hash value corresponding to the task to be executed is obtained.

[0052] The consumption system pre-assigns a unique code to each thread pool to facilitate quick differentiation and location of different thread pools. For example, this code can be represented numerically. The first thread pool is coded as "0", and the second thread pool as "1". Since the length of the business identifier (either numerical or character) is variable and complex, directly calculating the business identifier yields a result that, lacking a unified standard, cannot be directly used in subsequent calculations. However, a hash value is a fixed-length integer; therefore, this disclosure obtains the hash value corresponding to the task to be executed for subsequent calculations.

[0053] In step S132, an intermediate result is determined based on the hash value and the total number of threads in the thread pool.

[0054] The intermediate update result is calculated based on the update hash value and the total number of update thread pools. This intermediate result is used to select an update thread pool for the corresponding update task. The intermediate result can be represented numerically.

[0055] In step S133, the code that matches the intermediate result is searched.

[0056] For example, look up the code that matches the intermediate result. For instance, if the intermediate result is "2", the found code is "2".

[0057] In step S134, the thread pool corresponding to the encoding that matches the intermediate result is allocated to the task to be executed.

[0058] For example, the thread pool corresponding to the encoding that matches the intermediate result is assigned to the task to be executed. For instance, the thread pool encoded as "2" is assigned to the task to be executed where the intermediate result is "2".

[0059] The above technical solution, because the same business identifier corresponds to the same hash value, calculates the hash value and the total number of thread pools to determine the intermediate result. This ensures that tasks with the same business identifier correspond to the same intermediate result. When searching for a matching code based on the same intermediate result, the same code will always be found, and then the same thread pool will be selected based on the same code. This technical solution guarantees that tasks with the same business identifier are assigned to the same thread pool, thereby enabling the orderly allocation of a large number of random tasks to multiple thread pools.

[0060] Figure 3This is a flowchart illustrating step S131 of one embodiment of this disclosure. Figure 3 As shown, the method includes the following steps S1311 to S1313.

[0061] In step S1311, it is determined whether the service identifier of the task to be executed is empty. If yes, then step S1312 is executed. If no, then step S1313 is executed.

[0062] When calculating the hash value, the consumption system first determines whether the business identifier of the task to be executed is empty, that is, whether it is "null".

[0063] In step S1312, the hash value of the task to be executed is a preset value.

[0064] The preset value is a fixed integer. When the business identifier is empty, this preset value is used as the hash value of the task to be executed to ensure that a unique thread pool is selected when the business identifier is empty. For example, the preset value is "0", thus avoiding the occurrence of an exception by directly calculating the business identifier when the business identifier is empty.

[0065] In step S1313, the business identifier of the task to be executed is calculated to obtain a hash value.

[0066] If the business identifier is not empty, a preset hash function is called to calculate the hash value of the business identifier.

[0067] The above technical solution ensures that a definite hash value can be obtained regardless of whether the business identifier is empty, thereby allowing the selection of a specific thread pool and improving the fault tolerance of the method.

[0068] Figure 4 This is a flowchart illustrating step S132 of one embodiment of this disclosure. Figure 4 As shown, the method includes the following steps S1321 to S1324.

[0069] In step S1321, it is determined whether the hash value is greater than or equal to a preset threshold. If yes, then step S1322 is executed. If no, then step S1323 is executed.

[0070] In step S1322, the hash value and the total number are calculated to obtain intermediate results.

[0071] In step S1323, the absolute value of the hash value is obtained.

[0072] In step S1324, the absolute value of the hash value and the total number are calculated to obtain an intermediate result.

[0073] In some examples, intermediate results are obtained by modulo the hash value with the total quantity. For instance, if the preset threshold is "0", then when the hash value is greater than or equal to the preset threshold, the hash value is positive or "0", and the intermediate result is obtained by directly performing a modulo operation on the hash value and the total quantity. When the hash value is less than the preset threshold, the hash value is negative. In this case, the absolute value of the hash value is obtained, and the intermediate result is obtained by modulo the absolute value of the hash value with the total quantity. That is, the intermediate result is the remainder after performing a modulo operation on the hash value or the absolute value of the hash value with the total quantity. When the total quantity is "4", the intermediate result is "0", "1", "2", or "3", and "0", "1", "2", and "3" are the codes of the four thread pools, respectively. Therefore, the above technical solution can allocate a unique thread pool for each task to be executed based on the corresponding intermediate result. Furthermore, as can be seen from the above calculation, different business identifiers may have the same intermediate result because the remainder after performing a modulo operation on the total quantity with different hash values ​​may be the same. Therefore, tasks to be executed corresponding to different business identifiers may correspond to the same thread pool. In other words, there may be multiple tasks corresponding to different business identifiers within the same thread pool. Because these tasks with different business identifiers are in the same thread pool, they also need to be executed sequentially.

[0074] Figure 5 This is a flowchart illustrating the processing of context information according to one embodiment of this disclosure. Figure 5 As shown, the method includes the following steps S510 to S540.

[0075] In step S510, before executing the task to be executed, the task to be executed is packaged to obtain the packaged task to be executed.

[0076] In step S520, the context information corresponding to the packaged task to be executed is obtained, and the context information is stored in the packaged task to be executed.

[0077] The context information includes at least the request identifier, the user identifier, and the tracing identifier.

[0078] The context information includes public attributes of the corresponding task to be executed throughout its entire lifecycle, from start to finish, used to track the complete lifecycle of the task. In a multi-threaded environment, the context information is stored in the MDC (Multi-Threaded Data Center).

[0079] In step S530, when executing the packaged task to be executed, the context information is restored to the log of the thread corresponding to the packaged task to be executed.

[0080] This context information will be automatically included in all logs generated during the execution of the task to be executed.

[0081] In step S540, after the packaged task to be executed has finished, the context information is cleaned up.

[0082] Since the threads in the thread pool disclosed herein are reused, failing to clean up the context information will pollute the next task to be executed. Therefore, after the wrapped task to be executed finishes, the context information in the current thread's MDC will be cleaned up immediately to keep the context information of different tasks to be executed independent of each other, thereby avoiding pollution of subsequent tasks to be executed.

[0083] The above technical solution achieves lossless context pass-through, ensuring that all logs of each task can be correctly associated with its original request chain, whether the tasks are executed serially or in parallel. This helps staff track the complete lifecycle of a business request using a tracing identifier, thereby greatly improving the efficiency and accuracy of problem localization.

[0084] Figure 6 This is a flowchart illustrating the parameter set for the completion of a data acquisition task according to one embodiment of this disclosure. For example... Figure 6 As shown, the method includes the following steps S610 to S621.

[0085] In step S610, for each task that has completed execution, the parameter set of the task is collected.

[0086] The parameter set includes at least one of execution time, exception frequency, and queue length. The parameter set is a set of quantitative metrics describing the execution status and load of completed tasks. Execution time is the total execution time of multiple completed tasks. Exception frequency is the number of exceptions that occur during the execution of a completed task from start to finish. Queue length is the number of pending tasks currently waiting to be executed in the thread pool corresponding to the completed task. A completed task indicates that the task's execution status has changed from "pending execution" to "execution completed." Therefore, for each pending task, there is a corresponding completed task after its completion. Completed tasks may end normally or due to an exception.

[0087] During the execution of pending tasks, threads may modify shared state, such as the number of remaining pending tasks in the queue, the number of active threads, and the number of completed tasks. Therefore, collecting parameter sets during the execution of pending tasks can lead to inconsistencies or brief fluctuations in the parameters. For example, the number of active threads may change instantaneously during the execution of pending tasks, and the number of completed tasks is also unstable. Furthermore, since threads in a thread pool are reused, the context information collected during the execution of pending tasks may not be able to distinguish which pending task it matches. To solve these problems, this disclosure collects the parameter set of the corresponding completed task after the pending tasks have finished executing, in order to determine the execution status of the completed task. The above technical solution only requires collecting the parameter set once for each completed task, and the collected parameter set is more reliable.

[0088] In step S620, the operating parameters are adjusted or an alarm is issued based on the parameter set.

[0089] The running parameters include at least one of the following: the execution priority of the task to be executed, load balancing, and the number of threads in the thread pool corresponding to the completed task. The business identifier of the task to be executed is the same as the business identifier of the completed task.

[0090] In some scenarios, after collecting the parameter set, the consumption system analyzes the parameters in the parameter set according to preset rules. If these parameters trigger an automatic adjustment mechanism, the consumption system automatically adjusts its operating parameters. In other scenarios, the consumption system may generate alarms to promptly notify staff to handle related anomalies.

[0091] The above technical solution monitors the execution status of completed tasks and collects a set of parameters. Based on this parameter set, the operating parameters of the consumption system are automatically adjusted, thereby optimizing the resource utilization of the consumption system and ensuring its stable and efficient operation.

[0092] In some examples, when the execution time exceeds a first execution time threshold and the queue length exceeds a first queue length threshold, the number of core threads and the maximum number of threads in the thread pool corresponding to the completed task are increased. An execution time exceeding the first threshold indicates a long execution period for the completed task, and a queue length exceeding the first threshold indicates a large backlog of tasks. Therefore, the consumer system determines that its processing capacity is insufficient and automatically expands the thread pool corresponding to the completed task, increasing the number of core threads and the maximum number of threads to improve the system's concurrent processing capabilities and quickly handle the backlog of tasks. For example, if the execution time exceeds the first execution time threshold multiple times consecutively, an alarm is issued.

[0093] In some examples, when the exception frequency exceeds a first exception frequency threshold and the queue length exceeds a first queue length threshold, the execution priority of pending tasks with the same business identifier as the completed task is reduced. A higher exception frequency threshold indicates a higher number of exceptions during the execution of the completed task. Combined with a longer queue length, the consumer system assumes these exceptions are blocking the execution of tasks in the queue. Therefore, the consumer system reduces the execution priority of pending tasks with the same business identifier as the completed task, thus delaying their execution to prevent them from blocking the normal execution of other pending tasks with different business identifiers. For example, in a message push scenario, the consumer system needs to send notifications to a large number of users. If user A's device malfunctions, causing the pending task corresponding to the message pushed to user A to fail multiple times, without intervention, this pending task will repeatedly retry, consuming thread pool resources and affecting the normal push notifications for other users. In this case, the consumer system reduces the execution priority of the pending task corresponding to user A, indirectly increasing the execution priority of pending tasks corresponding to other users, thus prioritizing the execution of those other users' pending tasks. If the task to be executed for user A is executed successfully, the failure count will be reset to zero, and the execution priority of the task to be executed for user A will be restored.

[0094] In some examples, when the queue length is less than a second queue length threshold and the execution time is less than a second execution time threshold, the number of core threads in the thread pool corresponding to the completed task is reduced. Here, the first queue length threshold is greater than the second queue length threshold, and the first execution time is greater than the second execution time. A queue length less than the second queue length threshold indicates a smaller number of tasks currently queued for execution, and an execution time less than the second execution time threshold indicates a shorter execution time for the completed task. Therefore, the consumer system will determine that resources are currently excessive. To conserve computing resources, the consumer system will reduce the number of core threads in the thread pool to release some idle core threads.

[0095] In some examples, when the exception frequency exceeds a first exception frequency threshold, a fault tolerance mechanism is added to avoid blocking pending tasks corresponding to other business identifiers in the thread pool. This fault tolerance mechanism prevents the pending task from repeatedly consuming thread resources due to repeated retries and failures, thus preventing it from affecting the normal execution of other pending tasks. Additionally, the consumer system can create a low-priority thread pool with a small number of core threads. This thread pool is used to handle pending tasks corresponding to business identifiers with high exception frequencies. That is, when the exception frequency of a pending task exceeds a first exception frequency, the business identifier of that task is obtained, and subsequent pending tasks corresponding to that business identifier are routed to this low-priority thread pool. This isolates abnormal pending tasks from normal ones, ensuring that even if queue blocking occurs in this low-priority thread pool, it will not affect the normal execution of pending tasks in other thread pools. Furthermore, the consumer system sets a retry threshold for each business identifier and records the total number of retries for all pending tasks corresponding to that business identifier during execution. If the total number of retries is not less than the retry threshold, the pending task corresponding to the business identifier is not allowed to be retried, thereby preventing the queue in the entire thread pool from being blocked due to an infinite retry of a single pending task.

[0096] The above technical solution automatically expands the thread pool when the consumer system is under high load, reducing the number of backlogged tasks and lowering latency. When the frequency of exceptions during the execution of completed tasks is high, the execution priority of tasks with the same business identifier as the completed tasks is reduced to prevent these tasks from affecting the normal execution of other tasks. When the consumer system is under low load, idle thread resources are released, achieving resource optimization and load balancing.

[0097] It should be noted that the first execution time threshold, the first queue length threshold, the first abnormal frequency threshold, the second queue length threshold, and the second execution time threshold can be set or adjusted according to actual needs, and the embodiments disclosed herein will not be specifically limited.

[0098] The above solution only provides one implementation of a method to accelerate task execution. In other embodiments, this disclosure combines different types of identifiers to select a thread pool for the task to be executed, thereby further improving the user experience and satisfaction in different scenarios.

[0099] In some scenarios, users with different consumption levels require different quality of service. The aforementioned method for accelerating task execution is only applicable to low-consumption-level users, and can only distribute a large number of random tasks to be executed into multiple thread pools based on business identifiers to improve overall throughput and response speed. However, high-consumption-level users require higher response speeds and higher quality services. To achieve this, this disclosure provides dedicated thread pools for these high-consumption-level users. The dedicated thread pools have a larger number of core threads to provide higher response speeds and higher quality services. Specifically, after receiving multiple tasks to be executed, the consumption system obtains the business identifier and consumption level identifier for each task. If the identified consumption level identifier is low, steps S110 to S150 are executed. If the identified consumption level identifier is high, the task to be executed is routed to the dedicated thread pool to isolate the tasks to be executed for low-consumption-level users from those for high-consumption-level users, thereby preventing high-consumption-level users from being affected by low-consumption-level users and greatly improving the satisfaction of high-consumption-level users. If there are many high-consumption-level users, multiple dedicated thread pools can be created according to actual needs. In this scenario, once a high-level consumption status is identified, a dedicated thread pool is selected from multiple dedicated thread pools based on the business identifier of the task to be executed. The task is then routed to that dedicated thread pool and executed there. If a high-level user experiences a consumption downgrade, for example, to a low-level consumption status, subsequent tasks for that user will no longer be routed to a dedicated thread pool. Instead, a thread pool will be selected from multiple thread pools based on the user's business identifier, and the corresponding tasks will be routed to that thread pool.

[0100] In other scenarios, users in different regions require different quality of service. The aforementioned method for accelerating task execution is only applicable to users in smaller cities, while users in larger cities require higher response speeds and higher quality services. To achieve this, this disclosure provides multiple dedicated thread pools for users in these larger cities. Specifically, after receiving multiple tasks to be executed, the consumption system obtains the business identifier and regional identifier of each task. If the identified regional identifier is a smaller city, steps S110 to S150 are executed. If the identified regional identifier is a larger city, a dedicated thread pool is selected from the multiple dedicated thread pools based on the business identifier of the task to be executed, and the task is routed to that dedicated thread pool for execution.

[0101] In other scenarios, during promotional activities on e-commerce platforms, a large number of users simultaneously purchase the same product, resulting in the consumption system receiving multiple pending tasks within a short period. These pending tasks may have different business identifiers, but their corresponding product identifiers are the same, uniquely identifying the product. For each product, the types of pending tasks corresponding to each business identifier include, but are not limited to, inventory updates, coupon redemption, and logistics allocation. Coupon redemption and logistics allocation tasks can be executed in parallel, but multiple pending tasks of the inventory update type must be executed sequentially, not in parallel, to ensure that the total number of products sold does not exceed the inventory quantity. To achieve the sequential execution of multiple inventory update type pending tasks, this disclosure allocates an inventory update thread pool for inventory update type pending tasks. If an inventory update type pending task is identified, it is assigned to the inventory update thread pool, thereby achieving the sequential execution of multiple inventory update type pending tasks, thus avoiding inventory data corruption and ensuring the accuracy of inventory data.

[0102] To facilitate operation, maintenance, and debugging by staff, the embodiments of this disclosure support real-time export of execution data and playback of historical data. Specifically, a snapshot is generated and written to a local circular buffer at preset intervals. The local circular buffer retains a preset number of recent snapshots, and these snapshots are asynchronously written to the database to facilitate accurate problem localization through historical analysis. It should be noted that the preset number can be set or modified according to actual needs, and the embodiments of this disclosure do not impose specific limitations on this.

[0103] This disclosure also provides an apparatus for accelerating task execution. Figure 7 This is a schematic structural block diagram of an apparatus for accelerating task execution according to one embodiment of this disclosure. Figure 7 As shown, the device includes: The communication module 701 is used to receive multiple tasks to be executed.

[0104] The acquisition module 702 is used to acquire the business identifier of each task to be executed.

[0105] Selection module 703 is used to select a thread pool from multiple thread pools for each task to be executed based on the business identifier of each task. Tasks to be executed with the same business identifier belong to the same thread pool.

[0106] The routing module 704 is used to route each task to be executed to the corresponding thread pool.

[0107] Execution module 705 is used to execute the corresponding tasks to be executed in the thread pool.

[0108] The specific implementation process of the functions and roles of each module in the above-mentioned device is detailed in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here. The execution subject of the method for accelerating task execution in the specific embodiments of this disclosure can be a server (including a local server or a cloud server).

[0109] Therefore, based on any of the above embodiments, this disclosure also provides an electronic device that can execute the method for accelerating task execution of any of the embodiments described above.

[0110] Figure 8 This is a schematic structural block diagram of an electronic device according to one embodiment of the present disclosure.

[0111] The hardware architecture of the electronic device 1000 can be implemented using a bus architecture. The bus architecture can include any number of interconnect buses and bridges, depending on the specific application of the hardware and overall design constraints. Bus 1100 connects various circuits, including one or more processors 1200, memory 1300, and / or hardware modules. Bus 1100 can also connect various other circuits 1400, such as peripheral devices, voltage regulators, power management circuits, external antennas, etc.

[0112] Bus 1100 can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, this diagram uses only one connection line, but this does not imply that there is only one bus or one type of bus.

[0113] For ease of explanation, certain steps of the above method are described in relation to modules. It should be understood that the corresponding module performing one or more steps of the above method may be one or more hardware modules specifically configured to perform the corresponding step, or implemented by a processor configured to perform the corresponding step, or stored in a computer-readable medium for implementation by a processor, or implemented by some combination thereof.

[0114] This disclosure also provides a readable storage medium storing a computer program that, when executed by a processor, is used to implement the methods described above. A "readable storage medium" can be any means capable of containing, storing, communicating, propagating, or transmitting a program for use by or in conjunction with an instruction execution system, apparatus, or device. More specific examples of a readable storage medium include: an electrical connection with one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and programmable read-only memory (EPROM or flash memory), fiber optic devices, and portable read-only memory (CDROM), etc.

[0115] This disclosure also provides a computer program product, the methods of which can be implemented wholly or partially through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented wholly or partially as a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instructions are loaded and executed, all or part of the processes or functions of this disclosure are performed.

[0116] Computer programs or instructions can be stored in a readable storage medium or transferred from one readable storage medium to another. For example, the computer program or instructions can be transferred from one website, computer, server, or data center to another website, computer, server, or data center via wired or wireless means. The readable storage medium can be any available medium capable of access, or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium, such as a floppy disk, hard disk, or magnetic tape; an optical medium, such as a digital video optical disc; or a semiconductor medium, such as a solid-state drive. The computer-readable storage medium can be a volatile or non-volatile storage medium, or it can include both volatile and non-volatile types of storage media.

[0117] Those skilled in the art will understand that embodiments of this disclosure can be provided as methods, systems, or computer program products. Therefore, this disclosure can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this disclosure can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0118] This disclosure is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus, and computer program products according to this disclosure. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0119] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0120] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0121] Those skilled in the art should understand that the above embodiments are merely for illustrating the present disclosure and are not intended to limit the scope of the disclosure. Those skilled in the art can make other changes or modifications based on the above disclosure, and these changes or modifications still fall within the scope of the present disclosure.

Claims

1. A method for accelerating task execution, characterized in that, include: Receive multiple tasks to be executed; Obtain the business identifier for each of the tasks to be executed; Based on the service identifier of each task to be executed, a thread pool is selected from multiple thread pools for each task to be executed; tasks to be executed with the same service identifier correspond to the same thread pool. Each of the tasks to be executed is routed to the corresponding thread pool; The corresponding task to be executed is performed in the thread pool.

2. The method as described in claim 1, characterized in that, The thread pool is coded; the service identifier is an order number or a user identifier. Based on the business identifier of each task to be executed, a thread pool is selected from multiple thread pools for each task to be executed, including: For each of the tasks to be executed, obtain the hash value corresponding to the task to be executed; An intermediate result is determined based on the hash value and the total number of threads in the thread pool; the intermediate result is calculated based on the hash value and the total number of threads in the thread pool, and the intermediate result is used to select a thread pool for the corresponding task to be executed; Find the code that matches the intermediate result; The thread pool corresponding to the encoding that matches the intermediate result is allocated to the task to be executed.

3. The method as described in claim 2, characterized in that, Obtaining the hash value corresponding to the task to be executed includes: If the business identifier of the task to be executed is empty, then the hash value of the task to be executed is a preset value; Alternatively, if the business identifier of the task to be executed is not empty, the hash value is calculated based on the business identifier of the task to be executed.

4. The method as described in claim 2, characterized in that, The intermediate result is determined based on the hash value and the total number of threads in the thread pool, including: When the hash value is greater than or equal to a preset threshold, the hash value and the total quantity are calculated to obtain the intermediate result; When the hash value is less than the preset threshold, the absolute value of the hash value is obtained, and the absolute value of the hash value and the total number are calculated to obtain the intermediate result.

5. The method as described in claim 4, characterized in that, When the hash value is greater than or equal to a preset threshold, the hash value and the total quantity are calculated to obtain the intermediate result, including: The intermediate result is obtained by performing a modulo operation on the total quantity based on the hash value.

6. The method as described in claim 1, characterized in that, The method further includes: Multiple tasks to be executed in the same thread pool are executed one by one in a preset order. Multiple tasks to be executed from different thread pools are executed in parallel.

7. The method as described in claim 1, characterized in that, The method further includes: Before executing the task to be executed, the task to be executed is packaged to obtain the packaged task to be executed; Obtain the context information corresponding to the packaged task to be executed, and store the context information in the packaged task to be executed; the context information includes at least a request identifier, a user identifier, and a tracing identifier; When executing the packaged task to be executed, restore the context information to the log of the thread corresponding to the packaged task to be executed; After the packaged task to be executed is completed, the context information is cleared.

8. The method as described in claim 1, characterized in that, The method further includes: For each completed task, a set of parameters for the completed task is collected; the set of parameters includes at least one of execution time, exception frequency, and queue length. The operating parameters are adjusted or alarms are issued based on the parameter set; the operating parameters include at least one of the execution priority of the task to be executed, load balancing, and the number of threads in the thread pool corresponding to the task that has been completed, and the business identifier of the task to be executed is the same as the business identifier of the task that has been completed.

9. An electronic device, characterized in that, include: The memory stores execution instructions; as well as A processor that executes execution instructions stored in the memory, causing the processor to perform the method for accelerating task execution as described in any one of claims 1 to 8.

10. A readable storage medium, characterized in that, The readable storage medium stores execution instructions, which, when executed by a processor, are used to implement the method for accelerating task execution as described in any one of claims 1 to 8.