A task execution method and device
By monitoring the performance indicators of servers, databases and upstream interfaces, quantifying the task execution rate, and executing tasks using a chain of responsibility, the problems of batch task accumulation and system stability are solved, and efficient task execution and system resource management are achieved.
Patent Information
- Application Number
- CN202110084204.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-21
- Publication Date
- 2025-05-16
- Estimated Expiration
- 2041-01-21
AI Technical Summary
The prior art cannot effectively deal with the randomness and suddenness of batch tasks, resulting in task accumulation, affecting system stability, and lack of quantitative task execution rate indicators.
By monitoring the comprehensive performance indicators of the server, database and upstream interfaces, the task execution rate is quantified, and tasks are executed based on preset thread models and responsibility chain methods, the smoothing processing of batch tasks is achieved.
It reduces the accumulation of batch tasks, reduces system resource consumption, improves system stability, and provides quantifiable task execution rate indicators.
Smart Images

Figure CN113742057B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a task execution method and device. Background Art
[0002] With the vigorous development and widespread popularity of Internet technology, diversified data has shown an explosive growth trend. Diversified data has low real-time requirements, but consumes a lot of resources such as the server's CPU (central processing unit), memory resources, database resources, and upstream interfaces. There are two existing batch task processing solutions: Solution 1 divides batch tasks and real-time tasks in time, such as using idle time to execute batch tasks to avoid batch tasks affecting the system's business; Solution 2 is to process batch tasks based on methods such as thread pool queues.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] Due to the randomness and suddenness of batch tasks, the accumulation of batch tasks and their concentrated execution during business peak hours may affect related applications and systems and threaten the stability of related systems. Solution 1 only divides the tasks in time and cannot cope with the randomness and suddenness of batch tasks; Solution 2 smoothes the execution of tasks to a certain extent, but does not fundamentally solve the problem of batch task processing, and there is no quantifiable indicator for the smoothing rate of tasks. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a task execution method and device, which can quantify the task execution rate based on comprehensive indicators such as server performance, database performance, and upstream interface performance, realize smooth processing of batch tasks, reduce the accumulation of batch tasks, reduce system resource consumption, and improve system stability.
[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a task execution method is provided.
[0007] A task execution method comprises: converting the input source data of the task into a task in a standard input sequence format by a preprocessor corresponding to the input source data of the task; saving the task in the standard input sequence format into a task queue according to the subject of the task; monitoring a comprehensive indicator representing the execution capability of a server to determine the number of tasks that can be pulled from the task queue, and pulling the tasks from the task queue according to the number of tasks; and executing the pulled tasks by means of a chain of responsibility based on a preset thread model.
[0008] Optionally, the monitoring represents a comprehensive indicator of the server's execution capability to determine the number of tasks that can be pulled from the task queue, including: monitoring whether various indicator values in the comprehensive indicator representing the server's execution capability reach corresponding thresholds, the various indicator values including one or more of the server's load capacity indicator value, the upstream interface processing capacity indicator value, and the database's load capacity indicator value; when no indicator value reaches the corresponding threshold, determining the number of tasks that can be pulled from the task queue according to a congestion control algorithm, the congestion control algorithm including congestion control of the number of tasks pulled in the following stages: exponential growth stage, congestion avoidance stage, and stable stage; when an indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is obtained from a preset starting value.
[0009] Optionally, before the monitoring determines whether various indicator values in the comprehensive indicator representing the execution capability of the server reach corresponding thresholds, it includes: performing statistics on one or more of the load capacity indicator value of the server, the upstream interface processing capacity indicator value, and the load capacity indicator value of the database based on the query rate per second and the response time.
[0010] Optionally, determining the number of tasks that can be pulled from the task queue according to the congestion control algorithm includes: in the exponential growth stage, taking the number of tasks pulled last time as a benchmark, and growing according to an exponential law to obtain the number of tasks that can be pulled from the task queue, wherein when the number of tasks pulled last time does not exist, the preset initial value is used as the benchmark; in the congestion avoidance stage, adding a preset value to the number of tasks pulled last time to obtain the number of tasks that can be pulled from the task queue; in the stable stage, using a preset maximum pull value as the number of tasks that can be pulled from the task queue.
[0011] Optionally, the pulled task is executed by a responsibility chain based on a preset thread model, including: retrieving a successful execution record of the task in a cache; when it is determined that no successful execution record of the task is retrieved, splitting the task into one or more subtasks based on the preset thread model; executing the subtasks of the task in the responsibility chain, and when the subtask fails to execute, retrying the subtask in the responsibility chain if the upper limit of the number of retries of the subtask is not reached; if any of the subtasks still fails to execute after the number of retries reaches the upper limit of the number of retries, the task execution fails, and the failed task is saved again in the task queue for re-execution.
[0012] Optionally, if the task is executed successfully, a record of the successful execution of the task is stored in the cache, and a cache expiration time is set, wherein, for the task that is executed periodically, the cache expires in the next execution cycle of the task.
[0013] Optionally, the task queue is a distributed message queue, and the preset thread model is an event-driven thread model.
[0014] According to another aspect of an embodiment of the present invention, a task execution device is provided.
[0015] A task execution device includes: a preprocessing module, which is used to convert the input source data of the task into a task in a standard input sequence format through a preprocessor corresponding to the input source data of the task; a task saving module, which is used to save the task in the standard input sequence format into a task queue according to the subject of the task; a task pulling module, which is used to monitor a comprehensive indicator representing the execution capability of a server to determine the number of tasks that can be pulled from the task queue, and pull the tasks from the task queue according to the number of tasks; and a task execution module, which is used to execute the pulled tasks in a responsibility chain manner based on a preset thread model.
[0016] Optionally, the task pulling module is also used to: monitor whether various indicator values in the comprehensive indicator representing the execution capability of the server reach corresponding thresholds, the various indicator values include one or more of the server's load capacity indicator value, the upstream interface processing capability indicator value, and the database's load capacity indicator value; when no indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is determined according to a congestion control algorithm, and the congestion control algorithm includes congestion control of the following stages of the number of tasks pulled: exponential growth stage, congestion avoidance stage, and stable stage; when an indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is obtained by a preset starting value.
[0017] Optionally, the task pulling module is also used to: perform statistics on one or more of the load capacity index value of the server, the upstream interface processing capacity index value, and the load capacity index value of the database based on the query rate and response time per second.
[0018] Optionally, the task pulling module is also used for: in the exponential growth stage, taking the number of tasks pulled last time as the benchmark, and growing according to the exponential law to obtain the number of tasks that can be pulled from the task queue, wherein when the number of tasks pulled last time does not exist, the preset initial value is used as the benchmark; in the congestion avoidance stage, adding a preset value to the number of tasks pulled last time to obtain the number of tasks that can be pulled from the task queue; in the stable stage, using a preset maximum pulling value as the number of tasks that can be pulled from the task queue.
[0019] Optionally, the task execution module is also used to: retrieve the successful execution record of the task in the cache; if it is determined that the successful execution record of the task is not retrieved, split the task into one or more subtasks based on the preset thread model; execute the subtasks of the task in the responsibility chain, and when the subtask fails to execute, retry the subtask in the responsibility chain under the condition that the upper limit of the retry number of the subtask is not reached, if any of the subtasks still fails to execute after the number of retries reaches the upper limit of the retry number, the task execution fails, and the failed task is saved again in the task queue for reexecution.
[0020] Optionally, the task execution module is also used to: if the task is executed successfully, store the successful execution record of the task in the cache and set a cache expiration time, wherein, for the task executed periodically, the cache expires in the next execution cycle of the task.
[0021] Optionally, the task queue is a distributed message queue, and the preset thread model is an event-driven thread model.
[0022] An electronic device includes: one or more processors; and a memory for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the task execution method provided by an embodiment of the present invention.
[0023] According to yet another aspect of an embodiment of the present invention, a computer readable medium is provided.
[0024] A computer readable medium stores a computer program, which, when executed by a processor, implements a task execution method provided by an embodiment of the present invention.
[0025] One embodiment of the above invention has the following advantages or beneficial effects: monitoring the comprehensive index representing the execution capability of the server to determine the number of tasks that can be pulled from the task queue, and pulling tasks from the task queue according to the number of tasks; based on the preset thread model, executing the pulled tasks through the responsibility chain. Based on comprehensive indicators such as server performance, database performance, and upstream interface performance, the task execution rate can be quantified to achieve smooth processing of batch tasks, reduce the accumulation of batch tasks, reduce system resource consumption, and improve system stability.
[0026] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0028] Figure 1 is a schematic diagram of main steps of a task execution method according to an embodiment of the present invention;
[0029] Figure 2 is a flowchart of a task execution method according to an embodiment of the present invention;
[0030] Figure 3 is a schematic diagram of a task saving process according to an embodiment of the present invention;
[0031] Figure 4 is a schematic diagram of a congestion control algorithm according to an embodiment of the present invention;
[0032] Figure 5 is a schematic diagram of a framework for task execution according to an embodiment of the present invention;
[0033] Figure 6 is a schematic diagram of main modules of a task execution device according to an embodiment of the present invention;
[0034] Figure 7 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0035] Figure 8 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0036] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0037] Figure 1 It is a schematic diagram of main steps of a task execution method according to an embodiment of the present invention.
[0038] like Figure 1 As shown, a task execution method according to an embodiment of the present invention mainly includes the following steps S101 to S104.
[0039] Step S101: converting the input source data of the task into a task in a standard input sequence format through a preprocessor corresponding to the input source data of the task.
[0040] Step S102: According to the subject of the task, the task in the standard input sequence format is saved into the task queue.
[0041] The task queue can be a distributed message queue, such as Kafka (an open source message middleware).
[0042] The input source data of a task specifically refers to the original data of the task. In a batch task, there may be multiple input source data. Taking the implementation of the task queue using Kafka as an example, the input source data of different tasks are saved in the Kafka cluster in the form of message streams based on unified rules. The message stream based on unified rules is the task in the standard input sequence format.
[0043] Each task has its own topic, and batches of tasks have the same topic.
[0044] Step S103: monitor the comprehensive index representing the execution capability of the server to determine the number of tasks that can be pulled from the task queue, and pull tasks from the task queue according to the number of tasks.
[0045] Monitoring a comprehensive indicator representing the execution capability of a server to determine the number of tasks that can be pulled from a task queue may include: monitoring whether various indicator values in the comprehensive indicator representing the execution capability of a server reach corresponding thresholds, wherein the various indicator values include one or more of the server's load capacity indicator value, the upstream interface processing capability indicator value, and the database's load capacity indicator value; when no indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is determined according to a congestion control algorithm, and the congestion control algorithm includes congestion control of the number of tasks pulled in the following stages: an exponential growth stage, a congestion avoidance stage, and a stable stage, wherein the exponential growth stage is a stage in which the number of tasks pulled grows exponentially, the congestion avoidance stage is a stage in which the number of tasks pulled grows in an increasing manner, and the stable stage is a stage in which the number of tasks pulled is stable at a preset maximum pulling value, and the above stages will be described in detail below; when an indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is obtained from the preset starting value.
[0046] Before monitoring whether various indicator values in the comprehensive indicators representing the server execution capability have reached the corresponding thresholds, it can include: based on the query rate per second and the response time, statistics are collected on one or more of the server's load capacity indicator value, the upstream interface processing capacity indicator value, and the database's load capacity indicator value.
[0047] Determining the number of tasks that can be pulled from the task queue according to the congestion control algorithm may include: in the exponential growth stage, taking the number of tasks pulled last time as a benchmark, and growing according to an exponential law to obtain the number of tasks that can be pulled from the task queue, wherein when the number of tasks pulled last time does not exist, a preset initial value is used as a benchmark; in the congestion avoidance stage, adding a preset value to the number of tasks pulled last time to obtain the number of tasks that can be pulled from the task queue; in the stable stage, using a preset maximum pull value as the number of tasks that can be pulled from the task queue.
[0048] Step S104: Based on the preset thread model, the pulled task is executed through the responsibility chain.
[0049] The preset thread model may be an event-driven thread model, such as a Reactor thread model. Reactor is a specific implementation of the Reactive Programming specification. Reactive programming is an asynchronous programming paradigm involving data flow and change propagation.
[0050] Based on the preset thread model, executing the pulled task through the responsibility chain may include: retrieving the successful execution record of the task in the cache; when it is determined that the successful execution record of the task is not retrieved, splitting the task into one or more subtasks based on the preset thread model; executing the subtasks of the task in the responsibility chain, when a subtask fails to execute, retrying the subtask in the responsibility chain under the condition that the upper limit of the retry number of the subtask is not reached, if a subtask still fails to execute after the retry number reaches the upper limit, the task execution fails, and the failed task is saved again in the task queue for re-execution.
[0051] If the task is executed successfully, the successful execution record of the task is stored in the cache, and the cache expiration time is set. For tasks executed periodically, the cache expires in the next execution cycle of the task.
[0052] The following takes the smooth execution of batch tasks as an example to describe in detail the task execution method according to the embodiment of the present invention.
[0053] In view of the problems existing in the current batch task smoothing methods, such as the difficulty in quantifying the task execution rate and task execution accumulation, the embodiment of the present invention proposes a responsibility chain smoothing execution method based on a distributed message queue. The embodiment of the present invention introduces a distributed message queue to save tasks, avoiding problems such as tasks occupying server memory; quantifies the memory monitoring indicators of the application server, the QPS (Query Per Second) and RT (Response Time) monitoring indicators of the upstream execution method, and the dependent database performance monitoring indicators, etc., as the measurement standard for pulling tasks; tasks are executed in the form of a responsibility chain by the Reactor thread model (i.e., an event-driven thread model).
[0054] Figure 2 It is a flowchart of a task execution method according to an embodiment of the present invention.
[0055] like Figure 2 As shown, the embodiment of the present invention mainly processes the smoothing of the execution of batch tasks to ensure the stable performance of the server and related systems. The embodiment of the present invention can be divided into three parts, namely, a batch message saving module (i.e., a preprocessing module and a task saving module), a batch message pulling module (or a task pulling module) and a batch task execution module (or a task execution module). Through the batch message saving module, batch messages (i.e., tasks) are saved based on the distributed message queue; through the batch message pulling module, based on the comprehensive indicators such as the performance of the server itself (e.g., the load capacity index value of the server), the performance of the upstream method (e.g., the upstream interface processing capacity index value), and the performance of the database (e.g., the load capacity index value of the database), pull messages from the message queue on demand for consumption; through the batch task execution module, tasks are executed based on the Reactor thread model, and re-executed in the responsibility chain when the subtask fails. Through the above three parts, the smooth execution of batch tasks is completed.
[0056] The batch message saving module is mainly responsible for saving batch messages and constructing the message sequence (i.e., task queue) for task execution. The batch message pulling module is mainly responsible for pulling tasks from the message queue on demand based on comprehensive indicators such as server performance, which is used to achieve smooth processing of tasks, and to ensure the pressure balance of the server itself, related systems, databases, etc. as much as possible, and improve stability. The batch task execution module is mainly responsible for executing tasks in the form of a responsibility chain based on the Reactor thread model, ensuring single-threaded execution of tasks and avoiding repeated execution of tasks.
[0057] Figure 3 The figure is a flowchart of task saving according to an embodiment of the present invention.
[0058] like Figure 3As shown in the figure, the task saving process is mainly implemented by the preprocessing module and the task saving module. Among them, the distributed message queue uses Kafka, and the data from different task sources (i.e., input sources) are saved in the Kafka cluster in the form of message streams based on unified rules. Kafka is a message middleware developed and open sourced by LinkedIn. It is a high-throughput distributed publish-subscribe message system that can process all action stream data of consumers on the website. Kafka is mainly composed of Producer, Consumer and Broker. Producer is a message producer responsible for publishing messages to KafkaBroker; Consumer is a message consumer, reading messages from Kafka Broker; Kafka Broker cluster contains one or more servers, which are called Brokers.
[0059] The input source data of the task comes from multiple systems. The input source data format of each task is not uniform, and the amount of data from each data source is also not uniform. Therefore, each input source has a corresponding message preprocessor (i.e., preprocessor). Taking the Binlog log (binary log file) of MySQL (relational database management system) as an example, when the input source data is a Binlog log, the Binlog log is analyzed and parsed by the message preprocessor to generate a task in the standard input sequence format, and the task in the standard input sequence format is saved to the Kafka cluster according to the topic of the task.
[0060] Data can be backed up through the Kafka cluster. When an exception occurs, causing some tasks to fail to be successfully executed in the batch task execution module, the failed tasks can be saved back to the Kafka cluster so that they can be re-executed as needed.
[0061] In the batch message pulling module, the server load capacity index value, the upstream interface processing capacity index value, and the database load capacity index value are monitored to determine the number of tasks that can be pulled from the task queue and pull messages from the Kafka cluster.
[0062] The load capacity index value of the monitoring server is mainly to monitor the QPS related to the execution of batch tasks and the response time of the task execution method, and the response time can be the average response time. Among them, a high-performance sliding window can be used to count the real-time second-level index data to monitor the load capacity index value of the server. The load capacity index value of the server is a local index, which can be recorded as local_index={QPS, RT}, {QPS, RT} means that it is jointly determined by QPS and RT, and no further explanation is given below. For example, the QPS related to the execution of batch tasks by the monitoring server and the RT of the task execution method respectively reach the corresponding QPS threshold and RT threshold. If the QPS reaches the QPS threshold or the RT reaches the RT threshold, it is determined that the load capacity index value of the server reaches the threshold of the load capacity index of the server. If the QPS does not reach the QPS threshold and the RT does not reach the RT threshold, it is determined that the load capacity index value of the server does not reach the threshold of the load capacity index of the server. The load capacity index value of the server only affects the number of messages pulled by the server (i.e., the number of tasks pulled).
[0063] Monitor the upstream interface processing capacity index value, take the upstream interface as the monitoring object, and only count the relevant indicators of the server calling the upstream interface in the server for monitoring. Among them, the same method as the load capacity index value of the monitoring server can be used to determine whether the upstream interface processing capacity index value reaches the threshold of the upstream interface processing capacity index. For example, when the server calls the upstream interface, the QPS of the upstream interface reaches the QPS threshold or the RT reaches the RT threshold, then it is determined that the upstream interface processing capacity index value reaches the threshold of the upstream interface processing capacity index. If the QPS does not reach the QPS threshold and the RT does not reach the RT threshold, then it is determined that the upstream interface processing capacity index value does not reach the threshold of the upstream interface processing capacity index. The upstream interface processing capacity index value is a local indicator, which can be recorded as local_inter = {QPS, RT}.
[0064] When monitoring the load capacity index value of the database, if there is no monitoring point executed at the database level, relevant monitoring can also be performed on the method of calling the database, such as counting the response time of executing database operations, the QPS of executing database operations, etc. The load capacity index value of the database is a local index, which can be recorded as local_database={QPS, RT}. The method for judging whether the load capacity index value of the database reaches the threshold value of the load capacity index of the database is the same as the method for judging whether the load capacity index value of the server reaches the threshold value of the load capacity index of the server and the method for judging whether the upstream interface processing capacity index value reaches the threshold value of the upstream interface processing capacity index. Those skilled in the art can refer to the above judgment method for implementation, and will not be repeated here.
[0065] The upstream interface processing capability index value and the upstream interface processing capability index value introduced above are statistical local indicators. In the embodiment of the present invention, the upstream interface processing capability index value and the upstream interface processing capability index value can also be statistically analyzed as global indicators.
[0066] Since the upstream interface or database may provide services for multiple servers, the global upstream interface monitoring data can also be obtained as the global upstream interface processing capacity index value, denoted as global_inter={QPS, RT}, and the global database load capacity monitoring data can be obtained as the global database load capacity index value, denoted as global_database={QPS, RT}. The method for determining whether the global upstream interface processing capacity index value and the global database load capacity index value reach the corresponding threshold value is the same as the method for determining whether the local index of the upstream interface processing capacity index value and the upstream interface processing capacity index value reach the corresponding threshold value above. Those skilled in the art can refer to the above determination method for implementation, and no further description is given for this.
[0067] Based on the number of tasks pulled, the comprehensive indicators representing the execution capability of the server are monitored according to the server load capacity index value, the upstream interface processing capacity index value, and the database load capacity index value. For example, the server is judged to be in a congested state when any of the following situations occurs: the QPS of the tasks executed in the server reaches the corresponding QPS threshold; the upstream interface that is dependent times out or reaches the threshold of the upstream interface processing capacity index; the database load capacity reaches the threshold of the database load capacity index.
[0068] Figure 4 is a schematic diagram of a congestion control algorithm according to an embodiment of the present invention.
[0069] like Figure 4 As shown in the figure, according to the comprehensive index of the server execution capability, the number of tasks pulled by the current server is controlled by the congestion control algorithm. The congestion control algorithm includes the following stages of congestion control of the number of tasks pulled: exponential growth stage, congestion avoidance stage, and stable stage. The exponential growth stage is the stage in which the number of tasks pulled increases exponentially, for example Figure 4 The stage where the number of tasks pulled is between 0 and 4; the congestion avoidance stage is the stage where the number of tasks pulled increases in an increasing manner, for example Figure 4 The stage where the number of tasks pulled is between 4 and 12; the stable stage is the stage where the number of tasks pulled is stable at the preset maximum pull value, for example Figure 4 Four pull tasks when the congestion window is 28. The congestion window is the number of tasks actually pulled each time. Figure 4The medium slow start threshold can be initialized with a value, and then the value of the slow start threshold can be dynamically updated according to the actual situation of task pulling. When introducing the congestion control algorithm of the embodiment of the present invention below, the update mechanism of the slow start threshold will be introduced by example.
[0070] exist Figure 4 In the congestion avoidance phase, the preset maximum number of pulls is 28, the slow start threshold initialization value is 16, the preset value is 1, and the preset initial value is 1. It starts as an exponential growth phase, taking the number of tasks pulled last time as the benchmark, and growing according to the exponential law to obtain the number of tasks that can be pulled from the task queue. When the number of tasks pulled reaches the slow start threshold initialization value of 16, the congestion avoidance phase is carried out. In the congestion avoidance phase, the preset value is added to the number of tasks pulled last time to obtain the number of tasks that can be pulled from the task queue. The number of tasks pulled increases in an additive manner until the preset maximum number of pulls (i.e., the preset maximum pull value) is reached, or the performance index reaches the comprehensive index. The performance index reaches the comprehensive index, which means that the various index values in the comprehensive index representing the execution capability of the server have index values reaching the corresponding thresholds, for example, one or more of the server's load capacity index value, the upstream interface processing capacity index value, and the database's load capacity index value reach the corresponding threshold. If the performance does not meet the comprehensive index when the number of pulls reaches the maximum value (the preset maximum pull value), the system enters the stable stage; if the performance meets the comprehensive index, the new slow start threshold is set to half of the current number of pull tasks (i.e., multiplication reduction), such as Figure 4 In the example, assuming that the performance reaches the comprehensive index when the number of tasks pulled for the 12th time is 24, the new slow start threshold is 12 (i.e., half of the number of tasks 24), and when pulling tasks for the 13th time, the number of tasks that can be pulled from the task queue is set to the preset initial value 1.
[0071] In the batch task execution module, based on the Reactor thread model, the pull tasks are executed through the responsibility chain.
[0072] When executing a task, it is necessary to determine whether the task has been successfully executed. If the cache retrieves the successful execution record of the task, it means that the task has been successfully executed; if the cache does not retrieve the successful execution record of the task, it means that the task has not been successfully executed, and the task will continue to be executed. When the task is successfully executed, the successful execution record of the task is stored in the cache and the cache expiration time is set. For example, for periodic tasks, the cache expires in the next execution cycle of the task. The cache is implemented using redis (Remote Dictionary Server).
[0073] In the batch task execution module, the local Reactor thread model is used to execute, avoiding the thread switching overhead during the execution process. The task is split into one or more subtasks, and the subtasks of the task are executed in the responsibility chain. When a subtask fails to execute, it will be retried in the responsibility chain if the upper limit of the retry times of the subtask is not reached. If a subtask still fails to execute after the retry times reach the upper limit, the task execution fails, and the failed task is saved to the task queue for re-execution.
[0074] Figure 5 It is a schematic diagram of a framework of task execution according to an embodiment of the present invention.
[0075] like Figure 5 As shown, the batch task execution module consists of a thread pool (i.e., a task event loop group, Task Event LoopGroup), which contains one or more threads (i.e., a task event loop, Task Event Loop). Tasks are added to the task registration list (Task Chanel Pipeline), and when tasks are executed, threads are allocated based on policies. A task is split into one or more subtasks, passed to one or more subtask handlers (Task Channel Handler) and executed in the form of a responsibility chain. If a subtask fails to execute, it continues to be retried. If a certain number of repeated executions is reached, the task is added to the batch message saving module for re-execution. Each thread has a corresponding task buffer queue (Scheduled Task Queue and Task Queue) to serve as a buffer for local tasks. If the task queue is full and the add task (Add Task) fails to execute, the task is added back to the batch message saving module.
[0076] Figure 6 4 is a schematic diagram of main modules of a task execution device according to an embodiment of the present invention.
[0077] like Figure 6 As shown, a task execution device 600 according to an embodiment of the present invention mainly includes: a pre-processing module 601 , a task saving module 602 , a task pulling module 603 , and a task execution module 604 .
[0078] The preprocessing module 601 is used to convert the input source data of the task into a task in a standard input sequence format through a preprocessor corresponding to the input source data of the task.
[0079] The task saving module 602 is used to save the tasks in the standard input sequence format into the task queue according to the subject of the task.
[0080] The task pulling module 603 is used to monitor the comprehensive index representing the execution capability of the server to determine the number of tasks that can be pulled from the task queue, and pull tasks from the task queue according to the number of tasks.
[0081] The task execution module 604 is used to execute the pulled tasks through the responsibility chain based on the preset thread model.
[0082] In one embodiment, the task pulling module is specifically used to: monitor whether various indicator values in the comprehensive indicators representing the execution capability of the server reach corresponding thresholds, the various indicator values include one or more of the server's load capacity indicator value, the upstream interface processing capability indicator value, and the database's load capacity indicator value; when no indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is determined according to the congestion control algorithm, and the congestion control algorithm includes congestion control of the following stages of the number of tasks to be pulled: exponential growth stage, congestion avoidance stage, and stable stage; when an indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is obtained by the preset starting value.
[0083] In one embodiment, the task pulling module is specifically used to: perform statistics on one or more of the server's load capacity index value, the upstream interface processing capacity index value, and the database's load capacity index value based on the query rate and response time per second.
[0084] In one embodiment, the task pulling module is specifically used for: in the exponential growth stage, taking the number of tasks pulled last time as the benchmark, and growing according to the exponential law to obtain the number of tasks that can be pulled from the task queue, wherein when the number of tasks pulled last time does not exist, the preset initial value is used as the benchmark; in the congestion avoidance stage, adding the preset value to the number of tasks pulled last time to obtain the number of tasks that can be pulled from the task queue; in the stable stage, the preset maximum pulling value is used as the number of tasks that can be pulled from the task queue.
[0085] In one embodiment, the task execution module is specifically used to: retrieve the successful execution record of the task in the cache; if it is determined that the successful execution record of the task is not retrieved, split the task into one or more subtasks based on a preset thread model; execute the subtasks of the task in the responsibility chain, and when the subtask fails to execute, retry the subtask in the responsibility chain under the condition that the upper limit of the retry number of the subtask is not reached, if a subtask still fails to execute after the number of retries reaches the upper limit of the retry number, the task execution fails, and the failed task is saved again in the task queue for re-execution.
[0086] In one embodiment, the task execution module is specifically used to: if the task is successfully executed, store the successful execution record of the task in the cache and set the cache expiration time, wherein for periodically executed tasks, the cache expires in the next execution cycle of the task.
[0087] In one embodiment, the task queue may be a distributed message queue, and the preset thread model may be an event-driven thread model.
[0088] In addition, the specific implementation content of the task execution device in the embodiment of the present invention has been described in detail in the above task execution method, so the repeated content will not be described again here.
[0089] Figure 7 An exemplary system architecture 700 is shown to which the task execution method or task execution apparatus according to the embodiments of the present invention can be applied.
[0090] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, 703, network 704 and server 705. Network 704 is used to provide a medium for communication links between terminal devices 701, 702, 703 and server 705. Network 704 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0091] Users can use terminal devices 701, 702, and 703 to interact with server 705 through network 704 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 701, 702, and 703, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0092] The terminal devices 701 , 702 , and 703 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0093] The server 705 may be a server that provides various services, such as a backend management server (only for example) that supports shopping websites browsed by users using the terminal devices 701, 702, and 703. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only for example) to the terminal device.
[0094] It should be noted that the task execution method provided in the embodiment of the present invention is generally executed by the server 705 , and accordingly, the task execution device is generally disposed in the server 705 .
[0095] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0096] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system 800 of a terminal device or server suitable for implementing an embodiment of the present invention. Figure 8 The terminal device or server shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0097] like Figure 8 As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the system 800 are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0098] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.
[0099] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present invention are executed.
[0100] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer 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 above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0101] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0102] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be arranged in a processor, for example, they may be described as: a processor including a preprocessing module, a task saving module, a task pulling module, and a task execution module. The names of these modules do not constitute limitations on the modules themselves in certain cases, for example, the task pulling module may also be described as "a module for monitoring a comprehensive index representing the execution capability of a server to determine the number of tasks that can be pulled from a task queue, and pulling tasks from the task queue according to the number of tasks".
[0103] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: converting the input source data of the task into a task in a standard input sequence format through a preprocessor corresponding to the input source data of the task; saving the task in the standard input sequence format into a task queue according to the subject of the task; monitoring a comprehensive indicator representing the execution capability of the server to determine the number of tasks that can be pulled from the task queue, and pulling tasks from the task queue according to the number of tasks; and executing the pulled tasks through a responsibility chain based on a preset thread model.
[0104] According to the technical solution of the embodiment of the present invention, the input source data of the task is converted into a task in the standard input sequence format through a preprocessor corresponding to the input source data of the task; the task in the standard input sequence format is saved in the task queue according to the subject of the task; the comprehensive index representing the execution capability of the server is monitored to determine the number of tasks that can be pulled from the task queue, and tasks are pulled from the task queue according to the number of tasks; based on the preset thread model, the pulled tasks are executed by means of a responsibility chain. It is possible to quantify the task execution rate based on comprehensive indicators such as server performance, database performance, and upstream interface performance, realize smooth processing of batch tasks, reduce the accumulation of batch tasks, reduce system resource consumption, and improve system stability.
[0105] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A task execution method, characterized in that: include: Converting the input source data of the task into a task in a standard input sequence format by a preprocessor corresponding to the input source data of the task; According to the subject of the task, the task in the standard input sequence format is saved in the task queue; Monitoring a comprehensive indicator representing the execution capability of the server to determine the number of tasks that can be pulled from the task queue, and pulling the tasks from the task queue according to the number of tasks; Based on the preset thread model, the pulled task is executed through the responsibility chain; The monitoring represents a comprehensive indicator of the execution capability of the server to determine the number of tasks that can be pulled from the task queue, including: monitoring whether various indicator values in the comprehensive indicator representing the execution capability of the server reach corresponding thresholds, the various indicator values including one or more of the server's load capacity indicator value, the upstream interface processing capacity indicator value, and the database's load capacity indicator value; when no indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is determined according to a congestion control algorithm, the congestion control algorithm includes congestion control of the number of tasks pulled in the following stages: an exponential growth stage, a congestion avoidance stage, and a stable stage; wherein the exponential growth stage is a stage in which the number of tasks pulled grows according to an exponential law, the congestion avoidance stage is a stage in which the number of tasks pulled grows according to an increasing law, and the stable stage is a stage in which the number of tasks pulled is stable at a preset maximum pulling value; when an indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is obtained from the preset starting value.
2. The method according to claim 1, characterized in that The monitoring of whether various indicator values in the comprehensive indicator representing the execution capability of the server reach corresponding thresholds includes: According to the query rate per second and the response time, statistics are collected on one or more of the load capacity index value of the server, the upstream interface processing capacity index value, and the load capacity index value of the database.
3. The method according to claim 2 or 1, characterized in that: The determining the number of tasks that can be pulled from the task queue according to the congestion control algorithm includes: In the exponential growth stage, the number of tasks pulled last time is used as a benchmark, and the number of tasks that can be pulled from the task queue is obtained according to the exponential growth law, wherein when the number of tasks pulled last time does not exist, the preset initial value is used as the benchmark; In the congestion avoidance phase, a preset value is added to the number of tasks pulled last time to obtain the number of tasks that can be pulled from the task queue; In the stable stage, a preset maximum pull value is used as the number of tasks that can be pulled from the task queue.
4. The method according to claim 1, characterized in that: The pulling task is executed based on the preset thread model by means of a responsibility chain, including: Retrieving the successful execution record of the task in the cache; In the case of determining that no successful execution record of the task is retrieved, splitting the task into one or more subtasks based on the preset thread model; Execute subtasks of the task in the responsibility chain. When the subtask fails to execute, retry the subtask in the responsibility chain under the condition that the upper limit of the retry times of the subtask is not reached. If any subtask still fails to execute after the retry times reach the upper limit, the task execution fails, and the failed task is saved again in the task queue for re-execution.
5. The method according to claim 4, characterized in that Also includes: If the task is executed successfully, a record of the successful execution of the task is stored in the cache, and a cache expiration time is set. For the task that is executed periodically, the cache expires in the next execution cycle of the task.
6. A task execution device, characterized in that: include: A preprocessing module, used for converting the input source data of the task into a task in a standard input sequence format through a preprocessor corresponding to the input source data of the task; A task saving module, used for saving the tasks in the standard input sequence format into a task queue according to the subject of the tasks; A task pulling module, used for monitoring a comprehensive index representing the execution capability of the server to determine the number of tasks that can be pulled from the task queue, and pulling the tasks from the task queue according to the number of tasks; A task execution module, used to execute the pulled task through a responsibility chain based on a preset thread model; The task pulling module is also used to: monitor whether various indicator values in the comprehensive indicator representing the execution capability of the server reach corresponding thresholds, the various indicator values include one or more of the server's load capacity indicator value, the upstream interface processing capability indicator value, and the database's load capacity indicator value; when no indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is determined according to the congestion control algorithm, and the congestion control algorithm includes congestion control of the number of tasks pulled in the following stages: exponential growth stage, congestion avoidance stage, and stable stage; the exponential growth stage is the stage in which the number of tasks pulled increases according to an exponential law, the congestion avoidance stage is the stage in which the number of tasks pulled increases according to an increasing law, and the stable stage is the stage in which the number of tasks pulled is stable at a preset maximum pulling value; when an indicator value reaches the corresponding threshold, the number of tasks that can be pulled from the task queue is obtained by the preset starting value.
7. The device according to claim 6, characterized in that The task pulling module is also used for: According to the query rate per second and the response time, statistics are collected on one or more of the load capacity index value of the server, the upstream interface processing capacity index value, and the load capacity index value of the database.
8. The device according to claim 6 or 7, characterized in that The task pulling module is also used for: In the exponential growth stage, the number of tasks pulled last time is used as a benchmark, and the number of tasks that can be pulled from the task queue is obtained according to the exponential growth law, wherein when the number of tasks pulled last time does not exist, the preset initial value is used as the benchmark; In the congestion avoidance phase, a preset value is added to the number of tasks pulled last time to obtain the number of tasks that can be pulled from the task queue; In the stable stage, a preset maximum pull value is used as the number of tasks that can be pulled from the task queue.
9. The device according to claim 6, characterized in that The task execution module is also used for: Retrieving the successful execution record of the task in the cache; In the case of determining that no successful execution record of the task is retrieved, splitting the task into one or more subtasks based on the preset thread model; Execute subtasks of the task in the responsibility chain. When the subtask fails to execute, retry the subtask in the responsibility chain under the condition that the upper limit of the retry times of the subtask is not reached. If any subtask still fails to execute after the retry times reach the upper limit, the task execution fails, and the failed task is saved again in the task queue for re-execution.
10. The device according to claim 9, characterized in that The task execution module is also used for: If the task is executed successfully, a record of the successful execution of the task is stored in the cache, and a cache expiration time is set. For the task that is executed periodically, the cache expires in the next execution cycle of the task.
11. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.
12. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Method for improving running speed of local method of application program, mobile terminal and computer readable storage medium
CN107729134A
Task processing method, server and storage medium
CN111858055A