A task scheduling method and device

By generating the task scheduling relationship diagram and setting the scheduling parameters, the problem of low task scheduling efficiency in the Java system is solved, and flexible task scheduling and efficiency improvement are achieved.

CN112306471BActive Publication Date: 2024-09-13BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011119940.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-19
Publication Date
2024-09-13
Estimated Expiration
2040-10-19

AI Technical Summary

Technical Problem

In the Java system, task scheduling efficiency is low, especially in scenarios where the number of tasks and dependencies change dynamically, which is difficult to effectively handle with existing technology, resulting in a waste of time in writing code and affecting scheduling efficiency.

Method used

By generating the scheduling relationship diagram of the task, setting the scheduling parameters of the task thread, and submitting it to the thread pool, the task thread is executed according to the scheduling parameters to achieve flexible task scheduling.

Benefits of technology

It improves the efficiency of task scheduling, flexibly handles dependencies between tasks, reduces the time of writing code, and improves the efficiency of task execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112306471B
    Figure CN112306471B
Patent Text Reader

Abstract

The present application relates to a method and device for scheduling a task, wherein the method comprises: generating a scheduling relationship graph corresponding to a plurality of tasks according to a plurality of tasks to be executed and dependencies between the plurality of tasks; setting scheduling parameters of a task thread corresponding to each of the plurality of tasks according to the scheduling relationship graph, wherein the scheduling parameters are used to control the execution timing of the task thread corresponding to the scheduling parameters; submitting the task threads and scheduling parameters having a corresponding relationship to a thread pool, wherein the thread pool is used to execute each task thread according to the scheduling parameters corresponding to each task thread. The present application solves the technical problem of low scheduling efficiency of tasks in the related art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and in particular to a task scheduling method and device. Background Art

[0002] In the Java system, the ForkJoinPool and CompleteFuture frameworks are provided to implement multi-task scheduling. Both ForkJoinPool and CompleteFuture schedule tasks by writing code. They cannot handle scenarios where the number of tasks and task dependencies are dynamic, and have low flexibility. Even in scenarios where the number of tasks and task dependencies are relatively fixed, the process of writing code will waste a lot of time, affecting the efficiency of task scheduling.

[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0004] The present application provides a task scheduling method and device to at least solve the technical problem of low task scheduling efficiency in the related art.

[0005] According to one aspect of an embodiment of the present application, a task scheduling method is provided, including:

[0006] Generating a scheduling relationship graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationship between the multiple tasks;

[0007] Setting a scheduling parameter of a task thread corresponding to each of the multiple tasks according to the scheduling relationship diagram, wherein the scheduling parameter is used to control the execution timing of the task thread corresponding to the scheduling parameter;

[0008] Submitting task threads and scheduling parameters having corresponding relationships to a thread pool, wherein the thread pool is used to execute each task thread according to the scheduling parameters corresponding to each task thread.

[0009] Optionally, generating a scheduling relationship graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationship between the multiple tasks includes:

[0010] Generating a dependency graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationships between the multiple tasks;

[0011] The scheduling relationship graph is generated according to the dependency relationship graph.

[0012] Optionally, generating a dependency graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationships between the multiple tasks includes:

[0013] Traversing each task in the plurality of tasks as a first task node;

[0014] Acquire a task that depends on the first task node from the dependency relationship of the multiple tasks as a second task node;

[0015] An edge pointing from the second task node to the first task node is added as a dependency relationship between the first task node and the second task node to obtain the dependency relationship graph.

[0016] Optionally, traversing each task in the multiple tasks as the first task node includes: traversing each task in the multiple tasks as the first task; detecting whether the task node corresponding to the first task has been created; when detecting that the task node corresponding to the first task has not been created, creating the first task node; when detecting that the task node corresponding to the first task has been created, determining the created task node corresponding to the first task as the first task node;

[0017] Obtaining the task that depends on the first task node from the dependency relationships of the multiple tasks as the second task node includes: obtaining the second task that depends on the first task node from the dependency relationships of the multiple tasks; detecting whether the task node corresponding to the second task has been created; when it is detected that the task node corresponding to the second task has not been created, creating the second task node; when it is detected that the task node corresponding to the second task has been created, determining the created task node corresponding to the second task as the second task node.

[0018] Optionally, generating the scheduling relationship graph according to the dependency relationship graph includes:

[0019] Dividing the task nodes in the dependency graph into multiple layers, wherein the task nodes without pointing edges are located at the top layer of the multiple layers, and the other layers in the multiple layers except the top layer only have dependency relationships with the layers above the other layers;

[0020] Remove edges that span at least one level;

[0021] The edges between two adjacent layers are converted into edges from the dependent task node to the dependent task node as the scheduling relationship between the two task nodes, so as to obtain the scheduling relationship graph.

[0022] Optionally, setting the scheduling parameters of the task thread corresponding to each task according to the scheduling relationship diagram includes:

[0023] Acquire an in-degree value corresponding to each task from the scheduling relationship graph, wherein the in-degree value is used to indicate the number of edges pointing into the task node corresponding to each task, the task nodes in the scheduling relationship graph correspond one-to-one to the multiple tasks, and the edges connecting the task nodes in the scheduling relationship graph point from the dependent task node to the dependent task node;

[0024] The in-degree value is determined as a scheduling parameter of a task thread corresponding to each task.

[0025] Optionally, after submitting the task threads and scheduling parameters having a corresponding relationship to the thread pool, the method further includes:

[0026] Detecting whether the scheduling parameter corresponding to each task thread is a target value, wherein the scheduling parameter being the target value indicates that the corresponding task thread does not depend on other task threads, or that the task threads that the corresponding task thread depends on have all run to completion;

[0027] When it is detected that the scheduling parameter corresponding to the target task thread is the target value, obtaining a preceding node corresponding to the target task thread from the scheduling relationship graph;

[0028] When the predecessor node is obtained, the running result of the task thread corresponding to the predecessor node is input into the target task thread;

[0029] When the predecessor node is not obtained, or after the running result of the task thread corresponding to the predecessor node is input into the target task thread, the target task thread is run;

[0030] Obtaining the post-node corresponding to the target task thread from the scheduling relationship graph;

[0031] The scheduling parameters corresponding to the post-node are adjusted to indicate that the target task thread has completed execution.

[0032] According to another aspect of an embodiment of the present application, a task scheduling device is also provided, including:

[0033] A generation module, used to generate a scheduling relationship graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationship between the multiple tasks;

[0034] A setting module, used to set the scheduling parameters of the task thread corresponding to each task in the multiple tasks according to the scheduling relationship diagram, wherein the scheduling parameters are used to control the execution timing of the task thread corresponding to the scheduling parameters;

[0035] The submission module is used to submit task threads and scheduling parameters having a corresponding relationship to a thread pool, wherein the thread pool is used to execute each task thread according to the scheduling parameters corresponding to each task thread.

[0036] According to another aspect of an embodiment of the present application, a storage medium is further provided, which includes a stored program, and the above method is executed when the program is run.

[0037] According to another aspect of an embodiment of the present application, an electronic device is further provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the above method through the computer program.

[0038] In an embodiment of the present application, a scheduling relationship graph corresponding to multiple tasks is generated according to multiple tasks to be executed and the dependency relationship between the multiple tasks; scheduling parameters of the task thread corresponding to each task in the multiple tasks are set according to the scheduling relationship graph, wherein the scheduling parameters are used to control the execution timing of the task thread corresponding to the scheduling parameters; task threads and scheduling parameters having corresponding relationships are submitted to a thread pool, wherein the thread pool is used to execute each task thread according to the scheduling parameters corresponding to each task thread, and the influence of the dependency relationship between multiple tasks on the task scheduling process is reflected by generating a scheduling relationship graph corresponding to multiple tasks, and scheduling parameters are set for each task thread according to the generated scheduling relationship graph to control the execution timing of the corresponding task thread, and when submitting tasks to the thread pool, the task threads and scheduling parameters having corresponding relationships are submitted together, so that the thread pool can execute each task thread according to the scheduling parameters corresponding to each task thread, thereby achieving the purpose of flexibly scheduling tasks, thereby realizing the technical effect of improving the scheduling efficiency of tasks, and further solving the technical problem of low scheduling efficiency of tasks in related technologies. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0041] Figure 1 is a schematic diagram of a hardware environment of a task scheduling method according to an embodiment of the present application;

[0042] Figure 2is a flowchart of an optional task scheduling method according to an embodiment of the present application;

[0043] Figure 3 is a schematic diagram of an optional dependency graph according to an embodiment of the present application;

[0044] Figure 4 is a schematic diagram of an optional scheduling relationship diagram according to an embodiment of the present application;

[0045] Figure 5 is a schematic diagram of a task scheduling process according to an optional implementation mode of the present application;

[0046] Figure 6 is a schematic diagram of a task thread execution process according to an optional implementation mode of the present application;

[0047] Figure 7 is a schematic diagram of an optional task scheduling device according to an embodiment of the present application;

[0048] Figure 8 It is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0050] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0051] According to one aspect of an embodiment of the present application, a method embodiment for scheduling a task is provided.

[0052] Optionally, in this embodiment, the above task scheduling method can be applied to Figure 1 In the hardware environment composed of the terminal 101 and the server 103 shown in FIG. Figure 1 As shown, the server 103 is connected to the terminal 101 through a network, and can be used to provide services (such as game services, application services, etc.) for the terminal or the client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server 103. The above network includes but is not limited to: a wide area network, a metropolitan area network or a local area network, and the terminal 101 is not limited to a PC, a mobile phone, a tablet computer, etc. The scheduling method of the task of the embodiment of the present application can be executed by the server 103, or by the terminal 101, or by the server 103 and the terminal 101. Among them, the scheduling method of the task of the embodiment of the present application executed by the terminal 101 can also be executed by the client installed thereon.

[0053] Figure 2 is a flowchart of an optional task scheduling method according to an embodiment of the present application, such as Figure 2 As shown, the method may include the following steps:

[0054] Step S202, generating a scheduling relationship graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationship between the multiple tasks;

[0055] Step S204, setting a scheduling parameter of a task thread corresponding to each of the multiple tasks according to the scheduling relationship diagram, wherein the scheduling parameter is used to control the execution timing of the task thread corresponding to the scheduling parameter;

[0056] Step S206: submitting the task threads and scheduling parameters having a corresponding relationship to a thread pool, wherein the thread pool is used to execute each task thread according to the scheduling parameters corresponding to each task thread.

[0057] Through the above steps S202 to S206, a scheduling relationship diagram corresponding to multiple tasks is generated to reflect the influence of the dependency relationship between multiple tasks on the task scheduling process. Scheduling parameters are set for each task thread according to the generated scheduling relationship diagram to control the execution timing of the corresponding task thread. When submitting tasks to the thread pool, the task threads and scheduling parameters with corresponding relationships are submitted together, so that the thread pool can execute each task thread according to the scheduling parameters corresponding to each task thread, thereby achieving the purpose of flexible scheduling of tasks, thereby realizing the technical effect of improving the scheduling efficiency of tasks, and further solving the technical problem of low scheduling efficiency of tasks in related technologies.

[0058] Optionally, in this embodiment, the task scheduling method may be applied to, but not limited to, programs, tools, plug-ins, etc. with task scheduling functions. For example, a program or plug-in may be implemented to provide task scheduling services to the outside world through a RESTful API.

[0059] In the technical solution provided in step S202, the dependency relationship is used to represent the relationship between the initial parameters and the execution results between tasks. For example, there is a dependency relationship between task 1 and task 2: task 1 depends on task 2, or task 2 is dependent on task 1, which can mean that one or more initial parameters of task 1 are one or more execution results of task 2.

[0060] For example, the dependency relationship between multiple tasks can be presented in the form of a table. Multiple tasks include tasks A, B, C, and D. The dependency relationship between multiple tasks includes: task C depends on tasks A and B, and task D depends on tasks B and C. A table of task dependencies can be obtained as shown in Table 1.

[0061] Table 1

[0062] Task Name Task Dependencies A none B none C A,B D B,C

[0063] Optionally, in this embodiment, the scheduling relationship graph may be drawn in the form of, but not limited to, a DAG (Directed Acyclic Graph).

[0064] As an optional embodiment, the scheduling relationship graph corresponding to the multiple tasks may be generated in the following manner, but is not limited to:

[0065] S11, generating a dependency graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationships between the multiple tasks;

[0066] S12: Generate the scheduling relationship graph according to the dependency relationship graph.

[0067] Optionally, in this embodiment, the dependency relationships among multiple tasks may be first displayed through DAG to obtain a dependency graph, and then the dependency relationships displayed in the dependency graph may be converted into scheduling relationships among tasks, thereby generating a scheduling graph.

[0068] As an optional embodiment, the dependency graph may be generated in the following manner, but is not limited to:

[0069] S21, traversing each task in the multiple tasks as a first task node;

[0070] S22, acquiring a task that depends on the first task node from the dependency relationship of the multiple tasks as a second task node;

[0071] S23, adding an edge pointing from the second task node to the first task node as a dependency relationship between the first task node and the second task node, to obtain the dependency relationship graph.

[0072] Optionally, in this embodiment, each of the multiple tasks is added to the dependency graph as a task node, and the dependency relationship between tasks can be represented by, but is not limited to, directed connections between nodes (such as arrows).

[0073] For example: by traversing the tasks recorded in the above Table 1, you may first get task A and generate the A node corresponding to task A. Since task A has no dependent tasks, continue to traverse the next task and you may get task B and generate the B node corresponding to task B. Since task B has no dependent tasks, continue to traverse the next task and you may get task C and generate the C node corresponding to task C. Since task C depends on tasks A and B, first use node A as the second task node, add an edge from node C to node A, then use node B as the second task node, add an edge from node C to node B, and then continue to traverse the next task and get task D. Since task D depends on tasks B and C, first use node B as the second task node, add an edge from node D to node B, then use node C as the second task node, and add an edge from node D to node C. Figure 3 is a schematic diagram of an optional dependency graph according to an embodiment of the present application. A dependency graph is generated through the above dependency graph generation process, such as Figure 3 As shown, the solid arrows indicate that task C depends on task A and task B, and task D depends on task B and task C.

[0074] As an optional embodiment, traversing each task in the multiple tasks as a first task node includes:

[0075] S31, traversing each task in the plurality of tasks as a first task;

[0076] S32, detecting whether a task node corresponding to the first task has been created;

[0077] S33, when it is detected that the task node corresponding to the first task has not been created, creating the first task node;

[0078] S34: When it is detected that the task node corresponding to the first task has been created, determine the created task node corresponding to the first task as the first task node.

[0079] Optionally, in this embodiment, in the process of traversing each task among multiple tasks as the first task, it can be determined whether a new task node needs to be created by detecting the currently created task node. If the task node corresponding to the first task has been created, it is not necessary to create a new node. If the task node corresponding to the first task has not been created, a new node is created as the first task node, so that each first task has one and only one corresponding task node in the dependency graph.

[0080] As an optional embodiment, obtaining the task that depends on the first task node from the dependency relationship of the multiple tasks as the second task node includes:

[0081] S41, acquiring a second task that depends on the first task node from the dependency relationship of the multiple tasks;

[0082] S42, detecting whether a task node corresponding to the second task has been created;

[0083] S43, when it is detected that the task node corresponding to the second task has not been created, creating the second task node;

[0084] S44: When it is detected that the task node corresponding to the second task has been created, the task node corresponding to the created second task is determined as the second task node.

[0085] Optionally, in this embodiment, in the process of traversing the dependency relationship of the first task node, it can be determined whether a new task node needs to be created by detecting the currently created task node. If the task node corresponding to the second task has been created, it is not necessary to create a new node, and a dependency relationship can be directly added between the first task node and the second task node. If the task node corresponding to the second task has not been created, a new node is created as the second task node and then the dependency relationship between the nodes is added, so that each second task has one and only one corresponding task node in the dependency graph.

[0086] Optionally, in this embodiment, the detection process in the above traversal process can ensure that each of the multiple tasks has one and only one corresponding task node in the dependency graph, so that the display of the dependency graph is more concise and accurate.

[0087] As an optional embodiment, the scheduling relationship diagram may be generated in the following manner, but is not limited to:

[0088] S51, dividing the task nodes in the dependency graph into multiple layers, wherein the task nodes without pointing edges are located at the top layer of the multiple layers, and the other layers in the multiple layers except the top layer only have dependency relationships with layers above the other layers;

[0089] S52, delete the edges that span at least one layer;

[0090] S53, converting the edge between two adjacent layers into an edge from the dependent task node to the dependent task node as the scheduling relationship between the two task nodes, and obtaining the scheduling relationship graph.

[0091] Optionally, in this embodiment, the dependency relationship in the DAG graph is converted into a scheduling relationship, and the edges in the scheduling relationship graph represent the execution order between tasks.

[0092] Optionally, in this embodiment, since the upper task must have been executed when the lower task of two tasks connected by the edge spanning at least one layer is executed, the edge spanning at least one layer can be deleted and the scheduling relationship between the two tasks is not represented.

[0093] For example: Figure 4 is a schematic diagram of an optional scheduling relationship diagram according to an embodiment of the present application, such as Figure 4 As shown in the figure, node A, node B, node C and node D are divided into three layers, where node A and node B have no dependency relationship, so they can be regarded as the top layer, node C is in the second layer, and node D is in the third layer. The edge from node D to node B can be deleted because it spans a layer. The solid edge from node C to node A is converted to a dotted edge from node A to node C, the solid edge from node C to node B is converted to a dotted edge from node B to node C, and the solid edge from node D to node C is converted to a dotted edge from node C to node D.

[0094] In the above task execution process, Task A and Task B do not depend on other tasks and do not depend on each other, so A and B will be executed concurrently first. When Task A and Task B are completed, Task C starts to execute. Because Task D depends on Task C, Task D starts to execute after Task C is completed.

[0095] In the technical solution provided in step S204, the scheduling parameters may include but are not limited to: a CountDownLatch parameter, which is used to control the execution timing of the corresponding task thread.

[0096] As an optional embodiment, the scheduling parameters of each task thread may be set in the following manner, but not limited to:

[0097] S61, acquiring an in-degree value corresponding to each task from the scheduling relationship graph, wherein the in-degree value is used to indicate the number of edges pointing into the task node corresponding to each task, the task nodes in the scheduling relationship graph correspond one-to-one to the multiple tasks, and the edges connecting the task nodes in the scheduling relationship graph point from the dependent task node to the dependent task node;

[0098] S62: Determine the in-degree value as a scheduling parameter of the task thread corresponding to each task.

[0099] Optionally, in this embodiment, the in-degree value is used to indicate the number of edges pointing into the task node corresponding to each task, for example: Figure 4 As shown, the in-degree values ​​of node A and node B are both 0, the in-degree value of node C is 2, and the in-degree value of node D is 1.

[0100] In an optional implementation, a task scheduling process is provided. Figure 5 is a schematic diagram of a task scheduling process according to an optional implementation mode of the present application, such as Figure 5 As shown in the figure, when a task scheduling is requested, a DAG object is created, the program traverses all task information, and inserts tasks (denoted as M) into the DAG as nodes one by one. Then the dependent tasks of the task (denoted as N) are traversed, and the relationship between task M and task N is updated into the DAG as an edge. In this way, after traversing all tasks, a complete DAG view of all tasks is generated, and a dependency graph is obtained. The dependency relationship in the dependency graph is converted into a scheduling relationship, that is, the scheduling graph DAG is obtained.

[0101] Then traverse all nodes of the scheduling relationship graph DAG, set the node's in-degree value to the value of the node's CountDownLatch, and then submit all node tasks to the thread pool for execution.

[0102] In the technical solution provided in step S206, while submitting the task thread to the thread pool, the scheduling parameters corresponding to the task thread are also submitted to the thread pool. The thread pool can determine the execution time of each task thread according to the scheduling parameters corresponding to each task thread, thereby scheduling the execution of each task thread.

[0103] As an optional embodiment, after submitting the task threads and scheduling parameters having a corresponding relationship to the thread pool, the method further includes:

[0104] S71, detecting whether the scheduling parameter corresponding to each task thread is a target value, wherein the scheduling parameter being the target value indicates that the corresponding task thread does not depend on other task threads, or that the task threads that the corresponding task thread depends on have all run to completion;

[0105] S72, when it is detected that the scheduling parameter corresponding to the target task thread is the target value, obtaining a predecessor node corresponding to the target task thread from the scheduling relationship graph;

[0106] S73, when the predecessor node is obtained, inputting the running result of the task thread corresponding to the predecessor node into the target task thread;

[0107] S74, when the predecessor node is not obtained, or after the running result of the task thread corresponding to the predecessor node is input into the target task thread, running the target task thread;

[0108] S75, obtaining the post-node corresponding to the target task thread from the scheduling relationship graph;

[0109] S76, adjusting the scheduling parameters corresponding to the post-node to indicate that the target task thread has completed execution.

[0110] Optionally, in this embodiment, the scheduling parameter being the target value indicates that the corresponding task thread does not depend on other task threads, or that the task threads that the corresponding task thread depends on have all run to completion. By detecting the scheduling parameter, the timing of execution of each task thread can be determined. When the scheduling parameter of the task thread is the target value, it indicates that the task thread has the conditions for execution and can be executed.

[0111] Optionally, in this embodiment, the target value may be, but is not limited to, 0. That is, when each scheduling parameter counts down to 0, it is the execution time of the task thread corresponding to the scheduling parameter.

[0112] Optionally, in this embodiment, the predecessor node corresponding to the target task thread can be understood as the node of the task thread on which the target task thread depends, for example: Figure 4 As shown, the predecessor nodes of node C are node A and node B.

[0113] Optionally, in this embodiment, the post-node corresponding to the target task thread can be understood as a node of a task thread that depends on the execution result of the target task thread, such as: Figure 4 As shown, the subsequent node of node C is node D. The method of adjusting the scheduling parameter corresponding to the subsequent node may be, but is not limited to, reducing the scheduling parameter of the subsequent node by 1, which means that the target task thread has completed running.

[0114] In the above optional implementation manner, a task thread execution process is provided. Figure 6 is a schematic diagram of a task thread execution process according to an optional implementation mode of the present application, such as Figure 6As shown, the wait method of CountDownLatch is called to monitor the value of CountDownLatch of each task node, and determine whether the value of CountDownLatch is 0. If not, continue to wait. If yes, traverse all the predecessor nodes of the task, pass the execution result of the predecessor node as a parameter to the task, and after executing the task, traverse all the successor nodes of the task, and call the countDown method of the successor node to adjust the value of the CountDownLatch of the successor node.

[0115] For a task node without dependent tasks, the in-degree is 0, for example: Figure 4 For nodes A and B shown in the figure, the task thread will not be blocked by CountDownLatch and will be executed directly. When the task is completed, the CountDownLatch of the out-degree node (i.e. the subsequent node) will be reduced. Therefore, when tasks A and B are completed, the CountDownLatch value of C is reduced to 0, and the thread continues to execute, and so on.

[0116] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0117] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for an electronic device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0118] According to another aspect of an embodiment of the present application, a task scheduling device for implementing the above-mentioned task scheduling method is also provided. Figure 7 is a schematic diagram of an optional task scheduling device according to an embodiment of the present application, such as Figure 7 As shown, the device may include:

[0119] A generating module 72, configured to generate a scheduling relationship graph corresponding to the plurality of tasks according to the plurality of tasks to be executed and the dependency relationship between the plurality of tasks;

[0120] A setting module 74, configured to set a scheduling parameter of a task thread corresponding to each of the plurality of tasks according to the scheduling relationship diagram, wherein the scheduling parameter is used to control the execution timing of the task thread corresponding to the scheduling parameter;

[0121] The submission module 76 is used to submit the task threads and scheduling parameters having a corresponding relationship to the thread pool, wherein the thread pool is used to execute each task thread according to the scheduling parameters corresponding to each task thread.

[0122] It should be noted that the generation module 72 in this embodiment can be used to execute step S202 in the embodiment of the present application, the setting module 74 in this embodiment can be used to execute step S204 in the embodiment of the present application, and the submission module 76 in this embodiment can be used to execute step S206 in the embodiment of the present application.

[0123] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware.

[0124] Through the above module, by generating a scheduling relationship diagram corresponding to multiple tasks, the influence of the dependency relationship between multiple tasks on the task scheduling process is reflected, and scheduling parameters are set for each task thread according to the generated scheduling relationship diagram to control the execution timing of the corresponding task thread. When submitting tasks to the thread pool, the task threads and scheduling parameters with corresponding relationships are submitted together, so that the thread pool can execute each task thread according to the scheduling parameters corresponding to each task thread, thereby achieving the purpose of flexible scheduling of tasks, thereby realizing the technical effect of improving the scheduling efficiency of tasks, and further solving the technical problem of low scheduling efficiency of tasks in related technologies.

[0125] As an optional embodiment, the generating module includes:

[0126] A first generating unit, configured to generate a dependency graph corresponding to the plurality of tasks according to the plurality of tasks to be executed and the dependency relationships between the plurality of tasks;

[0127] The second generating unit is used to generate the scheduling relationship graph according to the dependency relationship graph.

[0128] As an optional embodiment, the first generating unit is used for:

[0129] Traversing each task in the plurality of tasks as a first task node;

[0130] Acquire a task that depends on the first task node from the dependency relationship of the multiple tasks as a second task node;

[0131] An edge pointing from the second task node to the first task node is added as a dependency relationship between the first task node and the second task node to obtain the dependency relationship graph.

[0132] As an optional embodiment, the first generating unit is used for:

[0133] Traversing each task in the plurality of tasks as a first task; detecting whether a task node corresponding to the first task has been created; when detecting that the task node corresponding to the first task has not been created, creating the first task node; when detecting that the task node corresponding to the first task has been created, determining the created task node corresponding to the first task as the first task node;

[0134] Obtain a second task that depends on the first task node from the dependency relationships of the multiple tasks; detect whether a task node corresponding to the second task has been created; when it is detected that the task node corresponding to the second task has not been created, create the second task node; when it is detected that the task node corresponding to the second task has been created, determine the created task node corresponding to the second task as the second task node.

[0135] As an optional embodiment, the second generating unit is used for:

[0136] Dividing the task nodes in the dependency graph into multiple layers, wherein the task nodes without pointing edges are located at the top layer of the multiple layers, and the other layers in the multiple layers except the top layer only have dependency relationships with the layers above the other layers;

[0137] Remove edges that span at least one level;

[0138] The edges between two adjacent layers are converted into edges from the dependent task node to the dependent task node as the scheduling relationship between the two task nodes, so as to obtain the scheduling relationship graph.

[0139] As an optional embodiment, the setting module includes:

[0140] an acquisition unit, configured to acquire an in-degree value corresponding to each task from the scheduling relationship graph, wherein the in-degree value is used to indicate the number of edges pointing into the task node corresponding to each task, the task nodes in the scheduling relationship graph correspond one-to-one to the multiple tasks, and the edges connecting the task nodes in the scheduling relationship graph point from the dependent task node to the dependent task node;

[0141] A determining unit is used to determine the in-degree value as a scheduling parameter of the task thread corresponding to each task.

[0142] As an optional embodiment, the device further includes:

[0143] A detection module, configured to detect whether the scheduling parameter corresponding to each task thread is a target value after submitting the task threads and scheduling parameters having a corresponding relationship to the thread pool, wherein the scheduling parameter being the target value indicates that the corresponding task thread does not depend on other task threads, or that the task threads on which the corresponding task thread depends have all run to completion;

[0144] A first acquisition module is used to acquire a preceding node corresponding to the target task thread from the scheduling relationship graph when detecting that the scheduling parameter corresponding to the target task thread is the target value;

[0145] An input module, used for inputting the running result of the task thread corresponding to the predecessor node into the target task thread when the predecessor node is acquired;

[0146] A running module, used to run the target task thread when the predecessor node is not obtained, or after the running result of the task thread corresponding to the predecessor node is input into the target task thread;

[0147] A second acquisition module is used to acquire the post-node corresponding to the target task thread from the scheduling relationship graph;

[0148] The adjustment module is used to adjust the scheduling parameters corresponding to the post-node to indicate that the target task thread has completed execution.

[0149] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware, wherein the hardware environment includes a network environment.

[0150] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned task scheduling method is also provided.

[0151] Figure 8 is a structural block diagram of an electronic device according to an embodiment of the present application, such as Figure 8 As shown, the electronic device may include: one or more (only one is shown in the figure) processors 801, a memory 803, and a transmission device 805, such as Figure 8 As shown, the electronic device may further include an input / output device 807 .

[0152] Among them, the memory 803 can be used to store software programs and modules, such as the program instructions / modules corresponding to the scheduling method and device of the tasks in the embodiment of the present application. The processor 801 executes various functional applications and data processing by running the software programs and modules stored in the memory 803, that is, realizing the scheduling method of the above-mentioned tasks. The memory 803 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 803 may further include a memory remotely arranged relative to the processor 801, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0153] The above-mentioned transmission device 805 is used to receive or send data via a network, and can also be used for data transmission between a processor and a memory. Specific examples of the above-mentioned network may include a wired network and a wireless network. In one example, the transmission device 805 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 805 is a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly.

[0154] Specifically, the memory 803 is used to store application programs.

[0155] The processor 801 may call the application stored in the memory 803 through the transmission device 805 to perform the following steps:

[0156] Generating a scheduling relationship graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationship between the multiple tasks;

[0157] Setting a scheduling parameter of a task thread corresponding to each of the multiple tasks according to the scheduling relationship diagram, wherein the scheduling parameter is used to control the execution timing of the task thread corresponding to the scheduling parameter;

[0158] Submitting task threads and scheduling parameters having corresponding relationships to a thread pool, wherein the thread pool is used to execute each task thread according to the scheduling parameters corresponding to each task thread.

[0159] By adopting the embodiment of the present application, a scheme for scheduling tasks is provided. The influence of the dependency relationship between multiple tasks on the task scheduling process is reflected by generating a scheduling relationship graph corresponding to multiple tasks, and scheduling parameters are set for each task thread according to the generated scheduling relationship graph to control the execution timing of the corresponding task thread. When submitting tasks to the thread pool, the task threads and scheduling parameters with corresponding relationships are submitted together, so that the thread pool can execute each task thread according to the scheduling parameters corresponding to each task thread, thereby achieving the purpose of flexible scheduling tasks, thereby achieving the technical effect of improving the scheduling efficiency of tasks, and further solving the technical problem of low scheduling efficiency of tasks in related technologies.

[0160] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.

[0161] It can be understood by those skilled in the art that Figure 8 The structure shown is for illustration only, and the electronic device may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (MID), a PAD, or other electronic devices. Figure 8 The structure of the electronic device is not limited. Figure 8 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 8 Different configurations are shown.

[0162] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the electronic device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0163] The embodiment of the present application further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to execute the program code of the task scheduling method.

[0164] Optionally, in this embodiment, the storage medium may be located on at least one network device among a plurality of network devices in the network shown in the above embodiment.

[0165] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps:

[0166] Generating a scheduling relationship graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationship between the multiple tasks;

[0167] Setting a scheduling parameter of a task thread corresponding to each of the multiple tasks according to the scheduling relationship diagram, wherein the scheduling parameter is used to control the execution timing of the task thread corresponding to the scheduling parameter;

[0168] Submitting task threads and scheduling parameters having corresponding relationships to a thread pool, wherein the thread pool is used to execute each task thread according to the scheduling parameters corresponding to each task thread.

[0169] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.

[0170] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.

[0171] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0172] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.

[0173] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0174] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0175] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0176] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0177] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A task scheduling method, characterized in that: include: Generating a scheduling relationship graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationship between the multiple tasks; The method further comprises: obtaining an in-degree value corresponding to each task from the scheduling relationship graph, wherein the in-degree value is used to indicate the number of edges pointing into the task node corresponding to each task, the task nodes in the scheduling relationship graph correspond to the multiple tasks one-to-one, and the edges connecting the task nodes in the scheduling relationship graph point from the dependent task node to the dependent task node; determining the in-degree value as a scheduling parameter of the task thread corresponding to each task, wherein the scheduling parameter is used to control the execution timing of the task thread corresponding to the scheduling parameter; Submitting task threads and scheduling parameters having corresponding relationships to a thread pool, wherein the thread pool is used to execute each task thread according to the scheduling parameters corresponding to each task thread.

2. The method according to claim 1, characterized in that Generating a scheduling relationship graph corresponding to the plurality of tasks according to the plurality of tasks to be executed and the dependency relationship between the plurality of tasks includes: Generating a dependency graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationships between the multiple tasks; The scheduling relationship graph is generated according to the dependency relationship graph.

3. The method according to claim 2, characterized in that Generating a dependency graph corresponding to the plurality of tasks according to the plurality of tasks to be executed and the dependency relationships between the plurality of tasks includes: Traversing each task in the plurality of tasks as a first task node; Acquire a task that depends on the first task node from the dependency relationship of the multiple tasks as a second task node; An edge pointing from the second task node to the first task node is added as a dependency relationship between the first task node and the second task node to obtain the dependency relationship graph.

4. The method according to claim 3, characterized in that: Traversing each task in the plurality of tasks as a first task node comprises: traversing each task in the plurality of tasks as a first task; detecting whether a task node corresponding to the first task has been created; when detecting that the task node corresponding to the first task has not been created, creating the first task node; when detecting that the task node corresponding to the first task has been created, determining the created task node corresponding to the first task as the first task node; Obtaining the task that depends on the first task node from the dependency relationships of the multiple tasks as the second task node includes: obtaining the second task that depends on the first task node from the dependency relationships of the multiple tasks; detecting whether the task node corresponding to the second task has been created; when it is detected that the task node corresponding to the second task has not been created, creating the second task node; when it is detected that the task node corresponding to the second task has been created, determining the created task node corresponding to the second task as the second task node.

5. The method according to claim 3, characterized in that: Generating the scheduling relationship graph according to the dependency relationship graph includes: Dividing the task nodes in the dependency graph into multiple layers, wherein the task nodes without pointing edges are located at the top layer of the multiple layers, and the other layers in the multiple layers except the top layer only have dependency relationships with the layers above the other layers; Remove edges that span at least one level; The edges between two adjacent layers are converted into edges from the dependent task node to the dependent task node as the scheduling relationship between the two task nodes, so as to obtain the scheduling relationship graph.

6. The method according to claim 1, characterized in that After submitting the task threads and scheduling parameters having a corresponding relationship to the thread pool, the method further includes: Detecting whether the scheduling parameter corresponding to each task thread is a target value, wherein the scheduling parameter being the target value indicates that the corresponding task thread does not depend on other task threads, or that the task threads that the corresponding task thread depends on have all run to completion; When it is detected that the scheduling parameter corresponding to the target task thread is the target value, obtaining a preceding node corresponding to the target task thread from the scheduling relationship graph; When the predecessor node is obtained, the running result of the task thread corresponding to the predecessor node is input into the target task thread; When the predecessor node is not obtained, or after the running result of the task thread corresponding to the predecessor node is input into the target task thread, the target task thread is run; Obtaining the post-node corresponding to the target task thread from the scheduling relationship graph; The scheduling parameters corresponding to the post-node are adjusted to indicate that the target task thread has completed execution.

7. A task scheduling device, characterized in that: include: A generation module, used to generate a scheduling relationship graph corresponding to the multiple tasks according to the multiple tasks to be executed and the dependency relationship between the multiple tasks; A setting module is used to set the scheduling parameters of the task thread corresponding to each task in the multiple tasks according to the scheduling relationship graph, including: obtaining the in-degree value corresponding to each task from the scheduling relationship graph, the in-degree value is used to indicate the number of edges pointing into the task node corresponding to each task, the task nodes in the scheduling relationship graph correspond to the multiple tasks one-to-one, and the edges connecting the task nodes in the scheduling relationship graph point from the dependent task node to the dependent task node; determining the in-degree value as the scheduling parameter of the task thread corresponding to each task, the scheduling parameter is used to control the execution timing of the task thread corresponding to the scheduling parameter; The submission module is used to submit task threads and scheduling parameters having a corresponding relationship to a thread pool, wherein the thread pool is used to execute each task thread according to the scheduling parameters corresponding to each task thread.

8. A storage medium, characterized in that: The storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 6 when executed.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: The processor executes the method described in any one of claims 1 to 6 through the computer program.