Task execution method and device, electronic equipment and readable storage medium

By preempting and storing tasks when they are launched, duplicate execution is avoided and lock dependencies are reduced, thus solving the performance problem of task scheduling systems under high concurrency and achieving efficient task execution and throughput.

CN122431816APending Publication Date: 2026-07-21HANGZHOU NETEASE CLOUD MUSIC TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HANGZHOU NETEASE CLOUD MUSIC TECH CO LTD
Filing Date
2026-03-20
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

In high-concurrency scenarios, distributed locks can lead to performance degradation of task scheduling systems, task backlog, and execution delays, and there is also a risk of task duplication.

Method used

By introducing a locking mechanism when a task goes online, the target task is preempted and stored in the storage structure of the target scheduling instance, avoiding duplicate task execution. The task executor is triggered to execute the task during task execution time, reducing the dependence on distributed locks.

Benefits of technology

In high-concurrency scenarios, this avoids duplicate task execution, reduces the performance overhead of distributed locks, and improves the throughput and execution efficiency of the task scheduling system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122431816A_ABST
    Figure CN122431816A_ABST
Patent Text Reader

Abstract

The present disclosure provides a task execution method and device, electronic equipment and readable storage medium. The present disclosure acquires a target task and stores it in a target storage space, sets the state of the target task as a first state, wherein the first state indicates that the target task is not held; in response to detecting the target task in the first state in the target storage space, the target task is preempted by at least two scheduling instances; in the case that the target task is successfully preempted by a target scheduling instance among the at least two scheduling instances, the target task is stored in a target storage structure corresponding to the target scheduling instance; when the execution time of the target task is reached, the target task is acquired from the target storage structure by the target scheduling instance and the corresponding task executor is triggered to execute the target task, which can not only avoid the repeated execution of the task in the high-concurrent task execution scenario, but also reduce the performance loss of the distributed lock to the system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and more specifically to a task execution method, apparatus, electronic device, and readable storage medium. Background Technology

[0002] A distributed task scheduling system refers to a system that schedules different task executors to execute tasks. To prevent the same task from being executed repeatedly by multiple task executors, distributed locks are introduced during the task executor scheduling process.

[0003] However, in high-concurrency scenarios, a large number of scheduling requests will simultaneously compete for the distributed lock, which not only reduces the throughput of task scheduling but may also cause problems such as task backlog and execution delays. Therefore, distributed locks can negatively impact the performance of distributed task scheduling systems under high concurrency. Summary of the Invention

[0004] This disclosure provides a task execution method, apparatus, electronic device, and readable storage medium, which can not only avoid repeated execution of tasks in scenarios with high concurrency of task execution, but also reduce the performance loss of the system caused by distributed locks.

[0005] In a first aspect, embodiments of this disclosure provide a task execution method, applied to a system including at least two scheduling instances, the method comprising: Obtain the target task and store it in the target storage space, and set the status of the target task to a first state, wherein the first state indicates that the target task is not held; In response to detecting a target task in the first state in the target storage space, the target task is preempted by at least two scheduling instances. If the target scheduling instance in at least two of the above scheduling instances successfully preempts the target task, the target task is stored in the target storage structure corresponding to the target scheduling instance. After the target task is successfully preempted, the target task is in a second state, which indicates that the target task has been held by the target scheduling instance. When the execution time of the aforementioned target task arrives, the aforementioned target task is retrieved from the aforementioned target storage structure through the aforementioned target scheduling instance, and the corresponding task executor is triggered to execute the aforementioned target task.

[0006] Secondly, embodiments of this disclosure provide a task execution apparatus, which is applied to a system including at least two scheduling instances. The apparatus includes: The first storage module is used to acquire the target task and store it in the target storage space, and set the status of the target task to a first state, wherein the first state indicates that the target task is not held. The task preemption module is used to preempt the target task by using at least two scheduling instances in response to detecting a target task in the first state in the target storage space. The second storage module is used to store the target task in the target storage structure corresponding to the target scheduling instance when the target scheduling instance of the above at least two scheduling instances successfully preempts the target task. The target task is in a second state after the target task is successfully preempted, and the second state indicates that the target task has been held by the target scheduling instance. The scheduling module is used to retrieve the target task from the target storage structure through the target scheduling instance and trigger the corresponding task executor to execute the target task when the execution time of the target task arrives.

[0007] Thirdly, embodiments of this disclosure also provide an electronic device, including a memory storing multiple instructions; a processor loading instructions from the memory to execute the steps of any of the task execution methods provided in embodiments of this disclosure.

[0008] Fourthly, embodiments of this disclosure also provide a computer-readable storage medium storing a plurality of instructions adapted for loading by a processor to perform the steps of any of the task execution methods provided in embodiments of this disclosure.

[0009] Fifthly, embodiments of this disclosure also provide a computer program product, including a computer program or instructions, which, when executed by a processor, implement the steps in any task execution method provided in embodiments of this disclosure.

[0010] In this embodiment, a target task is acquired and stored in a target storage space. The state of the target task is set to a first state, indicating that the target task is not held. In response to detecting a target task in the first state in the target storage space, the target task is preempted by at least two scheduling instances. If the target scheduling instance among the at least two scheduling instances successfully preempts the target task, the target task is stored in the target storage structure corresponding to the target scheduling instance. After the target task is successfully preempted, it is in a second state, indicating that the target task has been held by the target scheduling instance. When the execution time of the target task arrives, the target scheduling instance retrieves the target task from the target storage structure and triggers the corresponding task executor to execute the target task. This achieves task preemption when the task is online, ensuring that the task is held by only one scheduling instance to avoid repeated execution. Furthermore, it eliminates the need to preempt locks and preempt tasks from the time the task is preempted until the task is triggered. This not only avoids repeated execution of tasks under high concurrency but also reduces the performance loss caused by the locking mechanism.

[0011] Other features and advantages of this disclosure will be described in detail in the following detailed description section. Attached Figure Description

[0012] To more clearly illustrate the technical solutions in the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 This is a schematic diagram illustrating an application scenario of the task execution method provided by an exemplary embodiment of this disclosure; Figure 2 This is a schematic diagram illustrating another application scenario of the task execution method provided by the exemplary embodiments of this disclosure; Figure 3 This is a flowchart illustrating the task execution method provided in an exemplary embodiment of this disclosure; Figure 4 This is a schematic diagram illustrating the interaction between the system, task executor, database, and registry center provided in an exemplary embodiment of this disclosure; Figure 5 This is a schematic diagram illustrating the scheduling instance preemption of tasks provided by an exemplary embodiment of this disclosure; Figure 6 This is a schematic diagram of a task execution apparatus provided in an exemplary embodiment of this disclosure; Figure 7 This is a schematic diagram of an electronic device provided by an exemplary embodiment of this disclosure. Detailed Implementation

[0014] The technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure. Furthermore, in the description of the embodiments of this disclosure, the terms "first," "second," etc., are only used for distinguishing descriptions and should not be construed as indicating or implying relative importance. Thus, features defined as "first" or "second" may explicitly or implicitly include one or more features. In the description of the embodiments of this disclosure, "multiple" means two or more, unless otherwise explicitly specified. "A and / or B" includes the following three combinations: only A, only B, and a combination of A and B.

[0015] The use of “applies to” or “configured to” in this disclosure implies open and inclusive language, which does not exclude applicability to or configuration to devices performing additional tasks or steps. Additionally, the use of “based on” implies openness and inclusiveness, because processes, steps, calculations, or other actions “based on” one or more of the stated conditions or values ​​may in practice be based on additional conditions or values ​​beyond those stated.

[0016] In this disclosure, the term "exemplary" is used to mean "serving as an example, illustration, or description." Any embodiment described as "exemplary" in this disclosure is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use this disclosure. In the following description, details are set forth for purposes of explanation. It should be understood that those skilled in the art will recognize that this disclosure can be made without using these specific details. In other instances, well-known structures and processes will not be described in detail to avoid obscuring the description of this disclosure with unnecessary detail. Therefore, this disclosure is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed herein.

[0017] This disclosure provides a task execution method, apparatus, electronic device, and computer-readable storage medium. Specifically, this embodiment will be described from a system perspective, which can be deployed in at least one electronic device. That is, the task execution method of this disclosure can be executed by the electronic device, and optionally, the electronic device may include a server.

[0018] Optionally, the server can be a standalone server, or a server network or server cluster, including but not limited to computers, network hosts, single network servers, multiple network server sets, or cloud servers composed of multiple servers. Cloud servers consist of a large number of computers or network servers based on cloud computing.

[0019] The following is based on Figure 1 and Figure 2 The task execution method provided in this embodiment will be described below. Figure 1 As shown, the system is deployed in a scheduling server, with at least two scheduling instances, namely scheduling instance s1, scheduling instance s2, ... and scheduling instance sn (n represents the number of scheduling instances). Both scheduling instances reside in this scheduling server. The task executors reside in the business server, namely task executor t1, task executor t2, ... and task executor tm (m represents the number of task executors). The scheduling server, through the system, responds to the online request of the target task by storing the target task in the target storage space and setting the target task's status to a first state. The first state indicates the target... If a task is not held, in response to detecting a target task in the first state in the target storage space, the target task is preempted by at least two scheduling instances. If the target scheduling instance among the at least two scheduling instances successfully preempts the target task, the target task is stored in the target storage structure corresponding to the target scheduling instance. When the target task is successfully preempted, its state in the target storage space is set to the second state, indicating that the target task has been held by the target scheduling instance. When the execution time of the target task in the target storage structure arrives, the task executor corresponding to the target task in the scheduling business server executes the target task through the target scheduling instance.

[0020] like Figure 2As shown, the system is deployed in at least two scheduling servers, namely scheduling server b1, scheduling server b2, ... and scheduling server bj (j represents the number of scheduling servers). Each scheduling server includes at least one scheduling instance. The task executor is located in the business server. The target scheduling server, in response to the online request of the target task, stores the target task in the target storage space and sets the status of the target task to a first state, where the first state indicates that the target task is not held. In response to the detection of a target task in the first state in the target storage space, the target task is preempted by at least two scheduling instances. If the target scheduling instance among the at least two scheduling instances successfully preempts the target task, the target task is stored in the target storage structure corresponding to the target scheduling instance. When the target task is successfully preempted, the status of the target task in the target storage space is set to a second state, where the second state indicates that the target task has been held by the target scheduling instance. Through the target scheduling instance, when the execution time of the target task in the target storage structure arrives, the task executor corresponding to the target task in the scheduling business server executes the target task.

[0021] The following is a detailed description in conjunction with the accompanying drawings. It should be noted that the order of description of the following embodiments is not intended to limit the preferred order of the embodiments. Although a logical order is shown in the flowcharts, in some cases, the steps shown or described may be performed in a different order than that shown in the drawings.

[0022] Please refer to Figure 3 This task execution method is applied to a system that includes at least two scheduling instances. The specific flow of this task execution method can be summarized in steps 301 to 304, where: Step 301: Obtain the target task and store it in the target storage space. Set the status of the target task to the first state, where the first state indicates that the target task is not held.

[0023] The system may include a task scheduling system, which comprises at least two scheduling instances. A task scheduling system refers to a collection of code capable of receiving and assigning tasks. The task scheduling system can be deployed on at least one server. A scheduling instance refers to a service process or pod capable of assigning tasks. Different scheduling instances can reside on the same server or on different servers. Optionally, scheduling instances can be stateless services, allowing for scaling up or down.

[0024] The target task refers to the task newly configured by the user to be executed. The specific content of the target task can be set according to the actual situation. For example, the target task can be a scheduled task or a periodically executed task. A scheduled task is such as a scheduled accounting task, and a periodically executed task is such as a payment timeout shutdown task. This embodiment does not limit this.

[0025] The target storage space refers to the medium used to store various tasks and their task data. Its type can be set according to actual needs; for example, the target storage space can be a database or a data lake, but this embodiment does not limit this. Optionally, the target storage space may include a task table, which may include task data (also known as task metadata). The task data includes information such as the task name and task status.

[0026] The first state indicates that the target task is not held by a scheduling instance, so that each scheduling instance can preempt the target task based on the first state. Optionally, the target task not being held by a scheduling instance can be understood as the target task not being bound to a scheduling instance. Optionally, a state variable can be set in the target storage space. When the value of the state variable is the first character (the first character can be at least one of a number, a letter, or a special character), it indicates that the state of the target task is the first state.

[0027] Optionally, the target task can be obtained when it comes online. In this case, the target task is obtained in response to the online request and stored in the target storage space. The online request of the target task is used to indicate the request to write the target task into the target storage space, so that the scheduling instance can preempt the target task and trigger its execution.

[0028] Step 302: In response to detecting a target task in the first state in the target storage space, preempt the target task by at least two scheduling instances.

[0029] Each scheduling instance can monitor the status of each task in the target storage space in real time. When a task in the first state is detected, the instance preempts that task. Optionally, task preemption by a scheduling instance can be understood as the scheduling instance requesting lock permission for the target task in the target storage space. A scheduling instance that successfully requests lock permission can change the status of the target task in the target storage space from the first state to the second state, thus successfully preempting the target task. Alternatively, after preempting the target task, the instance can change the status of the target task from the first state to the second state. Optionally, the value of the target task's status variable can be modified from the first character to the second character, thereby changing the target task's status from the first state to the second state. Optionally, the process of preempting the target task through at least two scheduling instances can be configured according to actual conditions, and this embodiment does not limit this.

[0030] In some embodiments, in response to detecting a target task in a first state in the target storage space, preempting the target task by at least two scheduling instances includes: The status of tasks in the target storage space is detected using at least two scheduling instances; When a target task in the first state is detected, the lock access for the target task in the target storage space is preempted; In response to the target scheduling instance successfully preempting the lock, the state of the target task is set to the second state, so that the target scheduling instance can successfully preempt the target task.

[0031] Lock permissions refer to the mechanism in the target storage space that allows modification of the target task. When a scheduling instance acquires the lock permission of the target task, it means that the scheduling instance can modify the state of the target task, which means that the scheduling instance has successfully acquired the target task.

[0032] For example, a scheduling instance sends an update request for a target task to the target storage space. The update request includes the scheduling instance's instance identifier, the target task's name, and its first state. The target storage space then searches for the target task's task data based on its name, determining if the state is the first state. If the state is the first state, the scheduling instance locks the target task's task data, indicating it has successfully acquired the lock. The first state in the target task's task data is then changed to the second state, and the instance identifier carried in the update request is written to it. A response indicating a successful update is returned. If the state is not the first state, it means the target task has already been acquired by another scheduling instance, indicating the scheduling instance failed to acquire the lock and a response indicating update failure is returned directly. When a scheduling instance receives a response indicating a successful update, it means that the scheduling instance has successfully acquired the task.

[0033] For example, a scheduling instance sends a lock request for a target task to the target storage space. The target storage space checks if the target task is already locked based on the lock request, indicating whether the lock privileges have been preempted by another scheduling instance. If not locked, the target task is locked, and a successful lock result is returned to the scheduling instance, indicating that the scheduling instance has acquired the lock privileges. If locked, a lock failure result is returned. Upon receiving a successful lock result, the scheduling instance checks if the target task's status is in state one. If so, an update request is sent to the target storage space. The target storage space changes the target task's status from state one to state two based on the update request and writes the instance identifier of the scheduling instance to successfully acquire the target task. The lock on the target task is released upon completion of the update.

[0034] In this embodiment, a locking mechanism is used when a task is launched, instead of a distributed locking mechanism during task triggering. This not only prevents the task from being executed repeatedly, but also eliminates the need to use a distributed lock between when a task is preempted and when it is triggered. This reduces the performance overhead of distributed locks on the system under high concurrency.

[0035] Step 303: If the target scheduling instance in at least two scheduling instances successfully preempts the target task, the target task is stored in the target storage structure corresponding to the target scheduling instance. After the target task is successfully preempted, the target task is in a second state, which indicates that the target task has been held by the target scheduling instance.

[0036] In this implementation, when the target task is in the second state, other scheduling instances can recognize that the target task has been preempted by the target scheduling instance and will no longer preempt it. A target scheduling instance refers to a scheduling instance where at least two scheduling instances have preempted the target task. Each scheduling instance has a corresponding storage structure; the storage structure corresponding to the target scheduling instance is called the target storage structure. The type of storage structure can be set according to actual conditions; for example, the storage structure can be a linked list or an array, which is not limited in this embodiment.

[0037] Optionally, the task data of the target task may also include the execution time of the target task. Storing the target task in the target storage structure can be understood as storing the name of the target task in the target storage structure according to the execution time of the target task, or storing the name and execution time of the target task in the target storage structure. This embodiment does not limit this.

[0038] Step 304: When the execution time of the target task arrives, retrieve the target task from the target storage structure through the target scheduling instance and trigger the corresponding task executor to execute the target task.

[0039] In this context, a task executor can be understood as a method that encapsulates specific business logic. Specifically, it can be a task execution instance. Different task executors can reside on the same server or on different servers. The task executor corresponding to the target task refers to the task executor capable of completing the target task. Optionally, since there are usually multiple task executors to complete a task, scheduling the task executor corresponding to the target task to execute the target task can be understood as determining the target task executor from among the task executors corresponding to the target task and assigning the target task to the target task executor for execution. Optionally, there can be at least one target task executor. When there are multiple target task executors, the target task can be split into sub-tasks, and each sub-task can be assigned to a different target task executor for execution.

[0040] Optionally, when the target storage structure includes the execution time of the target task, the execution time in the target storage structure can be viewed through the target scheduling instance. If the current time is the execution time, the second task corresponding to that execution time is retrieved from the target storage structure, and the task executor corresponding to the second task is scheduled to execute the second task. The second task refers to the task whose execution time is the current time. When the execution time of the target task is the current time, the target task is the second task. When the target task is stored in the target storage structure according to its execution time, the position of the target task in the target storage structure can be used to indicate the execution time of the target task. When the pointer points to the position of the target task, it indicates that the current time is the execution time of the target task, and the task executor corresponding to the target task is scheduled to execute the target task.

[0041] Optionally, the task executor corresponding to the target task can be called asynchronously or synchronously; this embodiment does not impose any limitations on this.

[0042] In some embodiments, the task data of the target task in the target storage space may include an executor identifier of the task executor that completes the target task. The executor identifier of the task executor can be stored in the target storage structure. Then, through the target scheduling instance, when the execution time of the target task in the target storage structure arrives, the task executor corresponding to the target task is scheduled to execute the target task, including: When the execution time of the target task in the target storage structure is reached through the target scheduling instance, the task executor corresponding to the executor identifier in the target storage structure is invoked to execute the target task.

[0043] However, binding a task executor to a target task can lead to a situation where, if the executor can execute different types of tasks and has a high load, the actual execution time of the target task may be later than its actual execution time, resulting in low flexibility. Therefore, in some embodiments, when the execution time of the target task is reached, the target task is retrieved from the target storage structure through a target scheduling instance, and the corresponding task executor is triggered to execute the target task. This includes: By using the target scheduling instance, when the execution time of the target task arrives, the description information of the functions implemented by each task executor is obtained; Based on the description information of the functions implemented by each task executor, the task executor corresponding to the target task is determined from among the task executors. The task executor corresponding to the target task is scheduled to execute the target task.

[0044] The description information describes the functions implemented by the task executor. Optionally, the description information may include the functions possessed by the task executor, such as the task executor having a calculation function. After obtaining the target task through the target scheduling instance, the task description of the target task (which may be included in the task data) can be matched with the description information, and the task executor corresponding to the description information that matches the task description is determined as the task executor corresponding to the target task.

[0045] Optionally, the similarity between the task description and the description information can be determined. The description information that matches the task description is the description information with the highest similarity to the task description. The task executor corresponding to the description information with the highest similarity to the task description is determined as the task executor corresponding to the target task.

[0046] For example, task executor a1 has an accounting function, task executor a2 has a payment timeout shutdown function, and the task description of the target task includes performing accounting bill calculations every day at midnight. The description information of task executor a1 has the highest similarity to the task description, so task executor a1 is the target task executor.

[0047] Optionally, after determining the task executor corresponding to the target task, the target task executor can be determined from the task executors corresponding to the target task based on the load information of the task executor corresponding to the target task, and the target task executor can be called to execute the target task.

[0048] Optionally, when the target task is broken down into sub-tasks, each sub-task can be executed in parallel or sequentially. Since the execution of a sub-task depends on the result of another sub-task when it is executed sequentially, the different sub-tasks corresponding to the target task can be divided based on the load information of the sub-tasks and the transmission time between them. This results in a syndicate, where each syndicate includes sub-tasks used to complete the sub-tasks. The syndicate with the shortest total completion time is selected as the target task syndicate, thereby reducing the target task's completion time.

[0049] For example, the target task can be broken down into target subtasks k1 and k2. The execution of target subtask k2 depends on the execution result of target subtask k1. The task executors corresponding to the target task include task executor a1, task executor a2, and task executor a3. Task executor a1 completes target subtask k1 in 2 seconds, task executor a2 completes target subtask k2 in 3 seconds, the transmission time between task executors a1 and a2 is 0.5 seconds, the total completion time of task executors a1 and a2 to complete the target task is 5.5 seconds, task executor a3 completes target subtask k2 in 3 seconds, the transmission time between task executors a1 and a3 is 10 seconds, and the total completion time of task executors a1 and a3 to complete the target task is 15 seconds. Task executors a1 and a2 are then identified as the target task executors.

[0050] Optionally, when a task executor registers with the registry center, it can register its description information with the registry center so that each scheduling instance can obtain the description information of each task executor from the registry center. In this case, the scheduling instance can obtain the address information of each task executor from the registry center, obtain its description information, and store it. Then, when the execution time of the target task in the target storage structure arrives, it can read the description information of each task executor.

[0051] In this embodiment, through a target scheduling instance, when the execution time of the target task arrives, the description information of the functions implemented by each task executor is obtained; based on the description information of the functions implemented by each task executor, the task executor corresponding to the target task is determined from among the task executors; the task executor corresponding to the target task is scheduled to execute the target task, reducing the binding degree between the task and the task executor, realizing dynamic matching of the task and the task executor, so that the task can be matched with the task executor with less load, ensuring that the actual execution time of the target task is the same as the execution time of the target task, and improving the flexibility of task execution.

[0052] In some embodiments, the target storage structure includes a time wheel, which includes a time wheel pointer and multiple time wheel nodes. Each time wheel node is used to store tasks executed at the same time. Storing the target task into the target storage structure corresponding to the target scheduling instance includes: Based on the execution time of the target task, the target task is stored in the time wheel corresponding to the target scheduling instance. The target time wheel node in the time wheel is used to indicate the execution time of the target task. When the execution time of the target task arrives, the target task is retrieved from the target storage structure through the target scheduling instance, and the corresponding task executor is triggered to execute the target task, including: Through the target scheduling instance, when the time wheel pointer executes the target time wheel node, the task in the target time wheel node is retrieved and the task executor corresponding to the task in the target time wheel node is scheduled to execute the task in the target time wheel node.

[0053] The execution time of the target task can be represented by a timing rule expression. The target scheduling instance can obtain the execution time of the target task by parsing the timing rule expression. The time wheel can be understood as a circular array. A time wheel node refers to a slot in the circular array, with each slot representing a certain time length (tick). The target time wheel node refers to the time wheel node that stores the target task; the tasks in the target time wheel node include the target task. Optionally, the task executors corresponding to tasks in the same time wheel node can be the same or different.

[0054] Specifically, the target duration between the current time and the execution time can be determined through a target scheduling instance. The target duration is divided by the time length to obtain the number of lengths. The index of the time wheel node currently pointed to by the time wheel pointer is added to the number of lengths. The result is then moduloed by the total number of time wheel nodes to obtain the target index, which is the index of the target time wheel node. For example, if the time length is 1 second, the total number of time wheel nodes is 60, the index of the time wheel node currently pointed to by the time wheel pointer is 10, and the target task will execute in 5 seconds (i.e., the target duration is 5 seconds), the target duration is divided by the time length to obtain the number of lengths, which is 5. The index of the time wheel node currently pointed to by the time wheel pointer is added to the number of lengths, resulting in 15. The result is then moduloed by the total number of time wheel nodes to obtain the target index, which is 15. The target time wheel node is the 15th time wheel node.

[0055] Optionally, the target scheduling instance may include a preemption thread and a time wheel thread. The preemption thread is used to preempt the target task and store the target task in the target storage structure, and the time wheel thread is used to implement the time wheel pointer.

[0056] Optionally, when determining the task executor corresponding to the target task from among the task executors based on the description information of the functions implemented by each task executor, it can be done through the target scheduling instance. When the time wheel pointer executes the target time wheel node, the task in the target time wheel node is retrieved, and the task executor corresponding to the task in the target time wheel node is determined from among the task executors based on the description information of the functions implemented by each task executor. The task executor corresponding to the task in the target time wheel node is then scheduled to execute the task in the target time wheel node.

[0057] In this embodiment, the target storage structure includes a time wheel, which includes a time wheel pointer and multiple time wheel nodes. Each time wheel node is used to store tasks that are executed at the same time. According to the execution time of the target task, the target task is stored in the time wheel corresponding to the target scheduling instance. The target time wheel node of the target task in the time wheel is used to indicate the execution time of the target task. Through the target scheduling instance, when the time wheel pointer executes the target time wheel node, the task in the target time wheel node is retrieved and the task executor corresponding to the task in the target time wheel node is scheduled to execute the task in the target time wheel node. This realizes the time wheel to trigger tasks at regular intervals, achieving high throughput and low latency task scheduling.

[0058] In some embodiments, the target task is a periodically executed task. This embodiment further includes: re-storing the target task in the time wheel corresponding to the target scheduling instance based on the execution time of the target task. A periodically executed task refers to a task that executes cyclically, such as a task that executes at 12 noon every day or a task that executes every 3 hours. When the target task is a periodically executed task, even if the target task has already been triggered, it may still need to be triggered later. Therefore, in this embodiment, after the target task is executed, it is re-stored in the time wheel corresponding to the target scheduling instance, so that the target task can be triggered again without preemption, further reducing the performance overhead of the distributed lock on the system.

[0059] In some embodiments, this embodiment also includes: The system receives the registration information of the task executor through the corresponding registration center. The registration information includes the address information and protocol information of the task executor. The protocol information is used to indicate the service communication protocol of the task executor. At least two scheduling instances are used to obtain and store address and protocol information from the registry center. When the execution time of the target task arrives, the target task is retrieved from the target storage structure through the target scheduling instance, and the corresponding task executor is triggered to execute the target task, including: Through the target scheduling instance, when the execution time of the target task arrives, the target task is scheduled to execute the target task according to the service communication protocol indicated by the protocol information of the target task's corresponding task executor and based on the address information of the target task's corresponding task executor.

[0060] The system's registry center can refer to the registry center associated with the system, which is used to receive the registration information of task executors so that scheduling instances can obtain the registration information of task executors from the registry center. The type of registry center can be set according to the actual situation. For example, the registry center can be Etcd, ZooKeeper, or Kubernetes. This embodiment does not limit this.

[0061] The address information of the task executor indicates the address or path of the task executor, and may include data such as the task executor's interface, IP address, or port. The service communication protocol refers to the rules followed when different programs communicate, and may include at least one. The type of service communication protocol can be set according to actual conditions; for example, the service communication protocol may be at least one of Dubbo, HTTP, and GRPC, which is not limited in this embodiment.

[0062] Optionally, the protocol information can be a description rule of the service communication protocol. The description rule is used to indicate how to use the service communication protocol. The registry center can store the storage address of the description rule, and the scheduling instance can then download the description rule from the corresponding storage address.

[0063] After obtaining the address and protocol information, each scheduling instance can store this information in a local cache. When the execution time of the target task arrives, it queries the local cache for the address and protocol information of the task executor corresponding to the target task. If not found, it queries the registry center again. The target scheduling instance can first determine the target task executor from among the task executors corresponding to the target task, and then construct a call request to execute the target task according to the service communication protocol of the target task executor. Based on the address information of the target task executor, the call request is sent to the target task executor. The target task executor then executes the target task based on the call request and returns the task execution result to the target scheduling instance.

[0064] Optionally, the target task executor may return the task execution result to the target scheduling instance according to the target task executor's service communication protocol, or it may call the callback interface of the target scheduling instance to return the task execution result to the target scheduling instance. This embodiment does not limit this.

[0065] Optionally, when executing a target time wheel node through a target scheduling instance, and retrieving tasks from the target time wheel node and scheduling the task executor corresponding to the task in the target time wheel node to execute the task in the target time wheel node, when executing a target time wheel node through a target scheduling instance, the task in the target time wheel node can be retrieved through the target scheduling instance, and the task executor corresponding to the task in the target time wheel node can be scheduled to execute the task in the target time wheel node based on the address information of the task executor corresponding to the task in the target time wheel node, according to the service communication protocol indicated by the protocol information of the task executor corresponding to the task in the target time wheel node.

[0066] In related technologies, task executors require the system's SDK to interact with the system. When the development language of the task executor and the SDK differs, incompatibility arises, rendering the SDK unusable. In this embodiment, the system's registration center receives the task executor's registration information, including its address and protocol information. The protocol information indicates the task executor's service communication protocol. At least two scheduling instances retrieve and store the address and protocol information from the registration center. Upon reaching the execution time of the target task in the target storage structure, the target scheduling instance, based on the address information of the target task's corresponding task executor, schedules the target task's corresponding task executor to execute the target task according to the service communication protocol indicated by the target task's protocol information. This allows the system to call the task executor without an SDK, reducing usage costs. Furthermore, it enables the system to call the task executor even if the system and the task executor use different development languages, supporting cross-language projects. Additionally, multiple service communication protocols can be used, increasing flexibility.

[0067] In some embodiments, the registry center is further configured to receive load information of the task executor, and through the target scheduling instance, when the execution time of the target task arrives, schedule the task executor corresponding to the target task to execute the target task according to the service communication protocol indicated by the protocol information of the task executor corresponding to the target task and based on the address information of the task executor corresponding to the target task, including: By using the target scheduling instance, when the execution time of the target task arrives, the load information of the task executor corresponding to the target task is obtained from the registry center; Based on the load information, the task executor of the target task is determined from the task executor corresponding to the target task; According to the service communication protocol indicated by the protocol information of the target task executor, and based on the address information of the target task executor, the target task executor is invoked to execute the target task.

[0068] The load information indicates the workload currently being processed by the task executor. For example, it could be the number of tasks being executed, or the CPU and / or memory utilization of the task executor. After obtaining the load information, the target scheduling instance can determine the idle level of the task executors based on the load information, selecting the task executor with the highest idle level as the target task executor, or sorting the idle levels and selecting the top preset number of task executors with the highest idle levels as target task executors.

[0069] In this embodiment, the task executor can report its own load information to the registry center. The registry center then receives the load information of the task executor and, through the target scheduling instance, obtains the load information of the task executor corresponding to the target task from the registry center when the execution time of the target task arrives. Based on the load information, the target task executor is determined from the task executor corresponding to the target task. According to the service communication protocol indicated by the protocol information of the target task executor, and based on the address information of the target task executor, the target task executor is invoked to execute the target task. This allows the registry center to receive not only static information of the task executor but also dynamic information of the task executor, thereby making the invocation of task executors more balanced, improving the real-time performance and accuracy of the load information, and further improving the efficiency of task completion.

[0070] In some embodiments, this embodiment further includes: Receive heartbeat information periodically sent by at least two scheduling instances for different first tasks, wherein the first task is the task held by each of the at least two scheduling instances, and the first task includes the target task; Update the heartbeat time of the first task in the target storage space based on the heartbeat information; If the difference between the heartbeat time and the current time exceeds a preset threshold, the state of the first task corresponding to the heartbeat time will be changed from the second state to the first state.

[0071] The preset threshold is a pre-set duration, which can be set according to actual conditions. For example, the preset threshold can be 20 seconds or 30 seconds, which is not limited in this embodiment. Optionally, the scheduling instance can send heartbeat information at different times for different first tasks. For example, the scheduling instance holds task k1 and task k2, and the first task includes task k1 and task k2. The scheduling instance preempts task k1 at time A, and then sends heartbeat information to the target storage space every T starting from time A. The target storage space updates the heartbeat time of task k1 based on the heartbeat information. The target scheduling instance preempts task k2 at time B, and then sends heartbeat information to the target storage space every T starting from time B. The target storage space updates the heartbeat time of task k2 based on the heartbeat information. If the difference between the heartbeat time of task k1 and the current time exceeds the preset threshold, the state of task k1 in the target storage space is modified to the first state so that other scheduling instances can continue to preempt task k1.

[0072] Since problems may occur during the execution of the first task held by each scheduling instance, and the scheduling instance cannot complete the first task when a problem occurs, this embodiment receives heartbeat information periodically sent by at least two scheduling instances for different first tasks. The first task is a task held by each of the at least two scheduling instances, and the first task includes a target task. The heartbeat time of the first task in the target storage space is updated based on the heartbeat information. If the difference between the heartbeat time and the current time exceeds a preset threshold, the state of the first task corresponding to the heartbeat time is set from a second state to a first state, so that other scheduling instances can continue to preempt the task if it cannot be completed, ensuring the execution of the task.

[0073] In some embodiments, since the target scheduling instance may fail, all first tasks held by the target scheduling instance may fail to execute. Therefore, in this embodiment, each scheduling instance can also periodically send heartbeat information to the system. Based on the heartbeat information, the system updates the heartbeat time of the scheduling instance. If the difference between the heartbeat time of the scheduling instance and the current time exceeds a target preset threshold, the status of all first tasks held by the scheduling instance is changed from the second state to the first state, so that other scheduling instances can continue to preempt all first tasks held by the scheduling instance, ensuring the availability of the scheduling instance, thereby reducing operation and maintenance operations and thus reducing operation and maintenance costs.

[0074] The following is based on Figure 4 and Figure 5 The task execution method provided in this disclosure will be further explained. In this embodiment, a database is used as an example of the target storage space for illustration.

[0075] like Figure 4 As shown, the system includes a front-end control module and a data processing back-end. The front-end control module includes a task control interface, which is used for user task configuration, task scheduling control, display of task execution data, and user and task permission control. Users configure target tasks through the task space interface. Upon completion of the target task configuration, the front-end control module generates a launch request for the target task and sends it to the database. The database stores the target task and sets its status to the first state.

[0076] The data processing backend includes a task scheduling module, a task alarm module, a parsing module, and task triggers. The task scheduling module comprises at least two scheduling instances. Each instance, upon detecting a target task in its first state in the target storage space, preempts the target task. If a scheduling instance successfully preempts the target task, it stores the target task in the target storage structure corresponding to that instance. When the execution time of the target task in the target storage structure arrives, the scheduling instance retrieves the target task and sends it to the task executor for execution via the task trigger. The task alarm module sends alarm information to the task control interface for display when task execution encounters an anomaly. The parsing module generates a call request based on the service communication protocol's description rules (which indicate how to invoke the task executor). For example, when the service communication protocol is HTTP, the HTTP protocol's description rule is OpenAPI. The target scheduling instance generates a call request based on the OpenAPI specification through the parsing module and sends the call request to the task executor, enabling the task executor to execute the target task based on the call request, thus achieving communication with the task executor via the HTTP protocol.

[0077] The process of scheduling instances preempting tasks can be described as follows: Figure 5 As shown, the scheduling cluster includes scheduling instances s1, s2, and s3. Scheduling instances s1, s2, and s3 preempt task k1 from the database. When scheduling instance s1 successfully preempts task k1, it periodically updates the heartbeat time of the task at the end of the preemption period. Optionally, the scheduling instances also support functional extensions. Developers can develop task executors following the interface conventions in the scheduling instances and add them to the system so that the scheduling instances can obtain the registration information of the newly developed task executors from the registry center.

[0078] As can be seen from the above, in this embodiment of the disclosure, the target task is acquired and stored in the target storage space, and the state of the target task is set to a first state, wherein the first state indicates that the target task is not held; in response to detecting the target task in the first state in the target storage space, the target task is preempted by at least two scheduling instances; if the target scheduling instance among the at least two scheduling instances successfully preempts the target task, the target task is stored in the target storage structure corresponding to the target scheduling instance, wherein after the target task is successfully preempted, the target task is in a second state, the second state indicating that the target task has been held by the target scheduling instance; when the execution time of the target task arrives, the target scheduling instance retrieves the target task from the target storage structure and triggers the corresponding task executor to execute the target task, thereby realizing the preemption of the task when the task comes online. This not only ensures that the task is owned by only one scheduling instance to avoid the task being executed repeatedly, but also ensures that from the time the task is preempted until the task is triggered, there is no need to preempt the lock and thus no need to preempt the task. Therefore, under high concurrency, not only can the task be avoided from being executed repeatedly, but the performance loss caused by the locking mechanism to the system can also be reduced.

[0079] This embodiment also provides a task execution device, which is applied to a system including at least two scheduling instances. The task execution device is, for example, as shown in... Figure 6 As shown, the task execution device may include: The first storage module 601 is used to acquire the target task and store it in the target storage space, and set the status of the target task to a first state, wherein the first state indicates that the target task is not held.

[0080] The task preemption module 602 is used to preempt the target task by using at least two scheduling instances in response to detecting a target task in the first state in the target storage space.

[0081] The second storage module 603 is used to store the target task in the target storage structure corresponding to the target scheduling instance when the target scheduling instance successfully preempts the target task in at least two scheduling instances. After the target task is successfully preempted, the target task is in a second state, which indicates that the target task has been held by the target scheduling instance.

[0082] The scheduling module 604 is used to retrieve the target task from the target storage structure through the target scheduling instance and trigger the corresponding task executor to execute the target task when the execution time of the target task arrives.

[0083] In some embodiments, the task preemption module 602 is used to perform: The status of tasks in the target storage space is detected using at least two scheduling instances; When a target task in the first state is detected, the lock access for the target task in the target storage space is preempted; By successfully preempting the lock, the target scheduling instance sets the target task's state to the second state, thus successfully preempting the target task.

[0084] In some embodiments, the scheduling module 604 is specifically used to perform: By using the target scheduling instance, when the execution time of the target task arrives, the description information of the functions implemented by each task executor is obtained; Based on the description information of the functions implemented by each task executor, the task executor corresponding to the target task is determined from among the task executors. The task executor corresponding to the target task is scheduled to execute the target task.

[0085] In some embodiments, the target storage structure includes a time wheel, which includes a time wheel pointer and multiple time wheel nodes. Each time wheel node is used to store tasks executed at the same time. The second storage module 603 is specifically used to execute: Based on the execution time of the target task, the target task is stored in the time wheel corresponding to the target scheduling instance. The target time wheel node in the time wheel is used to indicate the execution time of the target task.

[0086] Scheduling module 604 is specifically used for execution: Through the target scheduling instance, when the time wheel pointer executes the target time wheel node, the task in the target time wheel node is retrieved and the task executor corresponding to the task in the target time wheel node is scheduled to execute the task in the target time wheel node.

[0087] In some embodiments, the second storage module 603 is further configured to perform: Based on the execution time of the target task, the target task is re-stored in the time wheel corresponding to the target scheduling instance.

[0088] In some embodiments, the above apparatus further includes: an acquisition module, which is configured to perform: The system receives the registration information of the task executor through the corresponding registration center. The registration information includes the address information and protocol information of the task executor. The protocol information is used to indicate the service communication protocol of the task executor. Address and protocol information are obtained and stored from the registry center through at least two scheduling instances.

[0089] Scheduling module 604 is specifically used for execution: Through the target scheduling instance, when the execution time of the target task arrives, the target task is scheduled to execute the target task according to the service communication protocol indicated by the protocol information of the target task's corresponding task executor and based on the address information of the target task's corresponding task executor.

[0090] In some embodiments, the registry center is also used to receive load information from the task executor, and the scheduling module 604 is specifically used to execute: By using the target scheduling instance, when the execution time of the target task arrives, the load information of the task executor corresponding to the target task is obtained from the registry center; Based on the load information, the task executor of the target task is determined from the task executor corresponding to the target task; According to the service communication protocol indicated by the protocol information of the target task executor, and based on the address information of the target task executor, the target task executor is invoked to execute the target task.

[0091] In some embodiments, the above-described apparatus further includes an update module, which is configured to perform: Receive heartbeat information periodically sent by at least two scheduling instances for different first tasks, wherein the first task is the task held by each of the at least two scheduling instances, and the first task includes the target task; Update the heartbeat time of the first task in the target storage space based on the heartbeat information; If the difference between the heartbeat time and the current time exceeds a preset threshold, the state of the first task corresponding to the heartbeat time will be changed from the second state to the first state.

[0092] In practice, each of the above modules can be implemented as an independent entity or can be combined arbitrarily to be implemented as the same or several entities. For the specific implementation methods and corresponding beneficial effects of each of the above modules, please refer to the previous method embodiments, which will not be repeated here.

[0093] Accordingly, embodiments of this disclosure also provide an electronic device, such as... Figure 7 As shown, Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. The electronic device 700 includes a processor 701 with one or more processing cores, a memory 702 with one or more computer-readable storage media, and a computer program stored on the memory 702 and executable on the processor. The processor 701 and the memory 702 are electrically connected. Those skilled in the art will understand that the electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0094] The processor 701 is the control center of the electronic device 700. It connects various parts of the electronic device 700 via various interfaces and lines. By running or loading software programs and / or units stored in the memory 702, and by calling data stored in the memory 702, it executes various functions and processes data of the electronic device 700, thereby providing overall monitoring of the electronic device 700. The processor 701 can be a central processing unit (CPU), a graphics processing unit (GPU), a network processor (NP), etc., and can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this disclosure.

[0095] In this embodiment of the disclosure, the processor 701 in the electronic device 700 loads the instructions corresponding to the processes of one or more application programs into the memory 702 according to the following steps, and the processor 701 runs the application programs stored in the memory 702 to realize various functions, such as: Obtain the target task and store it in the target storage space. Set the status of the target task to the first state, where the first state indicates that the target task is not held. In response to the detection of a target task in the first state in the target storage space, the target task is preempted by at least two scheduling instances; If the target scheduling instance successfully preempts the target task in at least two scheduling instances, the target task is stored in the target storage structure corresponding to the target scheduling instance. After the target task is successfully preempted, the target task is in a second state, which indicates that the target task has been held by the target scheduling instance. When the execution time of the target task arrives, the target task is retrieved from the target storage structure through the target scheduling instance and the corresponding task executor is triggered to execute the target task.

[0096] The specific implementation of each of the above operations and their corresponding beneficial effects can be found in the previous embodiments, and will not be repeated here.

[0097] Optional, such as Figure 7 As shown, the electronic device 700 also includes: a touch display screen 703, a radio frequency circuit 704, an audio circuit 705, an input unit 706, and a power supply 707. The processor 701 is electrically connected to the touch display screen 703, the radio frequency circuit 704, the audio circuit 705, the input unit 706, and the power supply 707. Those skilled in the art will understand that... Figure 7 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0098] The touch display screen 703 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 703 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the electronic device. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), an organic light-emitting diode (OLED), or other similar technology. The touch panel can be used to collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program according to the operation commands. Optionally, the touch panel may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 701. It can also receive and execute commands from the processor 701. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor 701 to determine the type of touch event. Subsequently, the processor 701 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and the display panel can be integrated into the touch display screen 703 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 703 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 703 can also be used as part of the input unit 706 to achieve input functions.

[0099] The radio frequency circuit 704 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other electronic devices, and to transmit and receive signals with network devices or other electronic devices.

[0100] Audio circuitry 705 can be used to provide an audio interface between a user and an electronic device via a speaker and a microphone. Audio circuitry 705 converts received audio data into electrical signals, transmits them to the speaker, and the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuitry 705, converted back into audio data, and then processed by processor 701 before being transmitted via radio frequency circuitry 704 to, for example, another electronic device, or output to memory 702 for further processing. Audio circuitry 705 may also include an earphone jack to facilitate communication between peripheral headphones and electronic devices.

[0101] The input unit 706 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.

[0102] Power supply 707 is used to supply power to various components of electronic device 700. Optionally, power supply 707 can be logically connected to processor 701 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 707 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0103] although Figure 7 As not shown in the diagram, the electronic device 700 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.

[0104] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0105] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0106] Therefore, embodiments of this disclosure provide a computer-readable storage medium storing a plurality of computer programs, which can be loaded by a processor to execute any of the task execution methods provided in embodiments of this disclosure. The computer program can perform the steps of the following task execution method: Obtain the target task and store it in the target storage space. Set the status of the target task to the first state, where the first state indicates that the target task is not held. In response to the detection of a target task in the first state in the target storage space, the target task is preempted by at least two scheduling instances; If the target scheduling instance successfully preempts the target task in at least two scheduling instances, the target task is stored in the target storage structure corresponding to the target scheduling instance. After the target task is successfully preempted, the target task is in a second state, which indicates that the target task has been held by the target scheduling instance. When the execution time of the target task arrives, the target task is retrieved from the target storage structure through the target scheduling instance and the corresponding task executor is triggered to execute the target task.

[0107] The specific implementation of each of the above operations and their corresponding beneficial effects can be found in the previous embodiments, and will not be repeated here.

[0108] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0109] Since the computer program stored in the computer-readable storage medium can execute any of the task execution methods provided in the embodiments of this disclosure, the beneficial effects that any of the task execution methods provided in the embodiments of this disclosure can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.

[0110] According to one aspect of this disclosure, a computer program product or computer program is also provided, comprising computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the methods provided in the various optional implementations of the above embodiments.

[0111] In the above embodiments of the task execution device, computer-readable storage medium, electronic device, and computer program product, the descriptions of each embodiment have different focuses. Parts not described in detail in a particular embodiment can be referred to in the relevant descriptions of other embodiments. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes and beneficial effects of the task execution device, computer-readable storage medium, computer program product, electronic device, and their corresponding units described above can be referred to the description of the task execution method in the above embodiments, and will not be repeated here.

[0112] The foregoing has provided a detailed description of a task execution method, apparatus, electronic device, computer-readable storage medium, and computer program product provided by the embodiments of this disclosure. Specific examples have been used to illustrate the principles and implementation methods of this disclosure. The descriptions of the embodiments above are only for the purpose of helping to understand the methods and core ideas of this disclosure. At the same time, those skilled in the art will recognize that there will be changes in the specific implementation methods and application scope based on the ideas of this disclosure. Therefore, the content of this specification should not be construed as a limitation of this disclosure.

Claims

1. A task execution method, characterized in that, Applied to a system comprising at least two scheduling instances, the method includes: Acquire the target task and store it in the target storage space, and set the status of the target task to a first state, wherein the first state indicates that the target task is not held; In response to detecting a target task in the first state in the target storage space, the target task is preempted by the at least two scheduling instances; If the target scheduling instance among the at least two scheduling instances successfully preempts the target task, the target task is stored in the target storage structure corresponding to the target scheduling instance. After the target task is successfully preempted, the target task is in a second state, which indicates that the target task has been held by the target scheduling instance. When the execution time of the target task arrives, the target task is retrieved from the target storage structure through the target scheduling instance and the corresponding task executor is triggered to execute the target task.

2. The method according to claim 1, characterized in that, The step of preempting the target task by the at least two scheduling instances in response to detecting a target task in the first state in the target storage space includes: The status of tasks in the target storage space is detected using the at least two scheduling instances; When a target task in the first state is detected, the lock access for the target task in the target storage space is preempted; In response to the target scheduling instance successfully preempting the lock, the state of the target task is set to the second state, so that the target scheduling instance successfully preempts the target task.

3. The method according to claim 1, characterized in that, When the execution time of the target task arrives, retrieving the target task from the target storage structure through the target scheduling instance and triggering the corresponding task executor to execute the target task includes: Using the target scheduling instance, when the execution time of the target task arrives, the description information of the functions implemented by each task executor is obtained; Based on the description information of the functions implemented by each of the task executors, the task executor corresponding to the target task is determined from among the task executors; The task executor corresponding to the target task is scheduled to execute the target task.

4. The method according to claim 1, characterized in that, The target storage structure includes a time wheel, which includes a time wheel pointer and multiple time wheel nodes. Each time wheel node is used to store tasks executed at the same time. Storing the target task into the target storage structure corresponding to the target scheduling instance includes: According to the execution time of the target task, the target task is stored in the time wheel corresponding to the target scheduling instance, and the target time wheel node of the target task in the time wheel is used to indicate the execution time of the target task; When the execution time of the target task arrives, retrieving the target task from the target storage structure through the target scheduling instance and triggering the corresponding task executor to execute the target task includes: Through the target scheduling instance, when the time wheel pointer executes the target time wheel node, the task in the target time wheel node is retrieved and the task executor corresponding to the task in the target time wheel node is scheduled to execute the task in the target time wheel node.

5. The method according to claim 4, characterized in that, The target task is a periodically executed task, and the method further includes: Based on the execution time of the target task, the target task is re-stored in the time wheel corresponding to the target scheduling instance.

6. The method according to claim 1, characterized in that, The method further includes: The system receives registration information of the task executor through its corresponding registration center. The registration information includes the address information and protocol information of the task executor. The protocol information is used to indicate the service communication protocol of the task executor. The address information and the protocol information are obtained and stored from the registration center through at least two scheduling instances; When the execution time of the target task arrives, retrieving the target task from the target storage structure through the target scheduling instance and triggering the corresponding task executor to execute the target task includes: Through the target scheduling instance, when the execution time of the target task arrives, the target task is scheduled to be executed by the task executor corresponding to the target task based on the address information of the task executor corresponding to the target task, according to the service communication protocol indicated by the protocol information of the task executor corresponding to the target task.

7. The method according to claim 6, characterized in that, The registration center is also used to receive the load information of the task executor. The step of scheduling the task executor corresponding to the target task to execute the target task based on the address information of the task executor corresponding to the target task, according to the service communication protocol indicated by the protocol information of the task executor corresponding to the target task, through the target scheduling instance, when the execution time of the target task arrives, includes: Through the target scheduling instance, when the execution time of the target task arrives, the load information of the task executor corresponding to the target task is obtained from the registry center; Based on the load information, the target task executor is determined from the task executor corresponding to the target task; According to the service communication protocol indicated by the protocol information of the target task executor, and based on the address information of the target task executor, the target task executor is invoked to execute the target task.

8. A task execution device, characterized in that, Applied to a system comprising at least two scheduling instances, the apparatus includes: The first storage module is used to acquire the target task and store it in the target storage space, and set the state of the target task to a first state, wherein the first state indicates that the target task is not held; A task preemption module is used to preempt the target task by means of the at least two scheduling instances in response to detecting a target task in the first state in the target storage space. The second storage module is used to store the target task in the target storage structure corresponding to the target scheduling instance when the target scheduling instance in the at least two scheduling instances successfully preempts the target task. The target task is set to a second state after the target task is successfully preempted, and the second state indicates that the target task has been held by the target scheduling instance. The scheduling module is used to retrieve the target task from the target storage structure through the target scheduling instance and trigger the corresponding task executor to execute the target task when the execution time of the target task arrives.

9. An electronic device, characterized in that, The device includes a processor and a memory, the memory storing multiple instructions; the processor loads instructions from the memory to perform the steps of the task execution method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of instructions adapted for loading by a processor to perform the steps of the task execution method as described in any one of claims 1 to 7.