Task scheduling method and device
By using a hierarchical and phased directed graph detection method, the change type and acyclic constraint are first matched. If no match is found, the system checks for cycles along the task scheduling direction. This solves the problem of long detection time in existing technologies and improves the accuracy and efficiency of task scheduling.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-11
- Publication Date
- 2026-03-17
AI Technical Summary
Existing technologies for detecting whether a directed acyclic graph has cycles after changes during task scheduling are time-consuming and cannot quickly determine this, leading to reduced task scheduling accuracy.
A hierarchical and phased directed graph detection method is adopted. First, the change type is matched based on the task change information and the preset acyclic constraint. If a match is found, it is determined to be a directed acyclic graph. Otherwise, the graph is checked for cycles along the task scheduling direction or the opposite direction.
This significantly reduces the time consumption of directed graph detection, improves detection efficiency, ensures the accuracy of task scheduling, and avoids the problem of inaccurate detection results caused by inaccurate factor graph extraction.
Smart Images

Figure CN116126484B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of task scheduling technology, and in particular to a task scheduling method and apparatus. Background Technology
[0002] Currently, with the continuous promotion of internet business services, the surge in the amount of business data generated by these services, and the increasingly complex dependencies between multiple data processing tasks involved in a particular internet business service, the task scheduling process is becoming increasingly complex. Furthermore, the task scheduling process requires that upstream tasks be completed before downstream tasks can be executed. Therefore, in order to improve the accuracy of task scheduling, it is necessary to first construct a directed acyclic graph containing multiple task nodes and their dependencies, and then perform task scheduling based on the directed acyclic graph.
[0003] However, due to constantly evolving business requirements, it is necessary to change the task nodes or dependencies in the existing directed acyclic graph. But once the directed acyclic graph is changed, it is necessary to re-detect whether the changed directed graph has a cycle, that is, to detect whether the changed directed graph is still a directed acyclic graph. Existing directed graph detection methods have the problems of large number of nodes to be detected and long time consumption, and cannot quickly determine whether the changed directed graph used for task scheduling has a cycle. Summary of the Invention
[0004] The purpose of this application is to provide a task scheduling method and apparatus. By using a hierarchical and phased directed graph detection method, the detection time of directed graphs can be greatly reduced and the detection efficiency of directed graphs can be improved. This enables the rapid determination of whether the target directed graph has a cycle, ensuring that the target directed graph used in the task scheduling process is a directed acyclic graph, thereby improving the accuracy of task scheduling.
[0005] To achieve the above technical solution, the embodiments of this application are implemented as follows:
[0006] In a first aspect, embodiments of this application provide a task scheduling method, the method comprising:
[0007] Obtain the target directed graph to be detected; the target directed graph is obtained by modifying the initial directed graph based on task change information, and the initial directed graph is a directed acyclic graph;
[0008] Based on the task change information and the preset acyclic constraint, the change type of the target directed graph is matched to obtain the first detection result of the target directed graph; the first detection result includes a detection result characterizing whether the change type matches the preset acyclic constraint.
[0009] If the first detection result does not match, then based on the task change information and the specified detection direction corresponding to the preset cycle detection method, the task nodes to be detected in the target directed graph are detected to obtain the second detection result of the target directed graph; the specified detection direction includes the task scheduling direction or the opposite direction of the task scheduling direction, the task nodes to be detected include associated task nodes that have a dependency relationship with the target task node in the specified detection direction starting from the target task node, the target task node is a task node related to the task change information, and the second detection result includes the detection result representing that the target directed graph is a directed acyclic graph or a directed cyclic graph;
[0010] If the second detection result indicates that the target directed graph is a directed acyclic graph, then task scheduling is performed on multiple task nodes in the target directed graph based on the target directed graph.
[0011] Secondly, an embodiment of this application provides a task scheduling device, the device comprising:
[0012] The directed graph acquisition module is configured to acquire the target directed graph to be detected; the target directed graph is obtained by modifying the initial directed graph based on task change information, and the initial directed graph is a directed acyclic graph;
[0013] The first detection module is configured to match the change type of the target directed graph based on the task change information and the preset acyclic constraint condition to obtain a first detection result of the target directed graph; the first detection result includes a detection result characterizing whether the change type matches the preset acyclic constraint condition;
[0014] The second detection module is configured to, if the first detection result does not match, detect the task nodes to be detected in the target directed graph based on the task change information and the specified detection direction corresponding to the preset cycle detection method, to obtain a second detection result of the target directed graph; the specified detection direction includes the task scheduling direction or the opposite direction of the task scheduling direction, the task nodes to be detected include associated task nodes that have a dependency relationship with the target task node in the specified detection direction starting from the target task node, the target task node is a task node related to the task change information, and the second detection result includes a detection result indicating that the target directed graph is a directed acyclic graph or a directed cyclic graph;
[0015] The task scheduling module is configured to perform task scheduling on multiple task nodes in the target directed graph based on the target directed graph if the second detection result indicates that the target directed graph is a directed acyclic graph.
[0016] Thirdly, this application provides a task scheduling device, the device comprising:
[0017] A processor; and a memory arranged to store computer-executable instructions configured to be executed by the processor, the executable instructions including steps for performing the method as described in the first aspect.
[0018] Fourthly, embodiments of this application provide a storage medium for storing computer-executable instructions that cause a computer to perform the steps described in the first aspect.
[0019] As can be seen in this embodiment, after obtaining the target directed graph to be detected, the change type of the target directed graph is first matched based on task change information and preset acyclic constraints to obtain a first detection result; then, based on the first detection result, it is decided whether to continue detecting some task nodes in the target directed graph. That is, if the first detection result indicates that the change type matches the preset acyclic constraints, the target directed graph can be directly determined to be a directed acyclic graph; if the first detection result indicates that the change type does not match the preset acyclic constraints, the task nodes to be detected in the target directed graph are then detected based on task change information and preset acyclic detection methods to obtain a second detection result indicating whether the target directed graph is a directed acyclic graph. Since in the directed graph detection process, the change type of the target directed graph is first identified as meeting the preset acyclic constraints (i.e., the first detection stage, a rapid detection stage that matches the change type with the acyclic constraints), if the change type meets the preset acyclic constraints, the target directed graph can be directly determined to be a directed acyclic graph. The first detection stage involves detecting whether a cycle exists in the target directed graph. If the change type does not meet the preset acyclic constraint, a second detection stage is performed on some task nodes in the target directed graph based on the preset cycle detection method to identify whether the target directed graph has a cycle (i.e., the second detection stage, which detects whether there is a cycle from the target task node to a specified detection direction). On the one hand, if the change type is determined to match the preset acyclic constraint in the first detection stage, there is no need to continue to execute the second detection stage. In this way, the hierarchical and phased directed graph detection method can greatly reduce the detection time of the directed graph and improve the detection efficiency. On the other hand, even if the second detection stage needs to be performed on the target directed graph, it is only necessary to detect whether there is a cycle starting from the target task node along the task scheduling direction or the opposite direction of the task scheduling direction. It is not necessary to traverse all task nodes. In this way, even if the change type does not meet the preset acyclic constraint, the detection efficiency of the directed graph can still be improved, thereby ensuring that the target directed graph used in the task scheduling process is a directed acyclic graph, and thus improving the accuracy of task scheduling. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in one or more of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 A flowchart illustrating the task scheduling method provided in this application embodiment;
[0022] Figure 2a A schematic diagram of the target directed graph in the task scheduling method provided in the embodiments of this application;
[0023] Figure 2b Another schematic diagram of the target directed graph in the task scheduling method provided in the embodiments of this application;
[0024] Figure 2c This is another schematic diagram of the target directed graph in the task scheduling method provided in the embodiments of this application;
[0025] Figure 3 This is a schematic diagram illustrating the first implementation principle of the task scheduling method provided in the embodiments of this application;
[0026] Figure 4 A flowchart illustrating the construction process of the target directed graph in the task scheduling method provided in this application embodiment;
[0027] Figure 5 This is a schematic diagram of the module composition of the task scheduling device provided in the embodiments of this application;
[0028] Figure 6 This is a schematic diagram of the structure of the task scheduling device provided in the embodiments of this application. Detailed Implementation
[0029] To enable those skilled in the art to better understand the technical solutions in one or more of this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of one or more of this application, and not all embodiments. Based on the embodiments of one or more of this application, all other embodiments obtained by those skilled in the art without creative effort should fall within the protection scope of this application.
[0030] It should be noted that, unless otherwise specified, one or more embodiments and features described in this application can be combined with each other. The embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0031] Considering that if the target directed graph is a directed cyclic graph, during task scheduling based on this graph, a situation might arise where, after a target task node completes execution, it returns to the original target task node after executing multiple downstream task nodes, leading to an infinite loop and preventing further task scheduling. Therefore, before scheduling tasks based on the target directed graph, it's necessary to check if the target directed graph is a directed acyclic graph (DAG). Task scheduling will only proceed if the target directed graph is indeed DAG. Specifically, the process of checking if the target directed graph is DAG involves directly calculating the in-degree of all task nodes in the target directed graph, deleting task nodes with an in-degree of zero, updating the in-degree of the remaining task nodes, and continuing to delete task nodes with an in-degree of zero. The final result is then checked to see if there are any nodes with a non-zero in-degree. If so, it indicates that the target directed graph has a cycle. Therefore, for directed acyclic graphs... In contrast, if this detection method is used, it is necessary to traverse all task nodes to determine whether the target directed graph is a directed acyclic graph, resulting in low detection efficiency. To address this issue, this technical solution first identifies whether the change type of the target directed graph meets the preset acyclic constraint (i.e., the first detection stage, a rapid detection stage that matches the change type with the acyclic constraint). If the change type meets the preset acyclic constraint, the target directed graph can be directly determined to be a directed acyclic graph. If the change type does not meet the preset acyclic constraint, then a preset cycle detection method is used to detect some task nodes in the target directed graph to identify whether the target directed graph has a cycle (i.e., the second detection stage, a detection stage that checks for cycles from the target task node towards a specified detection direction). If the change type is determined to match the preset acyclic constraint in the first detection stage, there is no need to continue with the second detection stage. This hierarchical and phased directed graph detection method can significantly reduce the detection time of directed graphs and improve their detection efficiency.Furthermore, considering that extracting sub-change directed graphs related to task change information from the target directed graph based on task change information first not only increases the subgraph extraction steps but also requires high accuracy, inaccurate extraction will result in broken edges and inaccurate detection results, this technical solution still starts from the target task node and, based on the opposite or opposite direction of the task scheduling direction, detects some associated task nodes of the target task node in the target directed graph, gradually identifying whether there are dependency edges returning to the target task node. If a dependency edge returning to the target task node is detected, the solution will proceed accordingly. If the target directed graph has a dependent edge, it indicates that the target directed graph is a directed cyclic graph. Otherwise, if an upstream end node (i.e., an upstream task node with an in-degree of zero) or a downstream end node (i.e., a downstream task node with an out-degree of zero) is detected, the target directed graph is a directed acyclic graph. In this way, even if a second detection stage is required for the target directed graph, it is only necessary to check for cycles starting from the target task node along the task scheduling direction or the opposite direction of the task scheduling direction. It is not necessary to traverse all task nodes. This can avoid the problem of inaccurate detection results due to inaccurate subgraph extraction, and can also improve the detection efficiency of directed graphs when the change type does not meet the preset acyclic constraint.
[0032] Specifically, Figure 1 This is a first flowchart illustrating a task scheduling method provided in one or more embodiments of this application. Figure 1 The method described herein can be executed by an electronic device equipped with a task scheduling mechanism, which can be a terminal device or a designated server. It should be noted that the task scheduling method provided in this application can be applied to any application scenario based on a directed acyclic graph (DAG), i.e., any application scenario that requires sequential execution of data processing tasks corresponding to each task node based on the DAG, and then, based on the business data processing results of the upstream task nodes, obtaining the business data processing results of the downstream task nodes, until the downstream endpoint (i.e., the downstream task node with an out-degree of zero) completes its execution, thus obtaining the final required business data processing result; for example, in the application scenario of online shopping services, based on the calculation results of the upstream task nodes, the final calculation... This includes calculating the inventory of goods for sale; for example, in the application scenario of fund application services, based on the calculation results of upstream task nodes, the final calculation is to determine the geographical distribution of users who have not yet repaid their loans; and in the application scenario of logistics services, based on the calculation results of upstream task nodes, the final calculation is to determine the distribution of delivery locations of packages awaiting shipment, etc. Since any application scenario based on directed acyclic graphs (DAGs) requires ensuring that the target directed graph is a DAG, after modifying the initial directed graph to obtain the target directed graph, the following task scheduling method can be used to determine whether the target directed graph is a DAG, such as... Figure 1 As shown, the method includes at least the following steps:
[0033] S102, Obtain the directed graph of the target to be detected; wherein, the directed graph of the target is obtained by modifying the initial directed graph based on the task change information, and the initial directed graph is a directed acyclic graph;
[0034] Specifically, the initial directed graph can be the original directed acyclic graph constructed for a preset business service. Correspondingly, the target directed graph is the modified directed graph obtained by making the first change to the original directed acyclic graph. Alternatively, the initial directed graph can be a directed acyclic graph obtained by making at least one change to the original directed acyclic graph. Correspondingly, the target directed graph is the modified directed graph obtained by making multiple changes to the original directed acyclic graph. The target directed graph includes multiple task nodes and multiple connection edges representing the dependencies between task nodes. Since the task scheduling process based on the target directed graph needs to ensure that the target directed graph is a directed acyclic graph, after obtaining the target directed graph, steps S104 to S108 need to be triggered to determine whether the target directed graph is a directed acyclic graph.
[0035] S104, Based on the above task change information and preset acyclic constraints, the change type of the target directed graph is matched to obtain the first detection result of the target directed graph; wherein, the first detection result includes a detection result that characterizes whether the change type of the target directed graph matches the preset acyclic constraints;
[0036] Specifically, the aforementioned task change information may include at least one of the following: deleting at least one task node, deleting at least one dependent edge, adding at least one task node, adding at least one dependent edge, or adjusting the position of at least one task node. Since adjusting the position of a task node may result in the deletion or addition of dependent edges, adjusting the position of a task node can be converted into a combination of multiple change types. Therefore, a single change type may include the deletion of a task node, the deletion of a dependent edge, the addition of a task node, or the addition of a dependent edge, etc. In this application's embodiments, a single change type is used for detailed explanation. For cases where the task change information corresponds to multiple change types (i.e., a change to a directed graph involves multiple change types), the target directed graph can be detected separately for each change type, and the final detection result can be determined by combining the detection results corresponding to each change type. This will not be elaborated further here.
[0037] Specifically, the aforementioned preset acyclic constraints can include at least one of the following sub-constraints: deleting at least one dependent edge, deleting at least one task node, adding at least one task node with an out-degree of zero, or adding at least one task node with an in-degree of zero. Specifically, neither deleting a dependent edge nor deleting a task node will cause the directed acyclic graph to become a directed cyclic graph; that is, the directed graph remains a directed acyclic graph after the change. The newly added task node with an out-degree of zero is equivalent to adding a downstream terminal node. Therefore, adding at least one task node with an out-degree of zero... A zero degree value will not cause a directed acyclic graph to become a directed cyclic graph. In addition, the in-degree value of the newly added task node is zero, which means that an upstream end node has been added. Therefore, adding at least one task node with an in-degree value of zero will not cause a directed acyclic graph to become a directed cyclic graph. Specifically, if the change type of the target directed graph matches any sub-constraint, then the change type of the target directed graph is determined to match the preset acyclic constraint. If the change type of the target directed graph does not match any sub-constraint, then the change type of the target directed graph does not match the preset acyclic constraint.
[0038] It should be noted that, in specific implementation, in order to ensure the stability of business scheduling, and considering the actual business requirements and the definition of responsibilities for changes, generally only downstream task nodes are allowed to actively initiate dependencies on upstream task nodes, while upstream task nodes are not allowed to actively initiate changes that affect downstream task nodes. Therefore, in reality, only some change types are allowed. For example, the actual change type may only include the case where the out-degree value of the newly added task node is zero, but not the case where the in-degree value of the newly added task node is zero. Therefore, the preset acyclic constraint conditions and optional change types can be set according to the actual situation and will not limit the scope of protection of this application.
[0039] S106, if the change type of the target directed graph represented by the first detection result matches the preset acyclic constraint condition, then the target directed graph is determined to be a directed acyclic graph.
[0040] Specifically, if the change type of the target directed graph matches the preset acyclic constraint, it means that the above task change information will not cause the directed acyclic graph to become a directed cyclic graph. Therefore, the target directed graph is still a directed acyclic graph, and the second detection stage of the target directed graph can be omitted.
[0041] S108, if the change type of the target directed graph represented by the first detection result does not match the preset acyclic constraint, then based on the task change information and the specified detection direction corresponding to the preset acyclic detection method, the task node to be detected in the target directed graph is detected to obtain the second detection result of the target directed graph.
[0042] The specified detection direction includes the task scheduling direction or the opposite direction of the task scheduling direction. The task node to be detected includes associated task nodes that have a dependency relationship with the target task node starting from the target task node in the specified detection direction. The target task node is a task node in the target directed graph that is related to task change information. The second detection result includes a detection result that characterizes the target directed graph as a directed acyclic graph or a directed cyclic graph. In specific implementation, the target task node can be the task node that initiates the change request, the upstream task node directly connected by the newly added dependency edge, or the downstream task node directly connected by the newly added dependency edge. The newly added dependency edge is a directed edge added based on task change information. In the case where only downstream task nodes are allowed to actively initiate dependencies on upstream task nodes, considering that a downstream task node may initiate dependencies on multiple upstream task nodes, the newly added dependency edge includes multiple dependency edges from multiple upstream task nodes to the downstream task node. Preferably, the target task node is the downstream task node of the newly added dependency edge. Thus, in the case of adding multiple dependency edges, the number of target task nodes is one, that is, the multiple dependency edges correspond to the same target task node.
[0043] Specifically, if the change type of the target directed graph does not match the preset acyclic constraint, it indicates that the above task change information may cause the directed acyclic graph to become a directed cyclic graph. Therefore, it is necessary to enter the second detection stage to continue detecting whether there is a cycle in the target directed graph. Since if the above task change information causes at least one cycle in the target directed graph, there must be node connection edges that start from the target task node and return to the target task node. Therefore, based on the dependency relationship between the target task node and other task nodes in the target directed graph, it is detected whether there is a cycle starting from the target task node, passing through multiple associated task nodes and returning to the target task node in a certain specified detection direction. If any cycle exists, the target directed graph is determined to be a directed cyclic graph; otherwise, the target directed graph is determined to be a directed acyclic graph.
[0044] In practical implementation, considering that during node detection based on a preset cycle detection method, one can start from the target task node and detect the upstream task nodes along the opposite direction of the task scheduling direction to identify whether a loop returns to the target task node. Correspondingly, the preset cycle detection method is the first sub-detection method based on detecting whether a cycle exists in the opposite direction of the task scheduling direction. The specified detection direction is the opposite direction of the task scheduling direction, i.e., the direction from the downstream task node to the upstream task node. In this case, the specified detection direction is opposite to the direction of the directed edge between any two associated task nodes. Alternatively, one can start from the target task node and detect the downstream task nodes along the task scheduling direction to identify whether a loop returns to the target task node. Correspondingly, the preset detection method is the second sub-detection method based on detecting whether a cycle exists in the task scheduling direction. The detection method specifies the task scheduling direction as described above, which is the direction from the upstream task node to the downstream task node. In this case, the specified detection direction is the same as the direction of the directed edge between any two associated task nodes. Regardless of whether the first or second sub-detection method is used, for the case where the target directed graph is a directed acyclic graph, the dependencies between the multiple associated task nodes to be detected and the target task node are the same. For example, for the first sub-detection method, the dependency between the associated task nodes to be detected and the target task node is that the target task node depends on the associated task node (i.e., the associated task node is the upstream task node of the target task node), while for the second sub-detection method, the dependency between the associated task nodes to be detected and the target task node is that the associated task node depends on the target task node (i.e., the associated task node is the downstream task node of the target task node).
[0045] Specifically, such as Figure 2a As shown, taking the addition of a dependency edge from task node P9 to task node P2 as an example, the target task node can be task node P2. In the first sub-detection method mentioned above, starting from the target task node P2, it will pass through multiple upstream task nodes of the target task node (including upstream task node P9 with direct dependency relationship and upstream task node with indirect dependency relationship, i.e., P2→P9→P7→P5→P2, or P2→P9→P8→P6→P2). It can be seen that the indirect upstream task node P5 or P6 returns to the target task node P2 (at this time, the indirect upstream task node P5 or P6 is also the direct downstream node of the target task node P2). Therefore, the target directed graph is determined to be a directed cyclic graph.
[0046] Regarding the second sub-detection method mentioned above, starting from the target task node P2, it will pass through multiple downstream task nodes of the target task node (including downstream task nodes P5 and P6 with direct dependencies and downstream task nodes with indirect dependencies, i.e., P2→P5→P7→P9→P2, or P2→P6→P8→P9→P2). It can be seen that the indirect downstream task node P9 returns to the target task node P2 (at this time, the indirect downstream task node P9 is also the direct upstream node of the target task node P2). Therefore, the target directed graph is determined to be a directed cyclic graph.
[0047] Specifically, such as Figure 2b As shown, taking the addition of a dependency edge from task node P7 to task node P12 as an example, the target task node can be task node P12. For the first sub-detection method described above, starting from the target task node P12, it will pass through multiple upstream task nodes (including upstream task nodes P7, P9, and P10 with direct dependencies and upstream task nodes with indirect dependencies, i.e., P12→P7→P5→P2→P1, P12→P7→P19→P20→P21→P1, P12→P9→P7→P5→P2→P1, P12→P9→P8→P6→P2→P1, and P12→P10→P8→P6→P2→P1). It can be seen that the final upstream end node is detected, and it does not return to the target task node P12 through the newly added dependency edge P7→P12. Therefore, the target directed graph is determined to be a directed acyclic graph.
[0048] Regarding the second sub-detection method mentioned above, starting from the target task node P12, it will pass through multiple downstream task nodes of the target task node (including downstream task nodes P15 and P13 with direct dependencies and downstream task node P16 with indirect dependencies, i.e., P12→P15→P16 and P12→P13). It can be seen that the downstream end node is finally detected, and it does not return to the target task node P12 through the newly added dependency edge P7→P12. Therefore, the target directed graph is determined to be a directed acyclic graph.
[0049] It should be noted that, Figure 2a and Figure 2b The middle arrow points to the direction of the dependent edge between two task nodes (i.e., the direction of the directed edge), while the arrow "→" indicates the specified detection direction, not the direction of the dependent edge between two task nodes. Specifically, when the specified detection direction is the opposite of the task scheduling direction, the direction of the arrow "→" is opposite to the direction of the dependent edge; when the specified detection direction is the task scheduling direction, the direction of the arrow "→" is the same as the direction of the dependent edge.
[0050] In practical implementation, the specified detection direction can be fixed, such as the opposite direction of the pre-agreed task scheduling direction or the task scheduling direction. To further improve the efficiency of directed graph detection, the specified detection direction can also be automatically determined based on the target structure data of the target task node (e.g., the first detection quantity from the target task node to the upstream end node and the second detection quantity from the target task node to the downstream end node). Thus, the specified detection direction selected for different target task nodes can be different. For example, for… Figure 2b For the target task node P12, the corresponding specified detection direction can be the task scheduling direction, while for the target task node P2, the corresponding specified detection direction can be the opposite direction of the task scheduling direction.
[0051] S110, if the second detection result indicates that the target directed graph is a directed acyclic graph, then task scheduling is performed on multiple task nodes in the target directed graph based on the target directed graph.
[0052] Specifically, if the second detection result indicates that the target directed graph is a directed cyclic graph, a corresponding alarm message is generated to remind the relevant personnel to adjust the target directed graph. Only when the second detection result indicates that the target directed graph is a directed acyclic graph will the step of scheduling multiple task nodes in the target directed graph be triggered, that is, the data processing tasks corresponding to each task node are executed sequentially based on the target directed graph to obtain the final required data processing result.
[0053] Additionally, it should be noted that in specific implementation, step S110 can be executed sequentially with step S108, or they can be executed separately. That is, the electronic device used for directed graph detection and the electronic device used for task scheduling can be the same electronic device or different electronic devices. In the case of using different electronic devices, the electronic device used for directed graph detection can send the second detection result to the electronic device used for task scheduling, or the electronic device used for directed graph detection can trigger the electronic device used for task scheduling to perform task scheduling based on the target directed graph if it is determined that the second detection result represents the target directed graph as a directed acyclic graph.
[0054] In this embodiment, during the directed graph detection process, the change type of the target directed graph is first identified to determine whether it meets the preset acyclic constraint condition (i.e., the first detection stage, a rapid detection stage that matches the change type with the acyclic constraint condition). If the change type meets the preset acyclic constraint condition, the target directed graph can be directly determined to be a directed acyclic graph. If the change type does not meet the preset acyclic constraint condition, then a portion of the task nodes in the target directed graph are detected based on a preset cycle detection method to identify whether the target directed graph has a cycle (i.e., the second detection stage, a detection stage that checks for cycles from the target task node towards a specified detection direction). (Stages); On the one hand, if the change type is determined to match the preset acyclic constraint in the first detection stage, there is no need to continue to the second detection stage. In this way, the hierarchical and staged directed graph detection method can greatly reduce the detection time of directed graphs and improve the detection efficiency of directed graphs. On the other hand, even if the second detection stage needs to be performed on the target directed graph, it is only necessary to check whether there is a cycle starting from the target task node along the task scheduling direction or the opposite direction of the task scheduling direction. It is not necessary to traverse all task nodes. In this way, the detection efficiency of directed graphs can also be improved even if the change type does not meet the preset acyclic constraint.
[0055] Specifically, the process for determining the first detection result, i.e., the first detection stage, involves a rapid detection process that matches the change type with the acyclic constraint. If the aforementioned preset acyclic constraint includes multiple sub-constraints for determining the acyclicity of the directed graph, then step S104, based on the aforementioned task change information and the preset acyclic constraint, matches the change type of the target directed graph to obtain the first detection result of the target directed graph. This specifically includes:
[0056] Step A1: Based on the above task change information, determine the change type from the initial directed graph to the target directed graph, and match the change type with each sub-constraint condition;
[0057] Step A2: If the above change type does not match multiple sub-constraints, then the detection result that the change type representing the target directed graph does not match the preset acyclic constraint is determined as the first detection result.
[0058] Step A3: If the above change type matches the target sub-constraint among multiple sub-constraints, then the detection result that matches the change type of the target directed graph with the preset acyclic constraint is determined as the first detection result.
[0059] Specifically, for the case where there is only one change type corresponding to the target directed graph, if the change type matches any one of the multiple sub-constraints, then the change type is determined to match the preset acyclic constraint; if the change type does not match any of the multiple sub-constraints, then the change type is determined to not match the preset acyclic constraint. For example, if the change type corresponding to the target directed graph is deleting a task node, then the change type is determined to match the preset acyclic constraint; as another example, if the change type corresponding to the target directed graph is adding a dependency edge between two task nodes, then the change type is determined to not match the preset acyclic constraint.
[0060] When there are multiple change types corresponding to the target directed graph, if the constraint matching result for each change type is a match, then the change type is determined to match the preset acyclic constraint, meaning there is no need to proceed to the second detection stage. If the constraint matching condition for any change type is a mismatch, then the change type is determined to be a mismatch with the preset acyclic constraint, meaning it is necessary to perform associated task node detection for change types with mismatched constraint conditions. For example, if the change types corresponding to the target directed graph include deleting a task node and adding a task node with an out-degree of zero, then the change type is determined to match the preset acyclic constraint. Alternatively, if the change types corresponding to the target directed graph include deleting a task node and adding a dependency edge between two task nodes, then the change type is determined to be a mismatch with the preset acyclic constraint, and associated task node detection is required for the newly added dependency edge. That is, if the target task node is the downstream task node of the newly added dependency edge, the associated task nodes of the target task node in the specified detection direction are detected to obtain the second detection result.
[0061] In the embodiments provided in this application, the change type of the target directed graph is first matched with multiple sub-constraints in the preset acyclic constraint conditions. If the change type matches at least one sub-constraint in the preset acyclic constraint conditions, the target directed graph can be directly determined to be a directed acyclic graph. Only when the change type does not match any of the sub-constraints in the preset acyclic constraint conditions is the associated task nodes of the target task node detected in a specified detection direction based on the preset cycle detection method continued. Based on the node detection results, it is determined whether the target directed graph is a directed cyclic graph. In this way, for the change of the directed graph that meets the preset acyclic constraint conditions, the directed graph detection result can be quickly determined in the change type matching stage without the need for the associated task node detection step in the second detection stage, which greatly improves the efficiency of directed graph detection.
[0062] Specifically, the process of determining the second detection result, i.e., the second detection stage, involves detecting whether there is a cycle from the target task node towards a specified detection direction. In step S108 above, based on the task change information and the specified detection direction corresponding to the preset cycle detection method, the task node to be detected in the target directed graph is detected to obtain the second detection result of the target directed graph. This specifically includes:
[0063] Step B1: Based on the above task change information, determine the target task node in the target directed graph;
[0064] Specifically, for change types that do not meet the aforementioned preset acyclic constraints, the task node targeted by the change type is determined as the target task node. For example, if the change type is the addition of a dependency edge, the upstream task node (i.e., the task node located upstream on the new dependency edge) or the downstream task node (i.e., the task node located downstream on the new dependency edge) directly connected by the new dependency edge can be determined as the target task node. In this case, since the actual requirements of some services are that only downstream task nodes are allowed to actively initiate dependencies on upstream task nodes, and a certain downstream task node may initiate dependencies on multiple upstream task nodes, i.e., the new dependency edge includes multiple dependency edges from multiple upstream task nodes to the downstream task node, it is preferable to use the downstream task node as the target task node. In this way, for the case of adding multiple dependency edges, the number of target task nodes is one, i.e., the multiple dependency edges correspond to the same target task node.
[0065] For example, in the above Figure 2a In the above example, a new dependency edge is added, which is the dependency edge from task node P9 to task node P2, which can identify task node P2 as the target task node; For example, in the above... Figure 2b In the process, a new dependency edge is added, which is the dependency edge between task node P7 and task node P12. Task node P12 can be identified as the target task node.
[0066] Step B2: Based on the specified detection direction corresponding to the preset loop detection method, determine the starting detection edge of the target task node; wherein, the starting detection edge includes the first directed edge with the target task node as one end in the specified detection direction;
[0067] Specifically, the starting detection edge of the target task node can include the upstream dependency edge of the target task node, or it can include the downstream dependency edge of the target task node. When the specified detection direction is the opposite direction of the task scheduling direction, the starting detection edge of the target task node includes the upstream dependency edge of the target task node. When the specified detection direction is the task scheduling direction, the starting detection edge of the target task node includes the downstream dependency edge of the target task node.
[0068] For example, in the above Figure 2aIn the above, the target task node is task node P2. If the specified detection direction is the opposite direction of the task scheduling direction, then the starting detection edge of the target task node includes at least one of P2→P9 and P2→P1; if the specified detection direction is the task scheduling direction, then the starting detection edge of the target task node includes at least one of P2→P5, P2→P6, and P2→P4; For example, in the above... Figure 2b In the process, the target task node can be task node P12. If the specified detection direction is the opposite direction of the task scheduling direction, the starting detection edge of the target task node includes at least one of P12→P7, P12→P9, and P12→P10. If the specified detection direction is the downstream direction, the starting detection edge of the target task node includes at least one of P12→P13 and P12→P15.
[0069] In practical implementation, considering that the initial directed graph is a directed acyclic graph, the target directed graph will only become a directed cyclic graph due to the addition of dependent edges. Therefore, for the case where the specified detection direction is the opposite of the task scheduling direction, if the directed edges in the opposite direction with the target task node as one end (i.e., the upstream dependent edges directly connected to the target task node) include both newly added dependent edges and existing dependent edges, only the newly added dependent edges can be used as the starting detection edges. This can further improve the efficiency of directed graph detection. Additionally, for the case where the specified detection direction is the task scheduling direction, the starting detection edge (i.e., the upstream dependent edge directly connected to the target task node) can be used as the starting detection edge. Downstream dependent edges that are directly connected typically only include existing dependent edges. The detection method based on the task scheduling direction to check for cycles is mainly for situations where the number of nodes detected from the target task node to the downstream end node is much smaller than the number of nodes detected from the target task node to the upstream end node. In other words, the target task node is closer to the downstream end node. Thus, even if the number of initial detection edges is relatively large, the detection efficiency of the detection method based on the task scheduling direction to check for cycles is still relatively high compared to the detection method based on the reverse direction of the task scheduling direction and the initial detection edges only include newly added dependent edges.
[0070] Step B3: Taking the first associated task node on the current starting detection edge as the starting detection node, based on the target directed graph, detect the associated task nodes in the specified detection direction to obtain the task node sub-detection result; wherein, each starting detection edge corresponds to a first associated task node (i.e., the task node on the starting detection edge other than the target task node), and the first associated task node is the other end of the first directed edge mentioned above.
[0071] Specifically, when there are multiple starting detection edges for the target task node, one starting detection edge can be selected sequentially as the current starting detection edge to be detected, that is, the associated task nodes on the target detection branch corresponding to each starting detection edge can be detected sequentially; alternatively, multiple starting detection edges can be detected in parallel, with all of them serving as the current starting detection edges to be detected, that is, the associated task nodes on the target detection branches corresponding to multiple starting detection edges can be detected in parallel. Here, the target detection branch corresponding to the starting detection edge refers to the detection branch formed by the associated task nodes in the specified detection direction based on the starting detection edge.
[0072] Specifically, after determining the starting edge to be detected, the first associated task node on the starting edge is the associated task node on the starting edge that is directly connected to the target task node; for example, the above Figure 2a In the above example, for the initial detection edge P2→P9, the first associated task node is P9. If the specified detection direction is the opposite direction of the task scheduling direction, then task node P9 is used as the starting detection node, and associated task nodes P9, P7, P8, P5, P6, P19, etc., are detected to obtain the task node sub-detection results; for example, the above... Figure 2b In the process, for the initial detection edge P12→P7, the first associated task node is P7. If the specified detection direction is the opposite direction of the task scheduling direction, then task node P7 is taken as the starting detection node, and associated task nodes such as task nodes P7, P5, P19, P2, and P20 are detected to obtain the task node sub-detection results.
[0073] Furthermore, since associated task nodes in a specified detection direction may be connected to multiple dependency edges, an object detection branch may contain multiple object sub-detection branches, for example, as described above. Figure 2b In the above, for the initial detection edge P12→P7, since the dependent edges of P7 in the specified detection direction include P7→P5 and P7→P19; in addition, for multiple target sub-detection branches, the associated task nodes can be detected in parallel along the specified detection direction. If a loop is found in a target sub-detection branch, it is determined that the target detection branch has a cycle. For example, as mentioned above... Figure 2a In the process, for the initial detection edge P2→P9, there are multiple target sub-detection branches, namely P2→P9→P7→P5→P2 and P2→P9→P7→P19→P20→P21→P1. When it is determined that a cycle exists through the target sub-detection branch P2→P9→P7→P5→P2, the detection of the remaining task nodes on the target sub-detection branch is stopped, and it is directly determined that the target detection branch corresponding to the initial detection edge P2→P9 has a cycle.
[0074] Step B4: Based on the task node sub-detection results corresponding to at least one starting detection edge of the target task node, determine the second detection result of the target directed graph.
[0075] Specifically, when there are multiple initial detection edges for the target task node, the detection can be stopped if the sub-detection result of the task node corresponding to a certain initial detection edge is a cycle, and the target directed graph is directly determined to be a directed cyclic graph. Alternatively, the target detection branches corresponding to each initial detection edge can be detected, and then the target directed graph can be determined to be a directed acyclic graph based on the sub-detection results of the task nodes corresponding to all initial detection edges.
[0076] The embodiments provided in this application, in the process of detecting the task nodes to be detected in the target directed graph, firstly determine the target task node and at least one starting detection edge in the specified detection direction based on task change information; then, starting from the starting detection edge, detect the associated task nodes in the specified detection direction based on the target directed graph, and determine whether the dependent task nodes of the associated task nodes in the specified detection direction are the target task nodes, to obtain the second detection result of the target directed graph. In this way, if the dependent task node of a certain associated task node in the specified detection direction is the target task node, that is, the connection from a certain associated task node back to the target task node, the case of a cycle in the target directed graph can be quickly detected. If all the terminal task nodes corresponding to the starting detection edge in the specified detection direction are detected, the case of no cycle in the target directed graph can also be quickly determined. Therefore, it is only necessary to detect some task nodes in the specified detection direction, without traversing all task nodes in the target directed graph.
[0077] Specifically, regarding the implementation process of detecting associated task nodes of a target task node in a specified detection direction based on the target directed graph, step B3 above involves detecting associated task nodes in the specified detection direction based on the target directed graph to obtain task node sub-detection results, specifically including:
[0078] Step B31: Based on the target directed graph and the specified detection direction corresponding to the preset loop detection method, determine the current task node to be detected;
[0079] Specifically, based on the directed graph of the target, the starting detection node is taken as the first current node to be detected, and the next node to be detected is determined sequentially according to the specified detection direction; for example, in the above... Figure 2a In the example of the initial detection edge P2→P9 with the specified detection direction being the opposite of the task scheduling direction, the first current task node to be detected is P9. The next task nodes to be detected, determined sequentially according to the specified detection direction, include related task nodes such as P7, P8, P5, P6, and P19. For another example, in the aforementioned... Figure 2bIn the example of starting detection edge P12→P7 and specifying the detection direction as the opposite direction of the task scheduling direction, the first current task node to be detected is P7, and the next task nodes to be detected in sequence according to the specified detection direction include related task nodes such as P5, P19, P2, and P20.
[0080] Step B32, perform the following loop detection operation on the current task node to be detected, specifically:
[0081] (1) Determine the number of target dependency edges corresponding to the current task node to be detected; wherein, the target dependency edges include the second directed edge with the current task node to be detected as one end in the specified detection direction;
[0082] Specifically, to determine whether a directed graph contains a cycle, it is necessary to determine whether the target detection branch corresponding to the initial detection edge forms a cycle. This requires determining whether, starting from the target task node and taking the initial detection edge as the starting point, the path along the specified detection direction, after passing through multiple associated task nodes, returns to the target task node or reaches all the terminal task nodes (upstream or downstream) of the target detection branch corresponding to the initial detection edge. Therefore, it is necessary to determine whether the number of target dependency edges of the current task node to be detected in the specified detection direction is zero. Thus, it is necessary to determine the number of target dependency edges of the current task node to be detected in the specified detection direction.
[0083] Specifically, if the specified detection direction is the opposite of the task scheduling direction, the target dependency edges of the current task node to be detected include upstream dependency edges directly connected to the current task node to be detected. The number of target dependency edges is the number of upstream dependency edges pointing to the current task node to be detected, which is also the in-degree value of the current task node to be detected. That is, it is necessary to determine whether the in-degree value of the current task node to be detected is zero. If the specified detection direction is the task scheduling direction, the target dependency edges of the current task node to be detected include downstream dependency edges directly connected to the current task node to be detected. The number of target dependency edges is the number of downstream dependency edges pointing to the current task node to be detected, which is also the out-degree value of the current task node to be detected. That is, it is necessary to determine whether the in-degree value or out-degree value of the current task node to be detected is zero, and then decide whether to continue to detect the next associated task node.
[0084] For example, in the above Figure 2aIn the case where the specified detection direction is the opposite of the task scheduling direction, if the current task node to be detected is P9, then the target dependency edges include P9→P7 and P9→P8, meaning the number of target dependency edges is 2, which is equal to the in-degree value of task node P9. In the case where the specified detection direction is the task scheduling direction, if the current task node to be detected is P5, then the target dependency edges include P5→P7, meaning the number of target dependency edges is 1, which is equal to the out-degree value of task node P5. For example, in the above... Figure 2b In the case where the specified detection direction is the opposite of the task scheduling direction, if the current task node to be detected is P7, then the target dependency edges include P7→P5 and P7→P19, that is, the number of target dependency edges is 2, which is equal to the in-degree value of task node P7; in the case where the specified detection direction is the task scheduling direction, if the current task node to be detected is P13, then the number of target dependency edges is 0, that is, the number of target dependency edges is equal to the out-degree value of task node P13.
[0085] (2) If the number of target-dependent edges is zero, the detection result of the target detection branch corresponding to the starting detection edge being acyclic is determined as the task node sub-detection result corresponding to the starting detection edge.
[0086] Specifically, if the number of target dependency edges of the current task node to be detected in the specified detection direction is zero, it means that the current task node to be detected is an upstream end node or a downstream end node and will not form a cycle. Therefore, if all associated task nodes on the target detection branch corresponding to the current starting detection edge have been detected, it can be determined that the target detection branch corresponding to the starting detection edge is acyclic.
[0087] It should be noted that, considering the target detection branch corresponding to the current starting detection edge may contain multiple target sub-detection branches, if the number of target dependency edges for a certain current task node to be detected is zero, it means that the terminal task node has been reached along a certain target sub-detection branch of the target detection branch, and other target sub-detection branches may not have been detected yet. Therefore, if the number of target dependency edges is zero and all associated task nodes on multiple target sub-detection branches have been detected, the sub-detection result of the task node corresponding to the starting detection edge is determined to be acyclic in the target detection branch; otherwise, the undetected associated task nodes on other target sub-detection branches continue to be detected; for example, the above. Figure 2bIn the example, for the initial detection edge P12→P7, if the specified detection direction is the opposite direction of the task scheduling direction, the corresponding target detection branches include target sub-detection branches P7→P5→P2→P1 and P7→P19→P20→P21→P1. Therefore, when the task node P1 is reached through the target sub-detection branch P7→P5→P2→P1, although the number of target dependency edges of the task node P1 is zero, the target sub-detection branch P7→P19→P20→P21→P1 may not have finished detecting. Therefore, it is necessary to reach the task node P1 through both the target sub-detection branches P7→P5→P2→P1 and P7→P19→P20→P21→P1 before determining that the task node sub-detection result of the initial detection edge P12→P7 is acyclic.
[0088] (3) If the number of target dependency edges is not zero, then determine the next associated task node corresponding to at least one target dependency edge; wherein, the next associated task node is the other end of the second directed edge, that is, the next associated task node is an associated task node directly connected to the current task node to be detected.
[0089] Specifically, if the number of target dependency edges is not zero, continuing to detect associated task nodes in the specified detection direction may form a loop. Therefore, it is necessary to continue to determine whether the next associated task node on the target dependency edge is the target task node, that is, to determine whether the current task node to be detected has returned to the target task node. Here, the next associated task node corresponding to the target dependency edge is the associated task node directly connected to the current task node to be detected through the target dependency edge; for example, in the above... Figure 2a In the case where the specified detection direction is the opposite of the task scheduling direction, if the current task node to be detected is P9, then the target dependency edges include P9→P7 and P9→P8, and the corresponding next associated task nodes include P7 and P8; in the case where the specified detection direction is the task scheduling direction, if the current task node to be detected is P5, then the target dependency edge includes P5→P7, and the corresponding next associated task node includes P7.
[0090] (4) If the next associated task node of any target-dependent edge is the target task node, then the detection result of the target detection branch corresponding to the starting detection edge having a cycle is determined as the sub-detection result of the task node corresponding to the starting detection edge.
[0091] Specifically, for cases where the number of target dependency edges is not zero, if the number of target dependency edges is 1, then the number of the next associated task nodes is also 1; if the number of target dependency edges is greater than 1, then the number of the next associated task nodes is also greater than 1. Specifically, after determining the corresponding next associated task node for each target dependency edge, it is determined whether the next associated task node is the target task node. If the next associated task node of a certain target dependency edge is the target task node, it indicates that the process has returned from the current task node to be detected to the target task node. For example, in the above... Figure 2a In the case where the specified detection direction is the opposite of the task scheduling direction, if the current task node to be detected is P5, then the target dependency edge includes P5→P2. Correspondingly, the next associated task node is the target task node P2. Therefore, the sub-detection result of the task node corresponding to the starting detection edge is determined to be a cycle in the target detection branch corresponding to the starting detection edge. In other words, at the second detection node, the criterion for determining that the target directed graph is a directed cyclic graph is that the number of target dependency edges of the current task node to be detected in the specified detection direction is not zero, and at least one target dependency edge corresponds to the next associated task node as the target task node.
[0092] (5) If the next associated task node of each target dependency edge is not a target task node, then the next associated task node is determined as the next task node to be detected.
[0093] Specifically, if none of the next associated task nodes of the target dependency edge of the current task node to be detected are the target task node, it means that the current task node to be detected has not returned to the target task node, nor has it reached the end task node in the specified detection direction, and the detection can continue; for example, in the above Figure 2a If the current task node to be detected is P9, then the number of target dependency edges is 2. The next associated task nodes corresponding to these two target dependency edges include P7 and P8. That is, neither the next associated task node P7 nor P9 is the target task node P2. Therefore, the next associated task nodes P7 and P8 are determined as the next task nodes to be detected. That is, the number of target dependency edges of the current task nodes to be detected P7 and P8 is determined until the preset stop detection condition is met. The preset stop detection condition for a certain starting detection edge includes at least one of the following: the number of target dependency edges is zero and the next associated task node is the target task node.
[0094] In the embodiments provided in this application, during the detection of the task node to be detected in the target directed graph, the number of target dependency edges of the currently detected associated task node in the specified detection direction is used. If the number of target dependency edges is not zero, it is then determined whether the next associated task node corresponding to the target dependency edge is the target task node. This process continues until the preset stop detection condition is met. In this way, it is possible to quickly identify whether there is a loop that returns to the target task node, and thus determine whether the target directed graph is a directed cyclic graph.
[0095] In specific implementation, in order to further reduce the detection volume of associated task nodes, for cases where there are multiple starting detection edges corresponding to the target task node and node detection is performed sequentially for each starting detection edge, the associated task nodes detected during the node detection process for a certain starting detection edge can be recorded. For example, the detected associated task nodes can be added to a preset set of detected nodes. In this way, repeated detection can be avoided during the subsequent node detection process for other starting detection edges, thereby further improving detection efficiency. Based on this, in the above (5), if the next associated task node of each target dependent edge is not the target task node, the next associated task node is determined as the next task node to be detected, specifically including:
[0096] (5-1) If the next associated task node of each target dependency edge is not a target task node, then determine whether the next associated task node belongs to the set of detected nodes; wherein, the set of detected nodes includes the associated task nodes detected for other initial detection edges.
[0097] (5-2) If the next associated task node belongs to the above set of detected nodes, continue to detect the next starting edge until the task node sub-detection result is a cycle, or the currently selected starting edge is the last starting edge to be detected.
[0098] Specifically, if the next associated task node corresponding to the current task node to be detected belongs to the set of detected nodes, it means that other associated task nodes in the specified detection direction, starting from the current task node to be detected, have already been detected and do not need to be detected again, thus avoiding duplicate detection. Therefore, after the node detection for the previously selected starting detection edge is completed, the associated task nodes detected for the starting detection edge are added to the preset set of detected nodes to reduce the number of node detections performed for the subsequently selected starting detection edge. That is, the overlapping part between the first target detection branch corresponding to the previously selected starting detection edge and the second target detection branch corresponding to the subsequently selected starting detection edge only needs to be detected once. Correspondingly, the above-mentioned preset stop detection condition may also include the next associated task node belonging to the set of detected nodes.
[0099] Furthermore, in specific implementation, the detected associated task nodes can be added to the detected node set after node detection is completed for a certain starting detection edge; alternatively, the detected associated task nodes can be added to the detected node set in real time during the node detection process for a certain starting detection edge. In this way, when the target detection branch corresponding to a certain starting detection edge contains multiple target sub-detection branches, the overlapping parts of the multiple target sub-detection branches can be detected only once, that is, the overlapping parts of the multiple target sub-detection branches do not need to be detected repeatedly. The specific method of recording detected nodes can be set according to actual needs.
[0100] (5-3) If the next associated task node does not belong to the above set of detected nodes, then the next associated task node is determined as the next task node to be detected. That is, the other associated task nodes on the target detection branch corresponding to the starting detection edge are detected to determine whether a certain associated task node returns to the target task node, and thus determine whether the target directed graph is a directed cyclic graph.
[0101] For example, such as Figure 2c As shown, taking the newly added dependent edges including connection edge A between P12 and P7 and connection edge B between P12 and P14, and specifying the detection direction as the opposite direction of the task scheduling direction, with the target task node being P12 as an example, if the initially selected starting detection edge is connection edge A, and the starting detection node corresponding to connection edge A is P7 (i.e., the first associated task node), the following cycle detection operation is performed on the current task node to be detected, P7, as follows:
[0102] The current task node P7 to be detected has 2 target dependency edges in the opposite direction of the task scheduling direction, meaning the number of target dependency edges is not zero. Therefore, the next associated task nodes corresponding to these two target dependency edges are P5 and P19. This means that neither P5 nor P19 is the target task node P12. We then need to determine whether the next associated task nodes P5 and P19 belong to the set of detected nodes. Since connecting edge A is the first selected starting detection edge, associated task nodes P5 and P19 do not belong to the set of detected nodes. Next, we will consider the next associated task nodes P5 and P19... 19 is identified as the next task node to be detected. Continue to perform the above cycle detection operation on the current task nodes P5 and P19 until the target sub-detection branches P7→P5→P2→P1 and P7→P19→P20→P21→P1 contained in the target detection branch corresponding to the connection edge A are passed. Since the number of target dependency edges of task node P1 is zero, it can be determined that the task node sub-detection result of the connection edge A is that the target detection branch is cycle-free. Then, add the task nodes P7, P5, P2, P19, P20, P21, and P1 detected for the connection edge A to the set of detected nodes.
[0103] Next, node detection needs to be performed on the connecting edge B, which is selected as the starting detection edge. The starting detection node corresponding to connecting edge B is P14 (i.e., the first associated task node). The following cycle detection operation is performed on the current task node P14 to be detected, specifically:
[0104] The number of target dependency edges of the current task node P14 in the opposite direction of the task scheduling direction is 1, that is, the number of target dependency edges is not zero. Therefore, the next associated task node corresponding to this target dependency edge is P11. That is, the next associated task node P11 of this target dependency edge is not the target task node P12. Then, it is determined whether the next associated task node P11 belongs to the set of detected nodes. Since the associated task node P11 does not belong to the set of detected nodes, the next associated task node P11 is determined as the next task node to be detected.
[0105] The number of target dependency edges of the current task node P11 in the opposite direction of the task scheduling direction is 1, that is, the number of target dependency edges is not zero. Therefore, the next associated task node corresponding to this target dependency edge is P7. That is, the next associated task node P7 of this target dependency edge is not the target task node P12. Then, we need to determine whether the next associated task node P7 belongs to the set of detected nodes. Since task nodes P7, P5, P2, P19, P20, P21, and P1 have been added to the set of detected nodes for connecting edge A, it can be known that the next associated task node P7 belongs to the set of detected nodes. Therefore, there is no need to continue to repeat the detection of the target sub-detection branches P7→P5→P2→P1 and P7→P19→P20→P21→P1. We can directly determine that the task node sub-detection result of connecting edge B is that the target detection branch is acyclic.
[0106] Next, since the initial detection edges A and B have been completed, based on the task node sub-detection results of connecting edge A and connecting edge B, it can be determined that the target directed graph is a directed acyclic graph.
[0107] In the embodiments provided in this application, by adding the associated task nodes detected for the initially selected starting detection edge to a preset set of detected nodes, during the node detection process for the subsequently selected starting detection edge, if the number of target dependency edges of the current task node to be detected is not zero, and the next associated task node of the target dependency edge is not the target task node, it can be determined whether the next associated task node does not belong to the set of detected nodes. Only if it does not belong will the subsequent associated task nodes continue to be detected. This can avoid repeated detection of overlapping parts in the target detection branches corresponding to different starting detection edges, thereby further improving the efficiency of directed graph detection.
[0108] Additionally, it should be noted that after determining the current task node to be detected, it is possible to directly determine whether the current task node to be detected belongs to the set of detected nodes; if it does not belong, then the cycle detection operation is triggered, that is, to determine whether the number of target dependency edges of the current task node to be detected in the specified detection direction is zero; however, considering that the number of target dependency edges can be quickly and accurately determined based on the target directed graph, and that if the number of target dependency edges of the current task node to be detected in the specified detection direction is zero, it means that the terminal task node has been reached, and the sub-detection result of the task node corresponding to the starting detection edge can be directly determined, therefore, preferably, it is preferable to first determine whether the number of target dependency edges of the current task node to be detected is zero. Then, it is determined whether the next associated task node of the target dependency edge is in the set of detected nodes to determine whether the next associated task node has been detected, and then decides whether to continue to detect the next associated task node. That is to say, in this embodiment, instead of first determining whether the current task node to be detected belongs to the set of detected nodes, it is first determined whether the number of target dependency edges of the current task node to be detected is zero, and then it is determined whether the next associated task node of the target dependency edge is in the set of detected nodes. In this way, for the case where the number of target dependency edges is zero, the step of searching for the current task node to be detected in the set of detected nodes is eliminated, thereby further improving the efficiency of directed graph detection.
[0109] In one specific embodiment, such as Figure 3 As shown, taking the specified detection direction as the opposite direction of the task scheduling direction as an example, the specific implementation process of the task scheduling method provided in this application embodiment is given, which mainly includes:
[0110] Based on the task change information corresponding to the target directed graph, determine the change type from the initial directed graph to the target directed graph;
[0111] The above change types are matched with multiple sub-constraints in the preset acyclic conditions to obtain the change type matching results;
[0112] Determine whether the change type matching result matches the preset acyclic condition;
[0113] If a match is found, the target directed graph is determined to be a directed acyclic graph.
[0114] If there is no match, the target task node is determined in the target directed graph based on the above task change information.
[0115] For cases where the specified detection direction is the opposite of the task scheduling direction, multiple newly added upstream dependency edges corresponding to the target task node are determined as the starting detection edges;
[0116] Select one of the multiple initial detection edges to be detected;
[0117] For the current starting edge to be detected, the upstream task node directly connected to the target task node on the starting edge is taken as the starting detection node. The current task node to be detected (i.e., the upstream task node directly connected to the target task node or the upstream task node indirectly connected to the target task node) is determined based on the opposite direction of the target directed graph and the task scheduling direction.
[0118] Determine whether the number of target dependency edges of the current task node to be detected in the opposite direction of the task scheduling direction is zero (i.e., whether the in-degree value of the current task node to be detected is zero).
[0119] If it is zero, then determine whether the associated task nodes on the target detection branch corresponding to the current starting detection edge to be detected have been detected.
[0120] If the detection is completed, the sub-detection result of the task node corresponding to the starting detection edge to be detected is determined to be acyclic in the target detection branch.
[0121] If the detection is not completed, the next task node to be detected is determined. The next task node to be detected is the associated task node on other target sub-detection branches in the target detection branch corresponding to the current starting detection edge.
[0122] If it is not zero, then determine the next associated task node corresponding to at least one target dependency edge; where the next associated task node is the upstream task node on the target dependency edge that is directly connected to the current task node to be detected.
[0123] Determine whether the next associated task node corresponding to any target dependency edge is the target task node;
[0124] If so, then the sub-detection result of the task node corresponding to the current starting detection edge to be detected is determined to be a target detection branch with a cycle;
[0125] If not, determine whether the next associated task node corresponding to the target dependency edge belongs to the set of detected nodes;
[0126] If it does not belong to the target, the next task node to be detected is determined, that is, the next associated task node corresponding to the target dependency edge is determined as the next task node to be detected, until the associated task nodes on the target detection branch corresponding to the current starting detection edge to be detected are detected.
[0127] If it belongs to the category, then the sub-detection result of the task node corresponding to the current starting detection edge to be detected is determined to be acyclic in the target detection branch;
[0128] Determine whether the current starting edge to be detected is the last starting edge to be detected;
[0129] If not, continue to select the next starting edge to be detected until the task node sub-detection result is a cycle, or the current starting edge to be detected is the last starting edge to be detected.
[0130] If so, the second detection result of the target directed graph is determined based on the sub-detection results of the task nodes corresponding to each initial detection edge.
[0131] Furthermore, considering the case where the target directed graph is a directed cyclic graph, regardless of the sub-detection method used, the target detection branch corresponding to the initial detection edge is always a cycle, so the detection efficiency is basically the same. However, for the case where the target directed graph is a directed acyclic graph, if there are many task nodes and complex dependencies in the target directed graph, for target task nodes near the upstream end node, using a detection method based on the reverse direction of task scheduling to detect whether there is a cycle to detect the upstream task nodes will be more efficient. For target task nodes near the downstream end node, using a detection method based on the task scheduling direction to detect whether there is a cycle is more efficient. Cycle detection is more efficient at detecting downstream task nodes of the target task node. Therefore, the specified detection direction corresponding to the aforementioned preset cycle detection method is not a default value, but rather a more efficient target sub-detection method is selected specifically for different target task nodes. This determines the starting detection edge of the target task node along the specified detection direction corresponding to that target sub-detection method. Specifically, the aforementioned preset cycle detection method includes multiple sub-detection methods for detecting whether a directed graph has a cycle. Correspondingly, step B2, based on the specified detection direction corresponding to the preset cycle detection method, determines the starting detection edge of the target task node, specifically including:
[0132] Step B21: Determine the target sub-detection method corresponding to the target task node from multiple sub-detection methods; wherein, the target sub-detection method includes a first sub-detection method that detects whether there is a cycle based on the opposite direction of the task scheduling direction, or a second sub-detection method that detects whether there is a cycle based on the task scheduling direction. The specified detection direction corresponding to the first sub-detection method is the opposite direction of the task scheduling direction, and the specified detection direction corresponding to the second sub-detection method is the task scheduling direction.
[0133] Specifically, the sub-detection method can be determined in real time based on the target directed graph. However, this inevitably reduces the overall detection efficiency due to the increased traversal and comparison of upstream and downstream task nodes in the target directed graph. To address this issue, considering that if the target directed graph is a directed acyclic graph, and for the case where the specified detection direction is the opposite of the task scheduling direction, the node detection branch after the first associated task node with a dependency relationship to the target task node on the newly added dependency edge in the target directed graph is the same as the node detection branch after that first associated task node in the initial directed graph (e.g., the above). Figure 2bIn the target directed graph and the initial directed graph, the node detection branches after the first associated task node P7 of the target task node P12 are the same. For the case where the specified detection direction is the task scheduling direction, the node detection branches after the target task node in the target directed graph are also the same as those in the initial directed graph (e.g., the above). Figure 2b In the target directed graph and the initial directed graph, the node detection branches after the target task node P12 are the same. Therefore, the graph structure data of the initial directed graph can be stored in advance. In this way, during the detection of the target directed graph, the first detection quantity from the target task node to the upstream end node and the second detection quantity from the target task node to the downstream end node can be determined based on the pre-stored graph structure data of the initial directed graph. Then, the target sub-detection method corresponding to the target task node can be determined based on the relationship between the first detection quantity and the second detection quantity.
[0134] In other words, the determination of the first and second detection quantities is not based on the target directed graph in real time, but on the graph structure data of the initial directed graph before the change. This can improve the efficiency of determining the first and second detection quantities. Therefore, after determining that the target directed graph is a directed acyclic graph, it is also necessary to update the graph structure data of the initial directed graph based on the task change information, so as to serve as the graph structure data of the initial directed graph corresponding to the next task change event (i.e., the target directed graph corresponding to this change event). Then, based on the graph structure data, the target sub-detection method corresponding to the target task node corresponding to the next task change event is determined in a targeted manner.
[0135] Furthermore, in specific implementation, considering that for the case where the target directed graph is a directed cyclic graph, regardless of the sub-detection method used, the target detection branch corresponding to the initial detection edge is a loop, so the detection efficiency is basically the same. However, for the case where the target directed graph is a directed acyclic graph, the number of arrows in the target detection branch corresponding to the initial detection edge can reflect the number of nodes detected in the specified detection direction. Therefore, a first neural network model can be introduced. The first neural network model to be trained is pre-trained based on the first training sample set to obtain a trained first neural network model. Then, the target directed graph is input into the first neural network model, and the number of first arrows from the target task node to the upstream end node and the number of second arrows from the target task node to the downstream end node are extracted. The number of first arrows is then determined as the first detection quantity from the target task node to the upstream end node, and the number of second arrows is determined as the second detection quantity from the target task node to the downstream end node. Then, the target sub-detection method corresponding to the target task node is determined based on the relationship between the first detection quantity and the second detection quantity.
[0136] It should be noted that in specific implementation, if the overlapping detection branch is only detected once in the second detection stage, then the overlapping detection branch is also only calculated once in the process of determining the first detection quantity and the second detection quantity. This can improve the accuracy of determining the first detection quantity and the second detection quantity, thereby improving the accuracy of determining the target sub-detection method.
[0137] Step B22: If the target sub-detection method is the first sub-detection method, then the newly added upstream dependency edge of the target task node is determined as the starting detection edge of the target task node.
[0138] Specifically, for the case where the target sub-detection method is the first sub-detection method, all upstream dependency edges of the target task node can be used as starting detection edges. However, considering that if the starting detection edges of the target task node in the opposite direction of the task scheduling direction include both newly added dependency edges and existing dependency edges, since the initial directed graph is a directed acyclic graph, the target directed graph will only become a directed cyclic graph due to the addition of dependency edges. Therefore, only the newly added dependency edges can be used as starting detection edges, which can further improve the efficiency of directed graph detection; for example, the above... Figure 2c In the target task node P12, the starting detection edges in the opposite direction of the task scheduling direction include newly added dependency edges (the connection edge between P7 and P12 and the connection edge between P14 and P12) and existing dependency edges (the connection edge between P9 and P12 and the connection edge between P10 and P12). Therefore, only the connection edges between P7 and P12 and the connection edges between P14 and P12 can be determined as the starting detection edges of the target task node P12, without having to detect the target detection branches corresponding to the connection edges between P9 and P12 and the connection edges between P10 and P12, which further improves the efficiency of directed graph detection.
[0139] Step B23: If the target sub-detection method is the second sub-detection method, then the downstream dependency edge of the target task node is determined as the starting detection edge of the target task node.
[0140] Specifically, regarding the case where the target sub-detection method is the second sub-detection method, although the newly added dependency edge may be an upstream dependency edge of the target task node, the downstream dependency edges of the target task node are all existing dependency edges. Therefore, each existing dependency edge needs to be determined as the starting detection edge of the target task node to detect whether there is a return path from the starting detection edge back to the target task node through the newly added dependency edge, thereby determining whether the target directed graph is a directed cyclic graph. However, the second sub-detection method is mainly used when the number of node detections from the target task node to the downstream end node is much smaller than the number of node detections from the target task node to the upstream end node, that is, the target task node is closer to the downstream end node. In this case, even if the number of starting detection edges is relatively large, the detection efficiency of the second sub-detection method is still higher than that of the first sub-detection method mentioned above, where the starting detection edges only include newly added dependency edges. For example, in the above Figure 2b Taking the target task node P12 as an example, if the second sub-detection method is used, the target detection branches corresponding to the target task node include P12→P15→P16 and P12→P13. That is, the number of associated task nodes that need to be detected is relatively small, so the target directed graph can be efficiently determined to be a directed acyclic graph. However, if the first sub-detection method is used, even if only the newly added dependent edges are determined as the starting detection edges, the number of nodes that need to be detected along the opposite direction of the task scheduling direction for a certain starting detection edge is much greater than the number of nodes that need to be detected along the task scheduling direction for all downstream dependent edges. Therefore, for the target task node P12, the second sub-detection method is more efficient.
[0141] In the embodiments provided in this application, by determining which sub-detection method to select as the target sub-detection method for different target task nodes based on the first detection quantity from the target task node to the upstream end node and the second detection quantity from the target task node to the downstream end node, a more efficient target sub-detection method can be selected for different target task nodes. This allows for the determination of the starting detection edge of the target task node in the specified detection direction corresponding to the target sub-detection method, thereby further reducing the detection quantity of associated task nodes on the target detection branch.
[0142] The process of determining the target sub-detection method can be based on the pre-stored graph structure data of the initial directed graph, or it can be determined using a pre-trained first neural network model. Specifically, for the process of determining the target sub-detection method corresponding to the target task node based on the pre-stored graph structure data of the initial directed graph, step B21 above, which determines the target sub-detection method corresponding to the target task node from multiple sub-detection methods, specifically includes:
[0143] B211, based on the pre-stored graph structure data of the initial directed graph, determine the target structure data of the target task node; wherein, the target structure data includes the first detection quantity from the target task node to the upstream end node, and the second detection quantity from the target task node to the downstream end node.
[0144] Specifically, considering that the initial directed graph does not contain newly added dependent edges, the pre-stored graph structure data of the initial directed graph only includes the third node detection quantity from the first associated task node with a dependency relationship with the target task node on the newly added dependent edge to the upstream end node. Therefore, adding one to the third node detection quantity can determine the node detection quantity from the target task node to the upstream end node. For example, for the target directed graph shown in Figure 2 above, the pre-stored graph structure data of the initial directed graph only includes the third node detection quantity from the first associated task node P7 to the upstream end node P1. Therefore, it is necessary to add the node detection quantity from the target task node P12 to the first associated task node P7.
[0145] B212, based on the first and second detection quantities mentioned above, determine the target sub-detection method corresponding to the target task node.
[0146] Specifically, if the first detection quantity is less than or equal to the second detection quantity, the first sub-detection method is determined as the target sub-detection method corresponding to the target task node; if the first detection quantity is greater than the second detection quantity, the second sub-detection method is determined as the target sub-detection method corresponding to the target task node. Furthermore, considering that for the first sub-detection method, only the newly added dependent edge can be determined as the starting detection edge, the judgment condition for selecting the first sub-detection method can be relaxed. The second sub-detection method is only selected when the second detection quantity is relatively small. That is, if the first detection quantity is greater than the second detection quantity and the difference between the first detection quantity and the second detection quantity is greater than the preset threshold, the second sub-detection method is determined as the target sub-detection method corresponding to the target task node; otherwise, the first sub-detection method is determined as the target sub-detection method corresponding to the target task node.
[0147] In the embodiments provided in this application, the first detection quantity from the target task node to the upstream end node and the second detection quantity from the target task node to the downstream node are estimated based on the graph structure data of the pre-stored initial directed graph to determine which detection method is more efficient. The first and second detection quantities are determined based on the graph structure data of the pre-stored initial directed graph, rather than being determined in real time based on the target directed graph. This can further improve the detection efficiency of the target directed graph without increasing the traversal of task nodes due to the determination of the first and second detection quantities.
[0148] Furthermore, considering the case where the target task node corresponds to multiple initial detection edges to be detected, and taking into account that if a cycle is detected for a certain initial detection edge, the target directed graph can be directly determined to be a directed cyclic graph, the probability of a cycle existing in the target detection branch corresponding to the initial detection edge to be detected can be predicted. Then, the target detection branches corresponding to the initial detection edges are detected sequentially in descending order of predicted probability. Based on this, if the number of initial detection edges corresponding to the target task node is multiple; correspondingly, after determining the initial detection edge of the target task node in step B2 based on the specified detection direction corresponding to the preset cyclic detection method, the following steps are also included:
[0149] Step B5: Determine the detection priority of the multiple initial detection edges corresponding to the target task node;
[0150] Specifically, to further improve the efficiency of directed graph detection, it is necessary to prioritize the detection of multiple initial detection edges, prioritizing the detection of associated task nodes on the target detection branch corresponding to the initial detection edge most likely to contain a cycle. This way, if a cycle is found in a target detection branch, detection can be stopped directly, thereby further accelerating the efficiency of directed graph detection. Therefore, step B5 above, determining the detection priority of multiple initial detection edges corresponding to the target task node, specifically includes:
[0151] The directed graph of the target is input into a pre-trained deep neural network model, and loop prediction is performed on the target detection branch corresponding to each starting detection edge to obtain the prediction result corresponding to each starting detection edge. The prediction result includes the prediction probability that the target detection branch corresponding to the starting detection edge has a loop. Based on the magnitude of the above prediction probability, the detection priority of each starting detection edge is determined.
[0152] Specifically, to distinguish it from the first neural network model mentioned above, the deep neural network model can be called the second neural network model. The second neural network model to be trained is pre-trained based on the second training sample set to obtain the trained second neural network model (i.e., the pre-trained deep neural network model). Then, the target directed graph is input into the second neural network model, the arrow pointing feature vectors corresponding to each starting detection edge are extracted, and the prediction results corresponding to the starting detection edges are determined based on the arrow pointing feature vectors.
[0153] Specifically, the second training sample set includes multiple labeled directed acyclic sample graphs and multiple directed cyclic sample graphs. During training, the second neural network model continuously learns the arrow direction rules of cyclic branches based on the arrow pointing feature vectors corresponding to cyclic branches in the directed cyclic sample graphs, and learns the arrow direction rules of acyclic branches based on the arrow pointing feature vectors corresponding to acyclic branches in the directed acyclic sample graphs. Thus, the trained second neural network model can predict which starting detection edge in the directed graph to be detected has a higher probability of containing a cycle in the target detection branch. It then prioritizes detecting the associated task nodes on the target detection branch corresponding to the starting detection edge. In this way, when the target directed graph is a directed cyclic graph, it can quickly detect branches containing cycles, thereby further improving the directed graph detection efficiency.
[0154] Furthermore, the electronic device equipped with a task scheduling device (especially an electronic device equipped with directed graph detection) provided in this application embodiment can access the servers corresponding to multiple preset business services to detect the target directed graphs corresponding to the multiple preset business services. Therefore, the aforementioned second training sample set can be multiple labeled directed acyclic sample graphs and multiple directed cyclic sample graphs from each preset business service. This can increase the amount of directed graph sample data in the second training sample set, thereby improving the training accuracy of the second neural network model. Moreover, if the directed graph sample data from one preset business service has a high degree of consistency with the target directed graph corresponding to another preset business service, the prediction probability accuracy of whether the target detection branch corresponding to the starting detection edge in the target directed graph has a cycle can be improved. This allows the directed graph sample data that is more helpful for optimizing the parameters of the second neural network model to play a role in the detection process of the target directed graphs of multiple preset business services.
[0155] Step B6: Based on the above detection priority, determine the starting detection edge to be detected in descending order of detection priority.
[0156] In the embodiments provided in this application, a pre-trained deep neural network model is used to predict which starting detection edge has a higher probability of containing a cycle in the target detection branch. The starting detection edge with a higher probability is given priority as the starting detection edge to be detected, so as to quickly identify the case that the target directed graph is a directed cyclic graph, thereby further improving the detection efficiency of the target directed graph.
[0157] In practical implementation, the task scheduling method provided in this application can be applied to any application scenario based on directed acyclic graphs (DAGs). The latest target directed graph may be obtained by modifying the original DAG multiple times. The original DAG can be pre-constructed based on the data processing requirements of preset business services. Specifically, for example... Figure 4 As shown, in S102, before obtaining the directed graph of the target to be detected, the following steps are also included:
[0158] S112, Obtain data processing requirements information for preset business services; wherein, preset business services may include any one of online shopping business services, fund application business services, and logistics business services;
[0159] S114. Based on the above data processing requirement information, determine the multiple data processing tasks involved in the preset business service and the dependencies between the multiple data processing tasks.
[0160] S116. Based on the above multiple data processing tasks and the dependencies between them, construct the original directed acyclic graph corresponding to the preset business service; wherein, each data processing task corresponds to a task node in the original directed acyclic graph, and each dependency corresponds to a dependency edge in the original directed acyclic graph.
[0161] S118, Determine an initial directed graph based on the original directed acyclic graph mentioned above; wherein, the initial directed graph includes the original directed acyclic graph mentioned above, or a directed acyclic graph obtained by making at least one change to the original directed acyclic graph mentioned above.
[0162] S120, based on the above initial directed graph and task change information, determine the target directed graph corresponding to the preset business service.
[0163] For example, in the application scenario of online shopping services, the inventory of goods to be sold is finally calculated based on the calculation results of upstream task nodes; in the application scenario of fund application services, the distribution of current non-paying users in terms of location is finally calculated based on the calculation results of upstream task nodes; and in the application scenario of logistics services, the distribution of current undelivered packages in terms of delivery locations is finally calculated based on the calculation results of upstream task nodes, and so on. Since any application scenario based on directed acyclic graphs (DAGs) requires ensuring that the target directed graph is a DAG, after determining the target directed graph, steps S102 to S108 in the above task scheduling method are first used to detect whether the target directed graph is a DAG. If the target directed graph is a DAG, task scheduling is then performed based on the target directed graph to obtain the final required business data calculation results.
[0164] The task scheduling method in this embodiment, after obtaining the target directed graph to be detected, first matches the change type of the target directed graph based on task change information and preset acyclic constraints to obtain a first detection result; then, based on the first detection result, it decides whether to continue detecting some task nodes in the target directed graph. That is, if the change type represented by the first detection result matches the preset acyclic constraints, the target directed graph can be directly determined to be a directed acyclic graph; if the change type represented by the first detection result does not match the preset acyclic constraints, the task nodes to be detected in the target directed graph are then detected based on task change information and preset acyclic detection methods to obtain a second detection result representing whether the target directed graph is a directed acyclic graph. Since in the directed graph detection process, the change type of the target directed graph is first identified as conforming to the preset acyclic constraints (i.e., the first detection stage, a rapid detection stage that matches the change type with the acyclic constraints), if the change type conforms to the preset acyclic constraints... If the acyclic constraint condition is met, the target directed graph can be directly determined to be a directed acyclic graph. If the change type does not meet the preset acyclic constraint condition, then a portion of the task nodes in the target directed graph are detected based on the preset cycle detection method to identify whether the target directed graph has a cycle (i.e., the second detection stage, which detects whether there is a cycle from the target task node to a specified detection direction). On the one hand, if the change type is determined to match the preset acyclic constraint condition in the first detection stage, there is no need to continue to execute the second detection stage. In this way, the hierarchical and phased directed graph detection method can greatly reduce the detection time of directed graphs and improve the detection efficiency. On the other hand, even if the second detection stage needs to be executed on the target directed graph, it is only necessary to detect whether there is a cycle starting from the target task node along the task scheduling direction or the opposite direction of the task scheduling direction. It is not necessary to traverse all task nodes. In this way, the detection efficiency of directed graphs can also be improved even if the change type does not meet the preset acyclic constraint condition.
[0165] Corresponding to the above Figures 1 to 4 Based on the same technical concept, this application also provides a task scheduling apparatus in its embodiments regarding the described task scheduling method. Figure 5 This is a schematic diagram of the module composition of the task scheduling device provided in the embodiments of this application. The device is used to execute... Figures 1 to 4 The described task scheduling method, such as Figure 5 As shown, the device includes:
[0166] The directed graph acquisition module 502 is configured to acquire the target directed graph to be detected; the target directed graph is obtained by modifying the initial directed graph based on task change information, and the initial directed graph is a directed acyclic graph;
[0167] The first detection module 504 is configured to match the change type of the target directed graph based on the task change information and the preset acyclic constraint condition to obtain a first detection result of the target directed graph; the first detection result includes a detection result characterizing whether the change type matches the preset acyclic constraint condition;
[0168] The second detection module 506 is configured to, if the first detection result does not match, detect the task nodes to be detected in the target directed graph based on the task change information and the specified detection direction corresponding to the preset cycle detection method, to obtain a second detection result of the target directed graph; the specified detection direction includes the task scheduling direction or the opposite direction of the task scheduling direction, the task nodes to be detected include associated task nodes that have a dependency relationship with the target task node in the specified detection direction starting from the target task node, the target task node is a task node related to the task change information, and the second detection result includes a detection result indicating that the target directed graph is a directed acyclic graph or a directed cyclic graph;
[0169] The task scheduling module 508 is configured to perform task scheduling on multiple task nodes in the target directed graph based on the target directed graph if the second detection result indicates that the target directed graph is a directed acyclic graph.
[0170] In this embodiment of the task scheduling device, after acquiring the target directed graph to be detected, it first matches the change type of the target directed graph based on task change information and preset acyclic constraints to obtain a first detection result. Then, based on the first detection result, it decides whether to continue detecting some task nodes in the target directed graph. That is, if the change type represented by the first detection result matches the preset acyclic constraints, the target directed graph can be directly determined to be a directed acyclic graph. If the change type represented by the first detection result does not match the preset acyclic constraints, the task nodes to be detected in the target directed graph are then detected based on the task change information and preset acyclic detection method to obtain a second detection result representing whether the target directed graph is a directed acyclic graph. Since in the directed graph detection process, the change type of the target directed graph is first identified as conforming to the preset acyclic constraints (i.e., the first detection stage, a rapid detection stage that matches the change type with the acyclic constraints), if the change type conforms to the preset acyclic constraints... If the acyclic constraint condition is met, the target directed graph can be directly determined to be a directed acyclic graph. If the change type does not meet the preset acyclic constraint condition, then a portion of the task nodes in the target directed graph are detected based on the preset cycle detection method to identify whether the target directed graph has a cycle (i.e., the second detection stage, which detects whether there is a cycle from the target task node to a specified detection direction). On the one hand, if the change type is determined to match the preset acyclic constraint condition in the first detection stage, there is no need to continue to execute the second detection stage. In this way, the hierarchical and phased directed graph detection method can greatly reduce the detection time of directed graphs and improve the detection efficiency. On the other hand, even if the second detection stage needs to be executed on the target directed graph, it is only necessary to detect whether there is a cycle starting from the target task node along the task scheduling direction or the opposite direction of the task scheduling direction. It is not necessary to traverse all task nodes. In this way, the detection efficiency of directed graphs can also be improved even if the change type does not meet the preset acyclic constraint condition.
[0171] It should be noted that the embodiments of the task scheduling device in this application and the embodiments of the task scheduling method in this application are based on the same inventive concept. Therefore, the specific implementation of this embodiment can be referred to the implementation of the corresponding task scheduling method mentioned above, and the repeated parts will not be described again.
[0172] Furthermore, corresponding to the above Figures 1 to 4 Based on the same technical concept, this application also provides a task scheduling device for executing the above-described task scheduling method, such as... Figure 6 As shown.
[0173] Task scheduling devices can vary considerably depending on configuration and performance. They may include one or more processors 601 and memory 602, with memory 602 storing one or more application programs or data. Memory 602 can be temporary or persistent storage. The application programs stored in memory 602 may include one or more modules (not shown), each module including a series of computer-executable instructions for the task scheduling device. Furthermore, processor 601 may be configured to communicate with memory 602, executing the series of computer-executable instructions stored in memory 602 on the task scheduling device. The task scheduling device may also include one or more power supplies 603, one or more wired or wireless network interfaces 604, one or more input / output interfaces 605, one or more keyboards 606, etc.
[0174] In one specific embodiment, the task scheduling device includes a memory and one or more programs, wherein the one or more programs are stored in the memory, and the one or more programs may include one or more modules, and each module may include a series of computer-executable instructions for the task scheduling device, and is configured to be executed by one or more processors. The one or more programs include computer-executable instructions for performing the following:
[0175] Obtain the target directed graph to be detected; the target directed graph is obtained by modifying the initial directed graph based on task change information, and the initial directed graph is a directed acyclic graph;
[0176] Based on the task change information and the preset acyclic constraint, the change type of the target directed graph is matched to obtain the first detection result of the target directed graph; the first detection result includes a detection result characterizing whether the change type matches the preset acyclic constraint.
[0177] If the first detection result does not match, then based on the task change information and the specified detection direction corresponding to the preset cycle detection method, the task nodes to be detected in the target directed graph are detected to obtain the second detection result of the target directed graph; the specified detection direction includes the task scheduling direction or the opposite direction of the task scheduling direction, the task nodes to be detected include associated task nodes that have a dependency relationship with the target task node in the specified detection direction starting from the target task node, the target task node is a task node related to the task change information, and the second detection result includes the detection result representing that the target directed graph is a directed acyclic graph or a directed cyclic graph;
[0178] If the second detection result indicates that the target directed graph is a directed acyclic graph, then task scheduling is performed on multiple task nodes in the target directed graph based on the target directed graph.
[0179] It should be noted that the embodiments of the task scheduling device in this application and the embodiments of the task scheduling method in this application are based on the same inventive concept. Therefore, the specific implementation of this embodiment can be referred to the implementation of the corresponding task scheduling method mentioned above, and the repeated parts will not be described again.
[0180] Furthermore, corresponding to the above Figures 1 to 4 Based on the same technical concept, this application also provides a storage medium for storing computer-executable instructions. In one specific embodiment, the storage medium can be a USB flash drive, optical disc, hard disk, etc. When the computer-executable instructions stored in the storage medium are executed by a processor, they can achieve the following process:
[0181] Obtain the target directed graph to be detected; the target directed graph is obtained by modifying the initial directed graph based on task change information, and the initial directed graph is a directed acyclic graph;
[0182] Based on the task change information and the preset acyclic constraint, the change type of the target directed graph is matched to obtain the first detection result of the target directed graph; the first detection result includes a detection result characterizing whether the change type matches the preset acyclic constraint.
[0183] If the first detection result does not match, then based on the task change information and the specified detection direction corresponding to the preset cycle detection method, the task nodes to be detected in the target directed graph are detected to obtain the second detection result of the target directed graph; the specified detection direction includes the task scheduling direction or the opposite direction of the task scheduling direction, the task nodes to be detected include associated task nodes that have a dependency relationship with the target task node in the specified detection direction starting from the target task node, the target task node is a task node related to the task change information, and the second detection result includes the detection result representing that the target directed graph is a directed acyclic graph or a directed cyclic graph;
[0184] If the second detection result indicates that the target directed graph is a directed acyclic graph, then task scheduling is performed on multiple task nodes in the target directed graph based on the target directed graph.
[0185] It should be noted that the embodiments concerning storage media in this application and the embodiments concerning task scheduling methods in this application are based on the same inventive concept. Therefore, the specific implementation of this embodiment can be referred to the implementation of the corresponding task scheduling method described above, and the repeated parts will not be described again.
[0186] The foregoing has described specific embodiments of this application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0187] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, embodiments of this application can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0188] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0189] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0190] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0191] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0192] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0193] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0194] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0195] The embodiments of this application can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. One or more embodiments of this application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules can reside in local and remote computer storage media, including storage devices.
[0196] The various embodiments in this application are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0197] The above description is merely an embodiment of this document and is not intended to limit the scope of this document. Various modifications and variations can be made to this document by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this document should be included within the scope of the claims of this document.
Claims
1. A task scheduling method, characterized by, The method comprises: obtaining a target directed graph to be detected; the target directed graph is obtained by changing an initial directed graph based on task change information, and the initial directed graph is a directed acyclic graph; based on the task change information and a preset acyclic constraint condition, matching a change type of the target directed graph to obtain a first detection result of the target directed graph; the first detection result comprises a detection result representing whether the change type matches the preset acyclic constraint condition; if the first detection result represents a mismatch, detecting a task node to be detected in the target directed graph based on the task change information and a specified detection direction corresponding to a preset cyclic detection mode to obtain a second detection result of the target directed graph; the specified detection direction comprises a task scheduling direction or a reverse direction of the task scheduling direction, the task node to be detected comprises an associated task node having a dependency relationship with a target task node in the specified detection direction starting from the target task node, the target task node is a task node related to the task change information, and the second detection result comprises a detection result representing whether the target directed graph is a directed acyclic graph or a directed cyclic graph; if the second detection result represents that the target directed graph is a directed acyclic graph, scheduling a plurality of task nodes in the target directed graph based on the target directed graph.
2. The method of claim 1, wherein, The preset acyclic constraint condition comprises a plurality of sub-constraint conditions for determining a directed graph acyclic; The method comprises: based on the task change information, determining a change type of the initial directed graph changed into the target directed graph, and matching the change type with each of the sub-constraint conditions; if the change type does not match a plurality of the sub-constraint conditions, determining a detection result representing that the change type does not match the preset acyclic constraint condition as the first detection result; if the change type matches a target sub-constraint condition in the plurality of sub-constraint conditions, determining a detection result representing that the change type matches the preset acyclic constraint condition as the first detection result.
3. The method of claim 1, wherein, The method comprises: based on the task change information, determining the target task node in the target directed graph; based on the specified detection direction corresponding to the preset cyclic detection mode, determining a starting detection edge of the target task node; the starting detection edge comprises a first directed edge having the target task node as one end in the specified detection direction; taking a first associated task node on the starting detection edge as a starting detection node, detecting the associated task nodes in the specified detection direction based on the target directed graph to obtain a task node sub-detection result; and Determine a second detection result of the target directed graph based on the task node sub-detection result corresponding to the starting detection edge.
4. The method of claim 3, wherein, The detecting, based on the target directed graph, of the associated task nodes in the specified detection direction to obtain task node sub-detection results comprises: Determine a current task node to be detected based on the target directed graph and the specified detection direction; and perform a loop detection operation on the current task node to be detected as follows: Determine the number of target dependent edges corresponding to the current task node to be detected; the target dependent edges include second directed edges having the current task node to be detected as one end in the specified detection direction; If the number of target dependent edges is zero, determine a detection result representing that a target detection branch is acyclic as the task node sub-detection result corresponding to the starting detection edge; If the number of target dependent edges is not zero, determine at least one next associated task node corresponding to the target dependent edge; the next associated task node is the other end of the second directed edge; If any of the next associated task nodes is the target task node, determine a detection result representing that a target detection branch is cyclic as the task node sub-detection result corresponding to the starting detection edge; If none of the next associated task nodes is the target task node, determine the next associated task node as a next task node to be detected.
5. The method of claim 4, wherein, The determining, if none of the next associated task nodes is the target task node, of the next associated task node as a next task node to be detected comprises: If none of the next associated task nodes is the target task node, determine whether the next associated task node belongs to a detected node set; the detected node set includes associated task nodes detected for other starting detection edges; If the next associated task node belongs to the detected node set, continue to detect for a next starting detection edge until the task node sub-detection result is cyclic or the starting detection edge is the last starting detection edge to be detected; If the next associated task node does not belong to the detected node set, determine the next associated task node as a next task node to be detected.
6. The method of claim 3, wherein, The preset loop detection manner comprises a plurality of sub-detection manners for detecting whether a directed graph has a loop; The determining, based on a specified detection direction corresponding to the preset loop detection manner, of a starting detection edge of the target task node comprises: Determine a target sub-detection manner corresponding to the target task node from a plurality of sub-detection manners; the target sub-detection manner includes a first sub-detection manner of detecting whether a loop exists based on a reverse direction of the task scheduling direction, or a second sub-detection manner of detecting whether a loop exists based on the task scheduling direction; If the target sub-detection manner is the first sub-detection manner, determine a newly added upstream dependent edge of the target task node as the starting detection edge of the target task node; If the target sub-detection mode is the second sub-detection mode, a downstream dependency edge of the target task node is determined as a starting detection edge of the target task node.
7. The method of claim 6, wherein, The determining of the target sub-detection mode corresponding to the target task node from the plurality of sub-detection modes comprises: determining target structure data of the target task node based on pre-stored graph structure data of the initial directed graph; the target structure data comprises a first detection quantity from the target task node to an upstream terminal node and a second detection quantity from the target task node to a downstream terminal node; determining the target sub-detection mode corresponding to the target task node based on the first detection quantity and the second detection quantity.
8. The method of claim 3, wherein, The number of starting detection edges corresponding to the target task node is a plurality; after determining the starting detection edge of the target task node based on the specified detection direction corresponding to the preset loop detection mode, the method further comprises: determining detection priorities of the plurality of starting detection edges corresponding to the target task node; determining a starting detection edge to be currently detected in order of detection priority from high to low based on the detection priorities.
9. The method of claim 8, wherein, The determining of the detection priorities of the plurality of starting detection edges corresponding to the target task node comprises: inputting the target directed graph into a pre-trained deep neural network model to perform loop prediction on a target detection branch corresponding to each starting detection edge to obtain a prediction result corresponding to each starting detection edge; the prediction result comprises a prediction probability representing that the target detection branch corresponding to the starting detection edge has a loop; determining the detection priority of each starting detection edge based on the size of the prediction probability.
10. The method according to any one of claims 1 to 9, characterized in that, Before obtaining the target directed graph to be detected, the method further comprises: obtaining data processing requirement information of a preset business service; the preset business service comprises any one of an online shopping business service, a fund application business service, and a logistics business service; determining a plurality of data processing tasks involved in the preset business service and dependency relationships between the plurality of data processing tasks based on the data processing requirement information; constructing a most original directed acyclic graph corresponding to the preset business service based on the plurality of data processing tasks and the dependency relationships between the plurality of data processing tasks; each data processing task corresponds to a task node in the most original directed acyclic graph, and each dependency relationship corresponds to a dependency edge in the most original directed acyclic graph; the initial directed graph comprises the most original directed acyclic graph or a directed acyclic graph obtained by changing the most original directed acyclic graph at least once.
11. A task scheduling apparatus characterized by comprising: The apparatus comprises: a directed graph obtaining module configured to obtain a target directed graph to be detected; the target directed graph is obtained by changing an initial directed graph based on task change information, and the initial directed graph is a directed acyclic graph; The first detection module is configured to match a change type of the target directed graph based on the task change information and a preset acyclic constraint condition, to obtain a first detection result of the target directed graph; the first detection result includes a detection result representing whether the change type matches the preset acyclic constraint condition; The second detection module is configured to, if the first detection result represents a mismatch, detect a to-be-detected task node in the target directed graph based on the task change information and a specified detection direction corresponding to a preset cyclic detection manner, to obtain a second detection result of the target directed graph; the specified detection direction includes a task scheduling direction or a reverse direction of the task scheduling direction, the to-be-detected task node includes an associated task node having a dependency relationship with the target task node in the specified detection direction starting from a target task node, the target task node is a task node related to the task change information, and the second detection result includes a detection result representing whether the target directed graph is a directed acyclic graph or a directed cyclic graph; The task scheduling module is configured to, if the second detection result represents that the target directed graph is a directed acyclic graph, perform task scheduling on a plurality of task nodes in the target directed graph based on the target directed graph.
12. A task scheduling device, characterized by comprising: The device includes: a processor; and a memory arranged to store computer-executable instructions configured to be executed by the processor, the executable instructions including steps for performing a method as claimed in any one of claims 1 to 10.
13. A storage medium, characterized by The storage medium is used to store computer-executable instructions, which cause a computer to perform a method as claimed in any one of claims 1 to 10.
Citation Information
Patent Citations
Loop detection method and device in directed graph, equipment and storage medium
CN110968429A
Cyclic dependency detection method and system in micro-service system
CN114416564A
Cited By
Assuring performance in a computing environment using an attribute dependency graph to allocate resources
US20250110795A1