Task scheduling method and device, storage medium and electronic equipment
By constructing a task dependency graph and using cache and execution dual-track queues, the problem that dependencies are not considered in task scheduling in the existing technology is solved, the accuracy and flexibility of task scheduling are improved, and it is suitable for complex and changing scheduling requirements. .
Patent Information
- Application Number
- CN202410597666.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-14
- Publication Date
- 2024-08-23
AI Technical Summary
Existing task scheduling methods do not fully consider the dependencies between tasks, resulting in inflexible and low accuracy of the scheduling process. Especially in the face of complex and changing scheduling requirements, the applicability and effectiveness are limited.
By building a task dependency graph, we determine the dependencies between tasks, optimize the order of tasks in the cache queue and execution queue, ensure that downstream tasks are executed after upstream tasks are completed, and use cache and execution dual-rail queues to achieve concurrent task scheduling.
It improves the accuracy and flexibility of task scheduling, meets the needs of concurrent task scheduling, and avoids the problem of inflexible scheduling caused by failure to consider dependencies.
Smart Images

Figure CN118535301A
Abstract
Description
Technical Field
[0001] The present application relates to the fields of data processing technology, financial technology and other related technical fields, and specifically to a task scheduling method and device, a storage medium and an electronic device. Background Art
[0002] In task scheduling environments such as real-time and batch processing, the scheduling between tasks is usually subject to dependency constraints, that is, subsequent tasks depend on the execution results and output parameters of previous tasks. However, the currently widely used task scheduling methods are often relatively isolated and do not fully consider the dependencies between tasks, resulting in an inflexible scheduling process. This also limits the applicability and effectiveness of scheduling methods when facing more complex and changing scheduling requirements.
[0003] Currently, no effective solution has been proposed to solve the problem that the task scheduling in related technologies does not consider the dependencies between tasks, resulting in a relatively low accuracy of task scheduling. Summary of the invention
[0004] The main purpose of the present application is to provide a task scheduling method and device, a storage medium and an electronic device to solve the problem in the related art that the task scheduling does not consider the dependencies between tasks, resulting in a relatively low accuracy of task scheduling.
[0005] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a task scheduling method is provided. The method comprises: obtaining multiple tasks and writing the multiple tasks into a cache queue; determining a target task from the multiple tasks in the cache queue according to a task dependency graph corresponding to the multiple tasks, wherein the task dependency graph is determined according to the dependency relationship between the multiple tasks; writing the target task into a target execution queue, and executing the target task when the order corresponding to the target task is a preset value to obtain a target processing result.
[0006] Furthermore, before determining the target task from the multiple tasks in the cache queue based on the task dependency graph corresponding to the multiple tasks, the method also includes: determining nodes based on the multiple tasks; determining edges based on the dependency relationships between the multiple tasks; and constructing the task dependency graph based on the nodes and the edges.
[0007] Furthermore, according to the task dependency graph corresponding to the multiple tasks, determining the target task from the multiple tasks in the cache queue includes: obtaining the first task in the cache queue, wherein the order of the first task in the cache queue is less than the order of the remaining tasks in the cache queue; according to the task dependency graph, determining whether there is an upstream task for the first task; if there is an upstream task for the first task, determining whether the upstream task of the first task has been executed to obtain a first judgment result; if the first judgment result indicates that the upstream task of the first task has been executed, determining the first task as the target task.
[0008] Furthermore, after determining whether the upstream task of the first task has been executed and obtaining a first judgment result, the method also includes: if the first judgment result indicates that there is a task in the upstream task of the first task that has not been executed, then obtaining task information of the unexecuted task in the upstream task, wherein the task information includes at least: the task name and estimated execution time of the unexecuted task; after the estimated execution time, re-determining whether the unexecuted task is currently executed and obtaining a second judgment result; if the second judgment result indicates that the unexecuted task is currently executed, then determining the first task as the target task.
[0009] Furthermore, before writing the target task into the target execution queue and executing the target task when the order corresponding to the target task is a preset value to obtain the target processing result, the method also includes: obtaining multiple candidate execution queues and the current number of tasks to be executed in each candidate execution queue; and determining the target execution queue from the multiple candidate execution queues based on the current number of tasks to be executed in each candidate execution queue.
[0010] Furthermore, executing the target task and obtaining the target processing result includes: determining the upstream task of the target task based on the task dependency graph; after the upstream task is executed, obtaining the execution parameters of the upstream task of the target task, and sending the execution parameters to the target task; executing the target task based on the execution parameters to obtain the target processing result.
[0011] Furthermore, obtaining multiple tasks and writing the multiple tasks into the cache queue includes: obtaining a target data format of the cache queue; converting the format of each task according to the target data format to obtain multiple converted tasks; and writing the multiple converted tasks into the cache queue.
[0012] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a task scheduling device is provided. The device includes: a writing unit, used to obtain multiple tasks and write the multiple tasks into a cache queue; a first determining unit, used to determine a target task from multiple tasks in the cache queue according to a task dependency graph corresponding to the multiple tasks, wherein the task dependency graph is determined according to the dependency relationship between the multiple tasks; an executing unit, used to write the target task into a target execution queue, and when the order corresponding to the target task is a preset value, execute the target task to obtain a target processing result.
[0013] Furthermore, the device also includes: a second determination unit, used to determine nodes based on the multiple tasks before determining the target task from the multiple tasks in the cache queue based on the task dependency graph corresponding to the multiple tasks; a third determination unit, used to determine edges based on the dependency relationship between the multiple tasks; and a construction unit, used to construct the task dependency graph based on the nodes and the edges.
[0014] Furthermore, the first determination unit includes: a first acquisition module, used to acquire the first task in the cache queue, wherein the order of the first task in the cache queue is less than the order of the remaining tasks in the cache queue; a first determination module, used to determine whether the first task has an upstream task based on the task dependency graph; a judgment module, used to judge whether the upstream task of the first task has been executed if the first task has an upstream task, and obtain a first judgment result; a second determination module, used to determine the first task as the target task if the first judgment result indicates that the upstream task of the first task has been executed.
[0015] Furthermore, the device also includes: a first acquisition unit, which is used to determine whether the upstream task of the first task has been executed and obtain a first judgment result. If the first judgment result indicates that there is a task in the upstream task of the first task that has not been executed, then obtain the task information of the unexecuted task in the upstream task, wherein the task information at least includes: the task name and estimated execution time of the unexecuted task; a judgment unit, which is used to re-determine whether the unexecuted task is currently executed after the estimated execution time, and obtain a second judgment result; and a fourth determination unit, which is used to determine the first task as the target task if the second judgment result indicates that the unexecuted task is currently executed.
[0016] Furthermore, the device also includes: a second acquisition unit, used to acquire multiple candidate execution queues and the current number of tasks to be executed in each candidate execution queue before writing the target task into the target execution queue and executing the target task when the order corresponding to the target task is a preset value and obtaining the target processing result; and a fifth determination unit, used to determine the target execution queue from the multiple candidate execution queues based on the current number of tasks to be executed in each candidate execution queue.
[0017] Furthermore, the execution unit includes: a third determination module, used to determine the upstream task of the target task based on the task dependency graph; a sending module, used to obtain the execution parameters of the upstream task of the target task after the upstream task is executed, and send the execution parameters to the target task; an execution module, used to execute the target task based on the execution parameters to obtain the target processing result.
[0018] Furthermore, the writing unit includes: a second acquisition module, used to obtain the target data format of the cache queue; a conversion module, used to convert the format of each task according to the target data format to obtain multiple converted tasks; and a writing module, used to write the multiple converted tasks into the cache queue.
[0019] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a computer-readable storage medium is provided, wherein the storage medium stores a program, wherein when the program is running, the device where the storage medium is located is controlled to execute any one of the task scheduling methods described above.
[0020] In order to achieve the above-mentioned purpose, according to another aspect of the present application, an electronic device is further provided, the electronic device includes one or more processors and a memory, and the memory is used to store the task scheduling method implemented by one or more processors as described above.
[0021] Through this application, the following steps are adopted: obtaining multiple tasks and writing the multiple tasks into a cache queue; determining a target task from multiple tasks in the cache queue according to a task dependency graph corresponding to the multiple tasks, wherein the task dependency graph is determined according to the dependency relationship between the multiple tasks; writing the target task into the target execution queue, and executing the target task when the order corresponding to the target task is a preset value, and obtaining a target processing result. Through this application, the problem that the task scheduling in the related art does not consider the dependency relationship between tasks, resulting in a relatively low accuracy rate of task scheduling is solved. In this scheme, firstly, multiple tasks to be scheduled are written into the cache queue. Then, the task dependency graph is used to determine whether the tasks in the cache queue meet the dependency relationship, and the tasks that meet the dependency relationship are determined as target tasks, and written into the execution queue. Finally, the target task at the head of the execution queue is executed to obtain the target processing result. The task dependency graph can be used to determine the dependency relationship of multiple tasks in the cache queue, and chain transfer of parameters between tasks can be realized. At the same time, the use of caching and execution dual-track queues meets the needs of concurrent task scheduling, avoiding the inflexible scheduling problems caused by the traditional method of task scheduling not considering the dependencies between tasks, thereby achieving the effect of improving the accuracy of task scheduling. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0023] Figure 1 is a flowchart of a task scheduling method provided according to an embodiment of the present application;
[0024] Figure 2 is a schematic diagram of a task scheduling method provided according to an embodiment of the present application;
[0025] Figure 3 is a schematic diagram of a task scheduling device provided according to an embodiment of the present application;
[0026] Figure 4 is a schematic diagram of an electronic device provided according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0028] 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.
[0029] 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 sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. 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.
[0030] It should be noted that the relevant information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties. For example, an interface is set between this system and the relevant user or organization. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain relevant information after receiving the consent information fed back by the aforementioned user or organization.
[0031] The present invention is described below in conjunction with preferred implementation steps. Figure 1 is a flowchart of a task scheduling method provided according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0032] Step S101, obtaining multiple tasks, and writing the multiple tasks into a cache queue.
[0033] Optionally, multiple tasks to be scheduled are obtained from the task source, and then the corresponding API tools are used to write the multiple tasks to be scheduled into the cache queue. Different queue services have different API tools and writing methods, and the corresponding method can be called according to the specific queue service used.
[0034] Step S102 , determining a target task from the multiple tasks in the cache queue according to a task dependency graph corresponding to the multiple tasks, wherein the task dependency graph is determined according to dependency relationships between the multiple tasks.
[0035] Optionally, it is determined through the task dependency graph whether the tasks in the cache queue satisfy the dependency relationship. If the dependency relationship is satisfied, the task is determined as the target task; otherwise, the task is determined as the target task after the dependency relationship is satisfied.
[0036] It should be noted that the task dependency graph is constructed based on the dependency relationship between tasks. The task dependency graph is a directed graph, where nodes represent tasks and edges represent the dependency relationship between tasks. If task A depends on task B, there is an edge from node B to node A in the graph. During task scheduling and execution, task A can only be executed after task B has been completed.
[0037] Step S103, writing the target task into the target execution queue, and executing the target task when the order corresponding to the target task is a preset value to obtain the target processing result.
[0038] Optionally, the target tasks are written into the execution queue in a certain order, and when the target task is at the head of the execution queue, the target task is executed to obtain a target processing result.
[0039] It should be noted that the execution queue can be composed of an array + queue. The length of the array is determined according to the number of CPU cores of the server hardware, etc., and is used to adapt the concurrency of the scheduling execution. When the concurrency is 1, the array length is 1, and the execution queue is a serial first-in-first-out (FIFO) queue. When the target task is written to the target execution queue, it is placed as evenly as possible in the queue where each element of the array is located according to the load balancing algorithm. The queue only exposes the first task and the last task to the outside world, and provides dequeueing and enqueuing services. The entire scheduling queue is transparent to the caller, which enhances the security of the scheduling process to a certain extent.
[0040] In summary, multiple tasks to be scheduled are first written into the cache queue. Then, the task dependency graph is used to determine whether the tasks in the cache queue satisfy the dependency relationship, and the tasks that satisfy the dependency relationship are determined as target tasks, and written into the execution queue. Finally, the target task at the head of the execution queue is executed to obtain the target processing result. The task dependency graph can be used to determine the dependency relationship of multiple tasks in the cache queue, and the chain transfer of parameters between tasks can be realized. At the same time, the dual-track queue method of cache and execution is used to meet the needs of concurrent task scheduling, avoiding the problems of inflexible scheduling caused by the task scheduling not considering the dependency relationship between tasks in the traditional method, thereby achieving the effect of improving the accuracy of task scheduling.
[0041] Optionally, in the task scheduling method provided in an embodiment of the present application, before determining the target task from multiple tasks in the cache queue based on the task dependency graph corresponding to the multiple tasks, the method also includes: determining nodes based on the multiple tasks; determining edges based on the dependency relationship between the multiple tasks; and constructing a task dependency graph based on the nodes and edges.
[0042] In an optional embodiment, all tasks are identified and listed, and each task is treated as a node in the task dependency graph. Then, a unique identifier is defined for each task node, and detailed information about the task is collected, such as: input parameters, output results, execution conditions, resource requirements, etc. of the task. At the same time, the dependencies between tasks are analyzed, and these dependencies may include: sequence dependency, data dependency, and resource dependency, etc. According to the dependencies between tasks, edges are drawn between corresponding task nodes, and the direction of the edge indicates the direction of dependency, that is, from the upstream task to the downstream task. Finally, check whether there is a circular dependency in the task dependency graph that may cause deadlock or fail to complete task scheduling. If there is no circular dependency that forms a closed loop in the task sequence, the task dependency graph is topologically sorted to determine a feasible execution order of the tasks, and at the same time identify tasks that can be executed in parallel without violating the dependencies to improve scheduling efficiency.
[0043] It should be noted that sequential dependency means that one task can only start after another task is completed; data dependency means that one task needs to use the output of another task as input; resource dependency means that multiple tasks may require the same resources, such as computing resources or I / O devices.
[0044] By constructing a task dependency graph, we can accurately and quickly determine whether the tasks in the cache queue meet the dependency relationship, which facilitates the subsequent scheduling of tasks.
[0045] Optionally, in the task scheduling method provided in the embodiment of the present application, determining the target task from the multiple tasks in the cache queue according to the task dependency graph corresponding to the multiple tasks includes: obtaining the first task in the cache queue, wherein the order of the first task in the cache queue is less than the order of the remaining tasks in the cache queue; determining whether there is an upstream task for the first task according to the task dependency graph; if there is an upstream task for the first task, determining whether the upstream task of the first task has been executed to obtain a first judgment result; if the first judgment result indicates that the upstream task of the first task has been executed, determining the first task as the target task.
[0046] In an optional embodiment, the first task at the head of the cache queue is obtained, and the task dependency graph is traversed by a dependency checker to perform a dependency check on the first task to find out whether there are other tasks that depend on the first task. If the first task has an upstream task, it is determined whether the upstream task has been executed. If all the upstream tasks of the first task have been executed, the task is determined as the target task.
[0047] It should be noted that the dependency checker continuously checks the dependency of the task at the head of the cache queue. When the task satisfies the dependency, the dequeue operation is performed and the next task is checked.
[0048] Through the task dependency graph and dependency checker, the dependency check of multiple tasks in the cache queue can be quickly performed to accurately determine the target task.
[0049] Optionally, in the task scheduling method provided in the embodiment of the present application, after determining whether the upstream task of the first task has been executed and obtaining a first judgment result, the method further includes: if the first judgment result indicates that there is a task in the upstream task of the first task that has not been executed, then obtaining the task information of the unexecuted task in the upstream task, wherein the task information includes at least: the task name and estimated execution time of the unexecuted task; after the estimated execution time, re-determining whether the unexecuted task is currently executed to obtain a second judgment result; if the second judgment result indicates that the unexecuted task is currently executed, then determining the first task as the target task.
[0050] In an optional embodiment, if there is a task that has not been executed in the upstream tasks of the first task, the task name and estimated execution time of the unexecuted task in the upstream task are obtained. After the estimated execution time, recheck whether the unexecuted task in the upstream task has been executed. If the unexecuted task in the upstream task has been executed, the first task is removed from the cache queue and determined as the target task; if the unexecuted task has not been executed, further scheduling decisions are required, such as re-evaluating the estimated execution time or considering exception handling.
[0051] By obtaining the task information of unexecuted tasks, you can ensure that the task is executed after all upstream tasks are completed, thereby avoiding execution errors caused by unsatisfied dependencies.
[0052] Optionally, in the task scheduling method provided in the embodiment of the present application, before writing the target task into the target execution queue and executing the target task when the order corresponding to the target task is a preset value to obtain the target processing result, the method also includes: obtaining multiple candidate execution queues and the current number of tasks to be executed in each candidate execution queue; determining the target execution queue from the multiple candidate execution queues based on the current number of tasks to be executed in each candidate execution queue.
[0053] In an optional embodiment, all available candidate execution queues in the system are first identified, and the status of each candidate execution queue, including the current number of tasks to be executed, is monitored in real time through the length of the queue, task count or other methods. Through the load balancing algorithm, the queue with the least number of tasks to be executed is selected, i.e., the target execution queue, to avoid situations such as some queues being overloaded while other queues are idle. At the same time, the status of the target execution queue is updated in the system, including: changes in the number of tasks and any related metadata.
[0054] By monitoring the candidate execution queues, multi-task scheduling can be effectively managed, resource utilization can be optimized, and the overall performance of the system can be improved.
[0055] Optionally, in the task scheduling method provided in the embodiment of the present application, executing the target task and obtaining the target processing result includes: determining the upstream task of the target task based on the task dependency graph; after the upstream task is executed, obtaining the execution parameters of the upstream task of the target task, and sending the execution parameters to the target task; executing the target task based on the execution parameters to obtain the target processing result.
[0056] In an optional embodiment, the upstream task of the target task is identified from the task dependency graph, the output parameters or results of the upstream task, i.e., the execution parameters, are collected, and the collected execution parameters are verified to ensure that the input requirements of the target task are met. After the verification is passed, the collected execution parameters are passed to the target task, including: writing the parameters to a file, sending them to a specific server, or directly passing them to the execution environment of the task. The target task is executed according to the received execution parameters.
[0057] It should be noted that errors or abnormal situations may occur during the execution of the target task, such as parameter errors, execution failure, etc. In response to the above situations, the compensation method is called, in which the unsubmitted tasks are rolled back according to the task granularity; for the submitted tasks, the anti-transaction operation is performed.
[0058] By obtaining the execution parameters of the upstream task, the target task can be executed quickly, and the target processing result can be accurately obtained.
[0059] Optionally, in the task scheduling method provided in an embodiment of the present application, obtaining multiple tasks and writing the multiple tasks into a cache queue includes: obtaining a target data format of the cache queue; converting the format of each task according to the target data format to obtain multiple converted tasks; and writing the multiple converted tasks into the cache queue.
[0060] In an optional embodiment, the target data format required by the cache queue is obtained, including but not limited to: JSON, XML, CSV, binary format or custom format, and also includes: field requirements, data types and structures, etc. Check the task data in the current cache queue to determine whether they conform to the target data format. For tasks that do not conform to the target data format, use the format conversion function to convert the task data from its current format to the target data format, encapsulate the converted task data as an instance or object of the target data format, and write it to the cache queue for subsequent processing.
[0061] The target data format ensures that all task data are stored in the cache queue in a unified format, which facilitates subsequent task scheduling and data processing.
[0062] It should be noted that Figure 2 Schematic diagram of a task scheduling method provided according to an embodiment of the present application. Figure 2 As shown, first, multiple tasks are obtained and written into the cache queue. Then, a dependency check is performed on the first task at the head of the cache queue through the task dependency graph and the dependency checker to determine whether the upstream task of the first task has been executed: if the upstream task of the first task has been executed, the first task is determined as the target task; if there is a task that has not been executed in the upstream task of the first task, the task information of the unexecuted task in the upstream task is obtained, and after the estimated execution time, it is re-determined whether the unexecuted task has been executed. Finally, the target task is written into the target execution queue, and the execution parameters of the upstream task of the target task are obtained. The execution parameters of the upstream task are used to execute the target task at the head of the target execution queue to obtain the target processing result.
[0063] The task scheduling method provided by the embodiment of the present application obtains multiple tasks and writes the multiple tasks into a cache queue; determines the target task from the multiple tasks in the cache queue according to the task dependency graph corresponding to the multiple tasks, wherein the task dependency graph is determined according to the dependency relationship between the multiple tasks; writes the target task into the target execution queue, and executes the target task when the order corresponding to the target task is a preset value, and obtains the target processing result, which solves the problem that the task scheduling in the related art does not consider the dependency relationship between the tasks, resulting in a relatively low accuracy of task scheduling. In summary, in this scheme, firstly, multiple tasks to be scheduled are written into the cache queue. Then, the task dependency graph is used to determine whether the tasks in the cache queue meet the dependency relationship, and the task that meets the dependency relationship is determined as the target task, and it is written into the execution queue. Finally, the target task at the head of the execution queue is executed to obtain the target processing result. The task dependency graph can be used to determine the dependency relationship of multiple tasks in the cache queue, and the chain transfer of parameters between tasks can be realized. At the same time, the use of caching and execution dual-track queues meets the needs of concurrent task scheduling, avoiding the inflexible scheduling problems caused by the traditional method of task scheduling not considering the dependencies between tasks, thereby achieving the effect of improving the accuracy of task scheduling.
[0064] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0065] The embodiment of the present application also provides a task scheduling device. It should be noted that the task scheduling device of the embodiment of the present application can be used to execute the task scheduling method provided by the embodiment of the present application. The task scheduling device provided by the embodiment of the present application is introduced below.
[0066] Figure 3 Schematic diagram of a task scheduling device according to an embodiment of the present application. Figure 3 As shown, the device includes: a writing unit 301, a first determining unit 302, and an executing unit 303.
[0067] A writing unit 301 is used to obtain multiple tasks and write the multiple tasks into a cache queue;
[0068] A first determining unit 302 is used to determine a target task from a plurality of tasks in a cache queue according to a task dependency graph corresponding to the plurality of tasks, wherein the task dependency graph is determined according to dependency relationships between the plurality of tasks;
[0069] The execution unit 303 is used to write the target task into the target execution queue, and execute the target task when the order corresponding to the target task is a preset value to obtain the target processing result.
[0070] In the task scheduling device provided by the embodiment of the present application, the writing unit 301 obtains multiple tasks and writes the multiple tasks into the cache queue; the first determining unit 302 determines the target task from the multiple tasks in the cache queue according to the task dependency graph corresponding to the multiple tasks, wherein the task dependency graph is determined according to the dependency relationship between the multiple tasks; the executing unit 303 writes the target task into the target execution queue, and executes the target task when the order corresponding to the target task is a preset value, and obtains the target processing result, which solves the problem that the task scheduling in the related art does not consider the dependency relationship between the tasks, resulting in a relatively low accuracy of task scheduling. In this scheme, firstly, multiple tasks to be scheduled are written into the cache queue. Then, the task dependency graph is used to determine whether the tasks in the cache queue meet the dependency relationship, and the task that meets the dependency relationship is determined as the target task, and it is written into the execution queue. Finally, the target task at the head of the execution queue is executed to obtain the target processing result. The task dependency graph can be used to determine the dependency relationship of multiple tasks in the cache queue, and the chain transfer of parameters between tasks can be realized. At the same time, the use of caching and execution dual-track queues meets the needs of concurrent task scheduling, avoiding the inflexible scheduling problems caused by the traditional method of task scheduling not considering the dependencies between tasks, thereby achieving the effect of improving the accuracy of task scheduling.
[0071] Optionally, in the task scheduling device provided in the embodiment of the present application, the device also includes: a second determination unit, used to determine nodes based on multiple tasks before determining the target task from multiple tasks in the cache queue based on the task dependency graph corresponding to the multiple tasks; a third determination unit, used to determine edges based on the dependency relationship between the multiple tasks; and a construction unit, used to construct a task dependency graph based on nodes and edges.
[0072] Optionally, in the task scheduling device provided in the embodiment of the present application, the first determination unit includes: a first acquisition module, used to acquire the first task in the cache queue, wherein the order of the first task in the cache queue is less than the order of the remaining tasks in the cache queue; a first determination module, used to determine whether there is an upstream task for the first task based on the task dependency graph; a judgment module, used to judge whether the upstream task of the first task has been executed if there is an upstream task for the first task, and obtain a first judgment result; a second determination module, used to determine the first task as the target task if the first judgment result indicates that the upstream task of the first task has been executed.
[0073] Optionally, in the task scheduling device provided in the embodiment of the present application, the device also includes: a first acquisition unit, used to determine whether the upstream task of the first task has been executed, and after obtaining a first judgment result, if the first judgment result indicates that there is a task in the upstream task of the first task that has not been executed, then obtain the task information of the unexecuted task in the upstream task, wherein the task information includes at least: the task name and estimated execution time of the unexecuted task; a judgment unit, used to re-determine whether the unexecuted task is currently executed after the estimated execution time, and obtain a second judgment result; a fourth determination unit, used to determine the first task as the target task if the second judgment result indicates that the unexecuted task is currently executed.
[0074] Optionally, in the task scheduling device provided in the embodiment of the present application, the device also includes: a second acquisition unit, used to write the target task into the target execution queue and execute the target task when the order corresponding to the target task is a preset value, and before obtaining the target processing result, obtain multiple candidate execution queues and the current number of tasks to be executed in each candidate execution queue; a fifth determination unit, used to determine the target execution queue from multiple candidate execution queues based on the current number of tasks to be executed in each candidate execution queue.
[0075] Optionally, in the task scheduling device provided in the embodiment of the present application, the execution unit includes: a third determination module, used to determine the upstream task of the target task based on the task dependency graph; a sending module, used to obtain the execution parameters of the upstream task of the target task after the upstream task is executed, and send the execution parameters to the target task; an execution module, used to execute the target task based on the execution parameters to obtain the target processing result.
[0076] Optionally, in the task scheduling device provided in an embodiment of the present application, the writing unit includes: a second acquisition module, used to obtain the target data format of the cache queue; a conversion module, used to convert the format of each task according to the target data format to obtain multiple converted tasks; and a writing module, used to write the multiple converted tasks into the cache queue.
[0077] The task scheduling device includes a processor and a memory. The above-mentioned writing unit 301, first determining unit 302, execution unit 303, etc. are all stored in the memory as program units. The processor executes the above-mentioned program units stored in the memory to realize accurate scheduling of tasks.
[0078] The processor contains a kernel, which calls the corresponding program unit from the memory. One or more kernels can be set, and accurate scheduling of tasks can be achieved by adjusting kernel parameters.
[0079] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0080] An embodiment of the present invention provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, a task scheduling method is implemented.
[0081] An embodiment of the present invention provides a processor, which is used to run a program, wherein a task scheduling method is executed when the program is running.
[0082] like Figure 4 As shown, an embodiment of the present invention provides an electronic device, the device includes a processor, a memory, and a program stored in the memory and executable on the processor, and the processor implements the following steps when executing the program: obtaining multiple tasks, and writing the multiple tasks into a cache queue; determining a target task from the multiple tasks in the cache queue based on a task dependency graph corresponding to the multiple tasks, wherein the task dependency graph is determined based on the dependency relationship between the multiple tasks; writing the target task into a target execution queue, and executing the target task when the order corresponding to the target task is a preset value to obtain a target processing result.
[0083] Optionally, before determining the target task from multiple tasks in the cache queue based on the task dependency graph corresponding to the multiple tasks, the method also includes: determining nodes based on the multiple tasks; determining edges based on the dependency relationship between the multiple tasks; and constructing a task dependency graph based on the nodes and edges.
[0084] Optionally, determining a target task from multiple tasks in a cache queue based on a task dependency graph corresponding to multiple tasks includes: obtaining a first task in the cache queue, wherein an order of the first task in the cache queue is less than an order of remaining tasks in the cache queue; determining whether an upstream task exists for the first task based on the task dependency graph; if an upstream task exists for the first task, determining whether the upstream task of the first task has been executed to obtain a first judgment result; if the first judgment result indicates that the upstream task of the first task has been executed, determining the first task as the target task.
[0085] Optionally, after determining whether the upstream task of the first task has been executed and obtaining a first judgment result, the method further includes: if the first judgment result indicates that there is a task in the upstream task of the first task that has not been executed, then obtaining task information of the unexecuted task in the upstream task, wherein the task information includes at least: the task name and estimated execution time of the unexecuted task; after the estimated execution time, re-determining whether the unexecuted task is currently executed to obtain a second judgment result; if the second judgment result indicates that the unexecuted task is currently executed, then determining the first task as the target task.
[0086] Optionally, before writing the target task into the target execution queue and executing the target task when the order corresponding to the target task is a preset value to obtain the target processing result, the method also includes: obtaining multiple candidate execution queues and the current number of tasks to be executed in each candidate execution queue; determining the target execution queue from the multiple candidate execution queues based on the current number of tasks to be executed in each candidate execution queue.
[0087] Optionally, executing the target task and obtaining the target processing result includes: determining the upstream task of the target task based on the task dependency graph; after the upstream task is executed, obtaining the execution parameters of the upstream task of the target task, and sending the execution parameters to the target task; executing the target task based on the execution parameters to obtain the target processing result.
[0088] Optionally, obtaining multiple tasks and writing the multiple tasks into the cache queue includes: obtaining a target data format of the cache queue; converting the format of each task according to the target data format to obtain multiple converted tasks; and writing the multiple converted tasks into the cache queue.
[0089] The devices in this article can be servers, PCs, PADs, mobile phones, etc.
[0090] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having the following method steps: obtaining multiple tasks and writing the multiple tasks into a cache queue; determining a target task from the multiple tasks in the cache queue based on a task dependency graph corresponding to the multiple tasks, wherein the task dependency graph is determined based on the dependency relationship between the multiple tasks; writing the target task into a target execution queue, and executing the target task when the order corresponding to the target task is a preset value to obtain a target processing result.
[0091] Optionally, before determining the target task from multiple tasks in the cache queue based on the task dependency graph corresponding to the multiple tasks, the method also includes: determining nodes based on the multiple tasks; determining edges based on the dependency relationship between the multiple tasks; and constructing a task dependency graph based on the nodes and edges.
[0092] Optionally, determining a target task from multiple tasks in a cache queue based on a task dependency graph corresponding to multiple tasks includes: obtaining a first task in the cache queue, wherein an order of the first task in the cache queue is less than an order of remaining tasks in the cache queue; determining whether an upstream task exists for the first task based on the task dependency graph; if an upstream task exists for the first task, determining whether the upstream task of the first task has been executed to obtain a first judgment result; if the first judgment result indicates that the upstream task of the first task has been executed, determining the first task as the target task.
[0093] Optionally, after determining whether the upstream task of the first task has been executed and obtaining a first judgment result, the method further includes: if the first judgment result indicates that there is a task in the upstream task of the first task that has not been executed, then obtaining task information of the unexecuted task in the upstream task, wherein the task information includes at least: the task name and estimated execution time of the unexecuted task; after the estimated execution time, re-determining whether the unexecuted task is currently executed to obtain a second judgment result; if the second judgment result indicates that the unexecuted task is currently executed, then determining the first task as the target task.
[0094] Optionally, before writing the target task into the target execution queue and executing the target task when the order corresponding to the target task is a preset value to obtain the target processing result, the method also includes: obtaining multiple candidate execution queues and the current number of tasks to be executed in each candidate execution queue; determining the target execution queue from the multiple candidate execution queues based on the current number of tasks to be executed in each candidate execution queue.
[0095] Optionally, executing the target task and obtaining the target processing result includes: determining the upstream task of the target task based on the task dependency graph; after the upstream task is executed, obtaining the execution parameters of the upstream task of the target task, and sending the execution parameters to the target task; executing the target task based on the execution parameters to obtain the target processing result.
[0096] Optionally, obtaining multiple tasks and writing the multiple tasks into the cache queue includes: obtaining a target data format of the cache queue; converting the format of each task according to the target data format to obtain multiple converted tasks; and writing the multiple converted tasks into the cache queue.
[0097] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0098] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0099] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0100] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0101] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0102] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0103] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules 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 technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0104] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0105] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0106] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A task scheduling method, characterized in that: include: Acquire multiple tasks and write the multiple tasks into a cache queue; Determining a target task from the plurality of tasks in the cache queue according to a task dependency graph corresponding to the plurality of tasks, wherein the task dependency graph is determined according to dependency relationships between the plurality of tasks; The target task is written into the target execution queue, and when the order corresponding to the target task is a preset value, the target task is executed to obtain a target processing result.
2. The method according to claim 1, characterized in that Before determining the target task from the multiple tasks in the cache queue according to the task dependency graph corresponding to the multiple tasks, the method further includes: Determining a node based on the multiple tasks; Determining edges based on dependency relationships between the multiple tasks; The task dependency graph is constructed based on the nodes and the edges.
3. The method according to claim 1, characterized in that Determining a target task from the multiple tasks in the cache queue according to a task dependency graph corresponding to the multiple tasks includes: Obtaining a first task in the cache queue, wherein the order of the first task in the cache queue is smaller than the order of the remaining tasks in the cache queue; Determining whether the first task has an upstream task based on the task dependency graph; If the first task has an upstream task, determining whether the upstream task of the first task has been executed to obtain a first determination result; If the first judgment result indicates that the upstream task of the first task has been executed, the first task is determined as the target task.
4. The method according to claim 3, characterized in that After determining whether the upstream task of the first task has been executed and obtaining a first determination result, the method further includes: If the first judgment result indicates that there is an unexecuted task in the upstream task of the first task, then obtaining task information of the unexecuted task in the upstream task, wherein the task information at least includes: a task name and an estimated execution time of the unexecuted task; After the estimated execution time, re-determining whether the unexecuted task has been currently executed to obtain a second determination result; If the second judgment result indicates that the unexecuted task has been currently executed, the first task is determined as the target task.
5. The method according to claim 1, wherein Before writing the target task into the target execution queue and executing the target task when the order corresponding to the target task is a preset value to obtain the target processing result, the method further includes: Get multiple candidate execution queues and the number of tasks to be executed in each candidate execution queue; The target execution queue is determined from the multiple candidate execution queues according to the current number of tasks to be executed in each candidate execution queue.
6. The method according to claim 1, wherein Executing the target task to obtain the target processing result includes: Determining upstream tasks of the target task based on the task dependency graph; After the upstream task is completed, obtaining the execution parameters of the upstream task of the target task, and sending the execution parameters to the target task; The target task is executed according to the execution parameters to obtain the target processing result.
7. The method according to claim 1, characterized in that Acquiring multiple tasks and writing the multiple tasks into a cache queue includes: Obtaining a target data format of the cache queue; Convert each task into a format according to the target data format to obtain multiple converted tasks; Writing the converted multiple tasks into the cache queue.
8. A task scheduling device, characterized in that: include: A writing unit, configured to obtain a plurality of tasks and write the plurality of tasks into a cache queue; a first determining unit, configured to determine a target task from the plurality of tasks in the cache queue according to a task dependency graph corresponding to the plurality of tasks, wherein the task dependency graph is determined according to dependency relationships between the plurality of tasks; The execution unit is used to write the target task into the target execution queue, and execute the target task when the order corresponding to the target task is a preset value to obtain a target processing result.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored program, wherein when the program is executed, the storage medium is controlled to execute the task scheduling method according to any one of claims 1 to 7 on a device.
10. An electronic device, characterized in that: It includes one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the task scheduling method described in any one of claims 1 to 7.
Citation Information
Cited By
Multi-task arrangement processing method and device, storage medium and computer equipment
CN119225932A
