Task scheduling method and device, computing equipment and storage medium
By introducing the mechanism of suspension and continuing to perform tasks in the task scheduling system, the efficiency of data flow models in the situation of resource scarcity is solved, the task parallelism and resource optimization are realized, and the application efficiency of the application is improved.
Patent Information
- Application Number
- CN202310921639.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-25
- Publication Date
- 2025-01-28
AI Technical Summary
In applications, when there are not many parallel computing tasks or there are fewer computing units, adopting the data flow model will introduce additional task creation, destruction and scheduling overhead, resulting in low execution efficiency and affecting system performance.
Provide a task scheduling method to perform tasks in the task queue by binding threads. If the task meets the scheduling conditions, the task is suspended, and other tasks in the task queue will be performed. Taste for pause.
Through this method, not only uses the data stream model to create tasks to ensure that the task is parallel, but also compatible with multi -threaded models to achieve task interruptions, avoid busy threads and deadlocks, reduce resource overhead, and improve task execution efficiency.
Smart Images

Figure CN119376867A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a task scheduling method, apparatus, computing device and storage medium. Background Art
[0002] Shared storage systems generally use multi-threaded models and asynchronous task models as parallel programming models to improve system performance. In recent years, the data flow model has been gradually introduced into shared storage systems because it has stronger parallel expression capabilities than the first two models. In the data flow model, parallel computing tasks in an application are abstracted as data flow graphs (a directed acyclic graph) to indicate the direction of data flow between tasks. In the data flow graph, when all dependencies of a task are met, the task can be assigned and executed. This fine-grained parallel expression can tap into more task parallelism and, to the greatest extent possible, eliminate the impact of slow-executing tasks on overall execution efficiency.
[0003] However, when there are not many parallel computing tasks in the application or there are few computing units used to execute tasks, the use of the data flow model will introduce additional task creation, destruction and scheduling overhead, resulting in lower actual execution efficiency of the application, which in turn affects the system performance. Summary of the invention
[0004] The embodiment of the present application provides a task scheduling method, apparatus, computing device and storage medium, which can effectively improve the task execution efficiency of the application program. The technical solution is as follows:
[0005] In a first aspect, a task scheduling method is provided, which is applied to a scheduling unit of a task scheduling system, wherein the task scheduling system includes at least one scheduling unit, each scheduling unit is bound to a thread, and the method includes:
[0006] Running the bound thread to execute a first task in a task queue, wherein the task queue is used to store a plurality of tasks to be executed of an application program, wherein the plurality of tasks to be executed are created based on a data flow graph of the application program;
[0007] If the first task meets the scheduling condition, suspend the execution of the first task and run the thread to execute the second task in the task queue;
[0008] If the second task is executed successfully and the first task no longer satisfies the scheduling condition, the thread is run to continue executing the first task.
[0009] Through the above method, for the task queue created based on the data flow graph of the application, when the scheduling unit runs the bound thread to execute a task in the task queue, if the task meets the scheduling conditions, the task will be suspended and other tasks in the task queue will be executed instead. After the other tasks are successfully executed, the suspended task will be continued. In this way, the data flow model is used to create tasks, ensuring the task parallelism of the application, and the multi-threaded model is compatible, and task interruption under the data flow model is realized, which can avoid the occurrence of thread busy waiting and deadlock, reduce additional resource overhead, and effectively improve the task execution efficiency of the application.
[0010] In some embodiments, suspending execution of the first task includes: suspending execution of the first task and storing execution information of the first task in the stack space of the application; running the thread to continue executing the first task includes: obtaining the execution information from the stack space and running the thread to continue executing the first task.
[0011] In some embodiments, if the first task satisfies the scheduling condition, suspending execution of the first task includes any of the following:
[0012] If it is determined based on the task code of the first task that the first task satisfies the scheduling condition, suspending execution of the first task;
[0013] If it is determined based on an event monitor that the first task satisfies the scheduling condition, execution of the first task is suspended, and the event monitor is used to monitor a target event occurring during execution of the first task.
[0014] In some embodiments, if it is determined based on the task code of the first task that the first task satisfies the scheduling condition, suspending execution of the first task includes:
[0015] If a target statement is read from the task code of the first task during the execution of the first task, suspending the execution of the first task;
[0016] The target statement indicates that the successful execution of the first task depends on other asynchronous tasks, or that the successful execution of the first task depends on target resources that have not yet been acquired.
[0017] In some embodiments, if it is determined based on the event monitor that the first task satisfies the scheduling condition, suspending execution of the first task includes:
[0018] If a notification message sent by the event monitor is obtained during the execution of the first task, suspending the execution of the first task;
[0019] The notification message indicates that the target event occurs during the execution of the first task, or that the number of occurrences of the target event is greater than or equal to a target threshold.
[0020] In some embodiments, the method further comprises:
[0021] If the second task is executed successfully and the first task continues to satisfy the scheduling condition, running the thread to execute at least one third task in the task queue;
[0022] After each of the third tasks is successfully executed, check whether the first task continues to meet the scheduling condition. If so, run the thread to execute the next third task. If not, run the thread to continue executing the first task.
[0023] In some embodiments, the task structure of each of the tasks to be executed includes the thread identifier of the task to be executed, and the thread structure of each of the threads includes a pointer, which is used to obtain the thread identifier of the task to be executed during the execution of the task to be executed to distinguish different tasks.
[0024] In some embodiments, the task scheduling system is configured in a multi-node system, each node in the multi-node system includes at least one scheduling unit, and the method further includes:
[0025] The scheduling unit of the first node runs the thread to execute a fourth task in the task queue, where the fourth task indicates data interaction with the second node;
[0026] If the fourth task meets the scheduling condition, suspend the execution of the fourth task, and run the thread to execute the fifth task in the task queue;
[0027] If the fifth task is executed successfully and the fourth task no longer satisfies the scheduling condition, the thread is run to continue executing the fourth task.
[0028] In some embodiments, the fourth task indicates sending data to the second node;
[0029] If the fourth task satisfies the scheduling condition, suspending execution of the fourth task includes: if it is determined that the second node has not yet received the data sent by the first node, suspending execution of the fourth task.
[0030] In some embodiments, the fourth task indicates receiving data from the second node;
[0031] If the fourth task satisfies the scheduling condition, suspending execution of the fourth task includes: if it is determined that no data has been received from the second node, suspending execution of the fourth task.
[0032] In the second aspect, an embodiment of the present application provides a task scheduling device, which is configured in a scheduling unit of a task scheduling system, wherein the task scheduling system includes at least one scheduling unit, each scheduling unit is bound to a thread, and the device includes at least one functional module for executing a task scheduling method provided by the aforementioned first aspect or any possible implementation method of the first aspect.
[0033] In a third aspect, an embodiment of the present application provides a computing device, which includes a processor and a memory; the memory is used to store at least one piece of program code, and the at least one piece of program code is loaded by the processor and executed as provided in the first aspect or any possible implementation method of the first aspect.
[0034] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium is used to store at least one program code, the at least one program code is used to implement the task scheduling method provided by the first aspect or any possible implementation of the first aspect. The storage medium includes but is not limited to a volatile memory, such as a random access memory, a non-volatile memory, such as a flash memory, a hard disk drive (HDD), and a solid state drive (SSD).
[0035] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on a computing device, enables the computing device to implement the task scheduling method provided by the aforementioned first aspect or any possible implementation of the first aspect. The computer program product may be a software installation package, and when the aforementioned task scheduling method needs to be implemented, the computer program product may be downloaded and executed on a computing device. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 is a schematic diagram of a data flow model provided by a related technology;
[0037] Figure 2 is a schematic diagram of the hardware structure of a computing device provided in an embodiment of the present application;
[0038] Figure 3 is a schematic diagram of the structure of a computing device cluster provided in an embodiment of the present application;
[0039] Figure 4This is a schematic diagram of a connection method of a computing device cluster provided in an embodiment of the present application;
[0040] Figure 5 It is a model memory view provided by a related technology;
[0041] Figure 6 It is a task execution flow diagram of a data flow model provided by a related technology;
[0042] Figure 7 It is a schematic diagram of a task execution process provided by an embodiment of the present application;
[0043] Figure 8 is a schematic diagram of a task scheduling system provided in an embodiment of the present application;
[0044] Fig. 9 is a schematic diagram of a scheduling unit provided in an embodiment of the present application;
[0045] Fig.10 is a flowchart of a task scheduling method provided by an embodiment of the present application;
[0046] Fig.11 is a schematic diagram of a thread identification provided in an embodiment of the present application;
[0047] Fig.12 is a schematic diagram of a multi-threaded model provided by a related technology;
[0048] Fig.13 is a flowchart of another task scheduling method provided by an embodiment of the present application;
[0049] Fig.14 is a schematic diagram of a task scheduling method applied to a multi-node system provided in an embodiment of the present application;
[0050] Fig.15 It is a structural diagram of a task scheduling device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] In order to make the purpose, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings. It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with the relevant laws, regulations and standards of the relevant countries and regions. For example, the data flow diagram of the application involved in this application, the task code of the task, etc. are all obtained with full authorization.
[0052] For ease of understanding, the key terms and key concepts involved in this application are explained below.
[0053] The runtime environment refers to the environment provided for running computer programs. In other words, the runtime environment includes the supporting libraries, data structures, functions and other components required during the operation of the computer program. They provide the necessary infrastructure to enable the computer program to run on a specific operating system and hardware. In some embodiments, the runtime environment is also called a runtime system.
[0054] The parallel programming model is an abstract parallel computer architecture. Its essence is based on the idea of divide-and-conquer algorithm. It decomposes the computing task into several independent subtasks, executes them asynchronously through multithreading, processes each subtask in parallel, and synchronizes all or part of the threads after a certain period of time and blocks them to wait for the merged computing results. Schematically, the parallel programming model includes a multithreading model, a message passing model, etc., which is not limited in this application.
[0055] The open multi-processing (OpenMP) model is a multi-threaded programming scheme that provides a high-level abstract description of parallel algorithms. Users can add compilation guidance statements to the source code, and the compiler automatically parallelizes the program. The model includes both the coarse-grained parallel model "omp parallel for" that uses large synchronization, and the fine-grained asynchronous task parallel model "omp task" that can eliminate some large synchronization.
[0056] Open computing language (OpenCL) is an open, royalty-free standard for cross-platform parallel programming of various accelerators in supercomputers, cloud servers, personal computers, mobile devices, and embedded platforms.
[0057] The basic principle of asynchronous task model, such as OpenMP task clause, async / await primitive, etc., is that while the thread is executing the current task, the application can initiate multiple other parallel tasks. These asynchronous tasks can be executed by other threads in the runtime system. The current thread can wait for these asynchronous tasks to complete, or re-enter the task loop to execute other tasks until these asynchronous tasks are completed.
[0058] The dataflow model is a method that abstracts the entire computing task into a dataflow diagram, processes the computing in a data-driven way, and implements the business processing process with data flow as the center. Among them, the dataflow diagram is a directed acyclic graph (DAG) that is used to indicate the direction of data flow between tasks. In the dataflow diagram, when all dependencies of a task are met, the task can be assigned and executed. This fine-grained parallel expression can tap into more task parallelism, and the point-to-point synchronization method can eliminate the impact of slow-executing tasks on the overall execution efficiency to the greatest extent possible.
[0059] The following uses the Codelet model (a fine-grained, event-driven parallel program execution model) as an example to illustrate the data flow model. Figure 1 It is a schematic diagram of a data flow model provided by a related technology. Figure 1 As shown, the main concept of the Codelet model is codelet (translated as small code). A codelet is a collection of machine instructions. Codelet is the main scheduling unit in the Codelet model and is atomically scheduled (meaning that there is no interruption or failure in execution at one time). Figure 1In the data flow graph shown, nodes represent codelets, edges between nodes indicate dependencies between codelets, and tokens passed on edges represent signals or data. In order to achieve better concurrency, the model supports dividing the data flow graph into multiple subgraphs based on data locality and the functions implemented by the codelet. Each subgraph is assigned to a threaded procedure (TP). TP serves as a container for the data flow graph and the data required by its codelets, providing users with the ability to decompose applications at different granularities. Schematically, the abstract architecture of the codelet model consists of multiple nodes connected together through a network, each node includes multiple chips, and the chips are interconnected by high-speed switches or buses. Each chip includes at least one general-purpose processing core and multiple heterogeneous processing cores. These two types of processing cores have a shared memory address space. Multiple heterogeneous processing cores are also called clusters. Among them, the processing core is functionally divided into a computing core (or a computing unit, CU) and a scheduling core (or a scheduling unit, SU). The computing core is used to execute codelets and is connected to other computing cores in the cluster. The scheduling core is used to manage all hardware resources in the cluster, schedule TPs between clusters (for example, scheduling tasks in cluster A to cluster B), and schedule codelets in the ready state to the corresponding computing cores for execution according to the scheduling strategy. Usually, a cluster includes a scheduling core and multiple computing cores. Each scheduling core includes two queues, one is a codelet queue and the other is a TP queue. The TP queue is used to store the parameter closure required to create a TP object.
[0060] Non-uniform memory access (NUMA) is a computer memory design for multiple processors. Using the NUMA architecture, dozens or even hundreds of processors can be combined in one server.
[0061] User level threads (ULT) refer to threads that are implemented in user programs without kernel support. They do not depend on the operating system kernel. Application processes use the thread library to provide functions for creating, synchronizing, scheduling, and managing threads to control user threads.
[0062] The following is an introduction to the application scenarios and implementation environment involved in this application.
[0063] The present application provides a task scheduling system that can be applied to a computing device configured with a shared storage architecture to improve the execution efficiency of the application program run by the computing device. Among them, the shared storage architecture refers to a system architecture with a unified memory address space simulated by software or hardware. Schematically, the computing device can be a terminal or a server, etc., which has a communication function and can access a wired network or a wireless network. The task scheduling system configured on the computing device can schedule and execute multiple pending tasks of the application program. Among them, the terminal is at least one of a smart phone, a smart watch, a desktop computer, a laptop, a virtual reality terminal, an augmented reality terminal, a wireless terminal and a laptop computer. The server is an independent physical server, or a server cluster or a distributed file system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0064] In some embodiments, the task scheduling system provided in the embodiment of the present application can also be applied to a multi-node system configured with a shared storage architecture, where a node refers to a device having at least one of the two functions of processing data and storing data. A node can be a complete physical machine, such as a terminal or a server, and accordingly, a multi-node system can be understood as a computing device cluster including multiple computing devices. A node can also be a device in a physical machine, such as a processor, memory, or storage, and accordingly, a multi-node system can be understood as a computing device including multiple nodes, and the present application does not limit the configuration form of a multi-node system.
[0065] It should be noted that the task scheduling system provided in the embodiment of the present application can be applied to various general computing scenarios, as well as to non-general computing scenarios such as autonomous driving computing platforms, near-memory computing platforms, and near-data computing platforms, but the present application is not limited thereto.
[0066] In some embodiments, the wireless network or wired network uses standard communication technology and / or protocol. The network includes but is not limited to a data center network, a storage area network (SAN), a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), a mobile, wired or wireless network, a dedicated network or any combination of a virtual private network. In some implementations, technologies and / or formats including hypertext markup language (HTML), extensible markup language (XML) are used to represent data exchanged through the network. In addition, conventional encryption technologies such as secure sockets layer (SSL), transport layer security (TLS), virtual private network (VPN), and Internet protocol security (IPsec) can be used to encrypt all or part of the links. In other embodiments, customized and / or dedicated data communication technologies can also be used to replace or supplement the above data communication technologies.
[0067] The hardware structure of the computing device in the above implementation environment is introduced below.
[0068] The present application embodiment provides a computing device, referring to Figure 2 , Figure 2 Schematic diagram of the hardware structure of a computing device provided in an embodiment of the present application. Figure 2 As shown, the computing device 200 includes a memory 201, a processor 202, a communication interface 203 and a bus 204. The memory 201, the processor 202 and the communication interface 203 are connected to each other through the bus 204.
[0069] The memory 201 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. Schematically, the memory 201 is used to store at least one section of program code, and when the program code stored in the memory 201 is executed by the processor 202, the processor 202 is used to execute the task scheduling method provided in the following method embodiment.
[0070] The processor 202 may be a network processor (NP), a central processing unit (CPU), an application-specific integrated circuit (ASIC), or an integrated circuit for controlling the execution of the program of the present application. The processor 202 may be a single-CPU processor or a multi-CPU processor. In some embodiments, the processor 202 is a system on chip (SOC), which is not limited in the present application. The number of the processors 202 may be one or more. The processor 202 may run multiple different threads simultaneously to perform corresponding tasks.
[0071] The communication interface 203 uses a transceiver module such as a transceiver to implement communication between the computing device 200 and other devices or communication networks. For example, data can be obtained through the communication interface 203.
[0072] The memory 201 and the processor 202 may be separately provided or integrated together.
[0073] Bus 204 may include a pathway for transmitting information between various components of computing device 200 (eg, memory 201 , processor 202 , communication interface 203 ).
[0074] The present application also provides a computing device cluster, which includes multiple computing devices. The multiple computing devices include a server and a terminal, wherein the server can be a server, such as a central server, an edge server, or a local server in a local data center, and the terminal can be a desktop computer, a laptop computer, or a smart phone. Figure 3 , Figure 3 Schematic diagram of a computing device cluster provided in an embodiment of the present application. Figure 3 As shown, the computing device cluster includes multiple computing devices 200. The same instructions for executing the task scheduling method may be stored in the memory 201 of the multiple computing devices 200 in the computing device cluster. In some embodiments, the memory 201 of the multiple computing devices 200 in the computing device cluster may also respectively store partial instructions for executing the task scheduling method. In other words, the combination of multiple computing devices 200 is used to jointly execute the instructions of the task scheduling method.
[0075] In some embodiments, multiple computing devices 200 in a computing device cluster may be connected via a network, which may be a wide area network or a local area network. Figure 4 Schematic diagram of a connection method of a computing device cluster provided in an embodiment of the present application. Figure 4 As shown, two computing devices 200 are connected via a network. Specifically, the network is connected via the communication interface 203 in each computing device 200. It should be understood that Figure 4 The functionality of the computing device 200 shown in FIG. 2 may also be performed by multiple computing devices 200 .
[0076] Based on the above introduction to the application scenario and implementation environment of this application, the task scheduling system provided by this application is introduced below.
[0077] The present application provides a task scheduling system, which includes at least one scheduling unit, which can be used as a runtime system compatible with data flow models, multi-threaded models and asynchronous task models, and improve the task execution efficiency of applications. Schematically, this runtime system provided by the present application is called a unified data flow runtime system (unified data-flow based runtime, UDFRT), which can be provided to users in the form of a library, and its upper-level programming interface can use parallel code expressing a mixture of three models of data flow model, multi-threaded model and asynchronous task model, which is visible to users. In addition, the task scheduling system provided by the present application can also be used as a back-end runtime system for high-level programming languages and parallel computing frameworks such as OpenMP and OpenCL, and these traditional programming models and frameworks are translated into tasks mixed with thread models, asynchronous task models and data flow models through compilation technology, and the task scheduling system provided by the present application performs task scheduling.
[0078] Please refer to the following Figures 5 to 7 , the principles of the task scheduling system provided by this application are introduced.
[0079] It should be understood that the advantage of the data flow model is to describe computing codes that can be decomposed into more tasks and to exploit the parallelism therein. However, for some relatively regular parallel codes, it is more intuitive and more efficient to describe them using a multi-threaded model or an asynchronous task model. In the related art, the data flow runtime system is designed for parallel programs described by a pure data flow model. However, due to the characteristics of the pure data flow model itself, the programming framework and runtime system designed based on this model have additional task creation, destruction, and scheduling overhead compared to the multi-threaded model and the asynchronous task model, resulting in lower actual execution efficiency of the application, which in turn affects the system's operating performance.
[0080] refer to Figure 5 , Figure 5 It is a model memory view provided by related technologies. Figure 5 As shown in Figure (a), taking the Fib function (calculating the sum of the first n terms of the Fibonacci sequence) as an example, in the asynchronous task model, the Fib function is regarded as an application, which includes multiple tasks to be executed, namely FibTask. The context data of each task can be saved in the stack space of the application, so the programming implementation is more intuitive. Figure 5As shown in Figure (b), taking the Fib function as an example, in the Codelet data flow model, when a task is executed, the stack space of the task it depends on has been recycled. Therefore, the context data required by the current task needs to be copied from the stack space of the task it depends on and placed in the context data of the current task. It can be seen that this design of the Codelet data flow model can express richer fine-grained parallelism on the one hand, but it will also introduce additional data movement overhead on the other.
[0081] It should be noted that in the codelet data flow model, the execution of the codelet is uninterruptible, that is, after any codelet task is scheduled to a thread for execution, its execution process cannot be interrupted. Figure 6 It is a task execution flow diagram of a data flow model provided by related technologies. Figure 6 As shown, in the Codelet data flow model, if an application includes multiple tasks A, B, and C to be executed, in the task scheduling system involved in the related technology, the scheduling unit executes task A→task B→task C in sequence. In this application, by designing a runtime system upper layer interface, the scheduling unit of the task scheduling system can suspend the execution of a task (that is, interrupt the execution) during the execution of a task, re-enter the task scheduling cycle of the scheduling unit, and execute other tasks instead. This design breaks the setting that Codelet cannot be interrupted to a certain extent. Reference Figure 7 , Figure 7 Schematic diagram of a task execution process provided by an embodiment of the present application. Figure 7 As shown, if an application includes multiple tasks A, B1, B2, and C to be executed (wherein, task B1 and task B2 are parallel tasks, task C is a synchronous task of task B1 and task B2, and task C depends on task B1 and task B2), when the scheduling unit is executing task A, if it encounters a statement that task A creates and executes tasks B1 and B2, the execution of task A will be suspended, and tasks B1 and task B2 will be executed instead (spawn indicates that tasks B1 and task B2 are added to the task queue). When the scheduling unit is executing tasks B1 and B2, it checks whether the dependency count of task C is 0 (that is, checks whether the dependency of the synchronous task of the current task is satisfied). If the dependency count of task C is 0, after tasks B1 and B2 are successfully executed, the remaining part of task A will continue to be executed. It should be understood that in this process, since the stack space of task A is not released during the execution of tasks B1 and B2, the context data of task A can be referenced during the execution of tasks B1 and B2, thereby avoiding some data movement overhead. In addition, the scheduling unit can continue to interrupt and execute other asynchronous tasks during the execution of task B1 and task B2, so as to realize nested asynchronous task execution, which will not be described in detail here.
[0082] Based on the above Figures 5 to 7 The principle introduction shown below refers to Figure 8 and Fig. 9 , the task scheduling system provided in the embodiment of the present application is introduced.
[0083] Figure 8 Schematic diagram of a task scheduling system provided in an embodiment of the present application. Figure 8 As shown, the task scheduling system includes a user layer 801, a logic layer 802, and a physical layer 803. The user layer 801 is used to create a data flow graph of the application based on the data flow model. The data flow graph includes at least one subgraph (task DAG), each subgraph indicates at least one task to be executed of the application, where "T" is used to represent a regular task (regular tasklet) and "A" is used to represent an asynchronous task (asynchronous tasklet), that is, a task that meets the scheduling conditions provided by this application. The logic layer 802 includes at least one scheduling unit (the components of the scheduling unit will be described later). Fig. 9 , each scheduling unit is bound to a thread, and each scheduling unit corresponds to a task queue. Schematically, the scheduling unit is used to execute the task scheduling method provided by the present application (see the subsequent method embodiments for details, which will not be repeated here). In addition, the present application does not limit the number of scheduling units in the task scheduling system, and the number can be set according to demand. For example, for a computing device using a NUMA architecture, the number of scheduling units can be set to the number of nodes in the NUMA; for another example, a scheduling unit is set for processing cores that share the same last-level cache; for another example, a scheduling unit is set for processing cores that share the same secondary cache, and so on, the present application is not limited thereto. The physical layer 803 is also the thread resource provided by the operating system, running at least one thread, and each thread is bound to a scheduling unit. In this way, multiple tasks to be executed of the application are separated from the threads, thereby ensuring that the application does not excessively occupy the thread resources of the system, thereby improving the resource utilization of the overall system.
[0084] Fig. 9 is a schematic diagram of a scheduling unit provided in an embodiment of the present application. Fig. 9As shown, the task queue of the application stores multiple tasks to be executed, and multiple tasks to be executed are created based on the data flow graph of the application. Spawn refers to the interface between the user layer and the logic layer, indicating that the tasks in the data flow graph are added to the task queue. In the embodiment of the present application, the user-level thread ULT is introduced to execute each task. Schematically, the scheduling unit includes a ULT wrapper, an event monitor, and a scheduler (scheduler, referred to as scheduler sched in the figure), wherein the ULT wrapper converts the ready tasks in the task queue into ULT and submits them to the scheduler so that the scheduler runs the bound thread to execute the corresponding task. In the process of executing the task, if the task meets the scheduling conditions, the scheduler suspends the execution of the task, stores the execution information of the task in the stack space of the application, and then obtains other tasks from the task queue and executes them. After the new task is successfully executed, check whether the suspended task still meets the scheduling conditions. If it meets, then get other tasks from the task queue and execute them. If not, continue to execute the suspended task. In addition, a task satisfies the scheduling conditions either because the task code itself indicates that the task satisfies the scheduling conditions, or because the scheduler determines that the task satisfies the scheduling conditions through a notification message sent by an event monitor. The scheduler can configure the event monitor, but the present application is not limited to this. The specific implementation method of the scheduling conditions will be described in detail in the following method embodiments and will not be repeated here.
[0085] The following are several method embodiments. Figure 8 and Fig. 9 Based on the task scheduling system shown, the task scheduling method provided by this application is introduced.
[0086] Fig.10 is a flowchart of a task scheduling method provided by an embodiment of the present application. Fig.10 As shown, the method is applied to a scheduling unit of a task scheduling system, the task scheduling system includes at least one scheduling unit, each scheduling unit is bound to a thread. Schematically, the method includes the following steps 1001 to 1005.
[0087] 1001. A scheduling unit runs a bound thread to execute a first task in a task queue, where the task queue is used to store a plurality of tasks to be executed of an application program, where the plurality of tasks to be executed are created based on a data flow graph of the application program.
[0088] In the embodiment of the present application, the scheduling unit refers to any scheduling unit of the task scheduling system, and the present application does not limit the number of scheduling units in the task scheduling system. It should be understood that the task scheduling system is configured on a computing device, and the computing device initializes the task scheduling system in response to the initialization operation for the task scheduling system, creates at least one scheduling unit, and binds each scheduling unit to a thread provided by the operating system, that is, one scheduling unit is bound to one thread.
[0089] The first task refers to any task in the task queue. Multiple tasks to be executed in the task queue are created based on the data flow graph of the application. For example, the application is expressed as multiple fine-grained parallel tasks using the codelet data flow model, and the data flow graph of the application is obtained. The multiple parallel tasks indicated by the data flow graph are added to the task queue, waiting for scheduling and execution by the scheduling unit. In the embodiment of the present application, one scheduling unit corresponds to one task queue.
[0090] In addition, the task structure of each task to be executed in the task queue includes the thread identifier of the task to be executed, and the thread structure of the thread bound to each scheduling unit includes a pointer, wherein the pointer is used to obtain the thread identifier of the task to be executed during the execution of the task to be executed to distinguish different tasks. Fig.11 , Fig.11 is a schematic diagram of a thread identifier provided by an embodiment of the present application. Fig.11As shown, in the thread model, the working thread needs to obtain the identification of the logical thread when executing the task, so as to distinguish multiple parallel tasks through the identification of each logical thread. It should be understood that the logical thread refers to the thread specified by the developer when writing the task code, and the working thread refers to the thread that actually executes the task. For example, the application includes tasks 0 to 9, and the number of threads provided by the operating system is 3. When the developer writes the task code, he can add the thread ID of the logical thread = 0 in the task structure of tasks 0 to 3, add the thread ID of the logical thread = 1 in the task structure of tasks 4 to 6, and add the thread ID of the logical thread = 2 in the task structure of tasks 7 to 9. In other words, the thread ID is used to record the logical thread to which the current task belongs, and it is realized by providing an interface for setting the thread ID in the user layer of the task scheduling system. Accordingly, pointers are added to the thread structures (or thread local storage, TLS) of the two working threads. Based on this, when the scheduling unit is running threads to execute tasks, when the working thread 0 executes tasks 0 to 3, it obtains thread ID 0 through the pointer in TLS. When the working thread 1 executes tasks 4 to 6, it obtains thread ID 1 through the pointer in TLS. When the working thread 3 executes tasks 7 to 9, it obtains thread ID 2 through the pointer in TLS. In this way, multiple parallel tasks can be distinguished. Moreover, if a task is successfully executed, the pointer corresponding to the working thread points to a null pointer, so that other tasks except the task can obtain the correct thread identifier during execution. In addition, by setting the thread identifier for the logical thread as described above, the decoupling of the logical thread and the working thread is achieved, that is, the complete separation of tasks and working threads in the multi-threaded model is achieved, which can avoid the thread explosion problem that occurs when parallel tasks are nested.
[0091] 1002. If the first task meets the scheduling condition, the scheduling unit suspends the execution of the first task and stores the execution information of the first task in the stack space of the application program.
[0092] In an embodiment of the present application, the execution information of the first task indicates the execution progress, execution data, etc. of the first task, but the present application is not limited thereto. For example, the execution information of the first task is the context data of the first task, and for another example, the execution information of the first task is the program stack of the first task, and so on. By storing the execution information of the first task in the stack space of the application, on the one hand, it is convenient for the scheduling unit to continue to execute the remaining part of the first task, and on the other hand, the scheduling unit can refer to the execution information of the first task in the stack space during the execution of other tasks, thereby reducing data movement overhead and saving computing resources.
[0093] Based on the aforementioned Fig. 9From the content shown, it can be known that a task meets the scheduling conditions either because the task code itself indicates that the task meets the scheduling conditions (or the task actively interrupts execution), or because the task meets the scheduling conditions through a notification message sent by an event monitor (or the task passively interrupts execution). The following introduces these two situations respectively:
[0094] Case 1: if it is determined based on the task code of the first task that the first task satisfies the scheduling condition, the execution of the first task is suspended.
[0095] Among them, this application supports inserting a target statement in the task code of the first task to indicate that the task meets the scheduling conditions. The target statement can also be understood as a suspend statement. If the scheduling unit reads the target statement from the task code of the first task during the execution of the first task, the execution of the first task is suspended. Schematically, the target statement indicates any of the following situations:
[0096] The first type is that the target statement indicates that the successful execution of the first task depends on other asynchronous tasks. For example, there are multiple asynchronous tasks for the first task, and the successful execution of the first task depends on the completion of these asynchronous tasks. In this way, by inserting the target statement in the task code of the first task, when the scheduling unit reads the target statement during the execution of the first task, it suspends the execution of the first task and stores the execution information of the first task in the stack space of the application (such as storing the context information of the first task in the program stack of the application).
[0097] The second type is that the target statement indicates that the successful execution of the first task depends on the target resource that has not yet been obtained. For example, during the execution of the first task, it needs to wait for some shared resources (such as disk I / O, network communication, etc.) but cannot be satisfied temporarily. In this way, by inserting the target statement in the task code of the first task, when the scheduling unit reads the target statement during the execution of the first task, it suspends the execution of the first task and stores the execution information of the first task in the stack space of the application (such as storing the program stack of the first task in the temporary storage area of the application).
[0098] Case 2: If it is determined based on the event monitor that the first task meets the scheduling conditions, the execution of the first task is suspended.
[0099] Wherein, the scheduling unit is configured with an event monitor for monitoring the target event occurring during the execution of the first task, and can send a notification message when the target event is detected, so that the scheduling unit suspends the execution of the first task. Wherein, the target event can be set according to demand, for example, the execution duration of the target event is greater than or equal to the preset duration, for another example, the execution period of the target event is greater than or equal to the preset period, for another example, the target event is that the first task is waiting for system shared resources, and so on, and the present application is not limited thereto. Schematically, if the scheduling unit obtains a notification message sent by the event monitor during the execution of the first task, the execution of the first task is suspended; wherein the notification message indicates that the target event has occurred during the execution of the first task, or the number of occurrences of the target event is greater than or equal to the target threshold. The target threshold can be configured according to the setting of the target event, and the present application does not limit this.
[0100] 1003. The scheduling unit runs the bound thread to execute the second task in the task queue.
[0101] In an embodiment of the present application, the second task refers to other tasks in the task queue except the first task. It should be understood that the execution order of each task to be executed in the task queue can be set according to the application requirements of the application. For example, the task queue includes tasks 0 to 9. If the first task is task 0, the scheduling unit suspends the execution of the first task and sequentially obtains task 1 from the task queue as the second task, or, in a specified order, obtains task 4 from the task queue as the second task, and so on. The present application is not limited to this.
[0102] 1004. If the second task is executed successfully and the first task no longer meets the scheduling condition, the scheduling unit obtains the execution information of the first task from the stack space of the application program and runs the bound thread to continue executing the first task.
[0103] In an embodiment of the present application, after the second task is successfully executed, the scheduling unit checks whether the first task continues to meet the scheduling conditions. If the first task no longer meets the scheduling conditions, the scheduling unit obtains the execution information of the first task from the stack space of the application program, continues to execute the remaining part of the first task, and releases system resources such as storage after the first task is successfully executed.
[0104] Among them, based on the above introduction to the scheduling conditions, it is possible to deduce a method for determining whether the first task continues to meet the scheduling conditions. For example, if there is a target statement in the task code of the first task, and the target statement indicates that the successful execution of the first task depends on other asynchronous tasks, then after the second task is successfully executed, the scheduling unit checks whether the other asynchronous tasks that the first task depends on are completed. If they are completed, it is determined that the first task no longer meets the scheduling conditions. For another example, if there is a target statement in the task code of the first task, and the target statement indicates that the successful execution of the first task depends on target resources that have not yet been obtained, then after the second task is successfully executed, the scheduling unit checks whether the target resources that the first task is waiting for have been obtained. If they have been obtained, it is determined that the first task no longer meets the scheduling conditions, and so on.
[0105] 1005. If the second task is executed successfully and the first task continues to meet the scheduling conditions, the scheduling unit runs the bound thread to execute at least one third task in the task queue. After each third task is executed successfully, check whether the first task continues to meet the scheduling conditions. If so, run the bound thread to execute the next third task. If no longer satisfied, run the bound thread to continue executing the first task.
[0106] In an embodiment of the present application, if after the second task is executed successfully, by checking whether the first task continues to meet the scheduling conditions, it is determined that the first task continues to meet the scheduling conditions, then the scheduling unit continues to obtain at least one third task from the task queue for execution, and after each third task is successfully executed, it is checked whether the first task continues to meet the scheduling conditions.
[0107] The process shown in the above steps 1003 to 1005 is that after the scheduling unit interrupts the execution of a task, it continuously obtains tasks from the task queue and runs the bound threads to execute these new tasks. Moreover, each time a new task is successfully executed, it checks whether the interrupted task continues to meet the scheduling conditions, thereby ensuring that the application will not deadlock.
[0108] It should be understood that in applications, there are often tasks that require a long wait for shared resources, such as synchronization barriers, disk I / O, and network communications. When these tasks are expressed using the pure data flow model provided by the relevant technology, the operating system can schedule threads to prevent these tasks from excessively occupying processing time and improve the utilization of the entire system. However, due to the setting that tasks cannot be interrupted in the data flow model provided by the relevant technology, the parallel resources available to the application during this period are reduced, thereby reducing the execution efficiency of the application. The task scheduling method provided by the present application supports temporarily interrupting the execution of the current task and executing other tasks instead, thereby improving the parallel execution efficiency of the application and avoiding the waste of hardware resources. In addition, in the relevant technology, a producer-consumer parallel mode is often adopted between multiple threads, that is, a certain thread produces data and other threads are responsible for consuming data, such as Fig.12 As shown, Fig.12 It is a schematic diagram of a multi-threaded model provided by a related technology. It can be seen that in a runtime system that supports a multi-threaded model (such as an OpenMP runtime), since the logical thread and the working thread are one-to-one corresponding, the operating system will ensure that the producer thread will be scheduled for execution and there will be no deadlock. In the data flow model provided by the related technology, since the task is not interruptible, that is, the scheduling unit will not switch to execute other tasks until the current task is completed during the execution of a certain task. When all the working threads in the system are executing consumer tasks and the producer tasks cannot be executed, the runtime system will experience a deadlock phenomenon. The task scheduling method provided by the present application is compatible with the multi-threaded model and the data flow model, supports interrupting the execution of the current task and executing other tasks instead, avoids the busy waiting and deadlock of the working thread, and reduces unnecessary time overhead.
[0109] In summary, in the task scheduling method provided in the embodiment of the present application, for the task queue created based on the data flow graph of the application, when the scheduling unit runs the bound thread to execute a task in the task queue, if the task meets the scheduling conditions, the task is suspended and other tasks in the task queue are executed instead, and after the other tasks are successfully executed, the suspended task is continued. In this way, the data flow model is used to create tasks, ensuring the task parallelism of the application, and the multi-threaded model is compatible, and task interruption under the data flow model is realized, avoiding the occurrence of thread busy waiting and deadlock, reducing additional resource overhead, and effectively improving the task execution efficiency of the application.
[0110] In some embodiments, the task scheduling system provided by the present application can also be applied to a multi-node system configured with a shared storage architecture, wherein each node in the multi-node system includes at least one scheduling unit, each scheduling unit is bound to a thread for executing the above Fig.10In other words, each node runs an independent application, that is, has an independent data flow graph, so that the scheduling unit on each node can execute the above Fig.10 The task scheduling method shown is not described here in detail. In addition, when each node in a multi-node system runs a parallel application, since the data is distributed on each node, each node will involve data interaction during the calculation process. In this scenario, the task scheduling method provided by this application is also applicable, that is, tasks involving data interaction are treated as communication tasks in the task queue, so that when the scheduling unit is executing a communication task, if the communication task scheduling conditions are not met, the communication task is suspended and other tasks in the task queue are executed instead, thereby improving the task execution efficiency of the application. Refer to the following Fig.13 , this process is introduced.
[0111] Fig.13 is a flowchart of another task scheduling method provided by an embodiment of the present application. Fig.13 As shown, the method is applied to a multi-node system configured with a task scheduling system, each node in the multi-node system includes at least one scheduling unit, and each scheduling unit is bound to a thread. Schematically, taking the scheduling unit of the first node (any node in the multi-node system) as an example, the method includes the following steps 1301 to 1303.
[0112] 1301. A scheduling unit of a first node runs a bound thread to execute a fourth task in a task queue, where the fourth task indicates data interaction with a second node.
[0113] The scheduling unit can also perform the above Fig.10 The task scheduling method shown is not described in detail here. In this step, the fourth task is also an asynchronous communication task, which indicates data interaction with the second node, for example, sending data to the second node, or receiving data from the second node.
[0114] 1302. If the fourth task meets the scheduling condition, the scheduling unit suspends execution of the fourth task and runs the thread to execute the fifth task in the task queue.
[0115] In some embodiments, the fourth task indicates sending data to the second node. In an illustrative embodiment, if the fourth task satisfies the scheduling condition, suspending the execution of the fourth task includes: if it is determined that the second node has not yet received the data sent by the first node, suspending the execution of the fourth task. For example, during the execution of the fourth task, the scheduling unit calls the communication interface to send data to the second node. If the second node does not receive a successful reception message, it is determined that the fourth task satisfies the scheduling condition, and the target statement is called (as described above). Fig.10The embodiment shown is the same and will not be described in detail), suspending the execution of the fourth task, storing the execution information of the fourth task in the stack space of the application program, and waiting to be executed again.
[0116] In some embodiments, the fourth task indicates receiving data from the second node. Indicatively, if the fourth task meets the scheduling condition, suspending the execution of the fourth task includes: if it is determined that data has not been received from the second node, suspending the execution of the fourth task. For example, during the execution of the fourth task, the scheduling unit calls the communication interface to receive data from the second node. If data sent by the second node is not received temporarily, it is determined that the fourth task meets the scheduling condition, calls the target statement, suspends the execution of the fourth task, and stores the execution information of the fourth task in the stack space of the application program, waiting to be re-executed.
[0117] 1303. If the fifth task is executed successfully and the fourth task no longer meets the scheduling condition, the scheduling unit runs the thread to continue executing the fourth task.
[0118] Among them, based on the above Fig.10 In the illustrated embodiment, steps 1004 and 1005 are similar. After the fifth task is successfully executed, the scheduling unit checks whether the fourth task continues to meet the scheduling conditions. If the scheduling conditions are no longer met (for example, if the fourth task indicates to send data to the second node, when the first node receives the successful reception message fed back by the second node, the fourth task no longer meets the scheduling conditions; for another example, if the fourth task indicates to receive data from the second node, when the first node receives the data sent by the second node, the fourth task no longer meets the scheduling conditions), the scheduling unit obtains the execution information of the fourth task from the stack space of the application and continues to execute the remaining part of the fourth task. If the scheduling conditions continue to be met, the scheduling unit continues to obtain at least one sixth task from the task queue for execution. After each sixth task is successfully executed, it checks whether the fourth task continues to meet the scheduling conditions. No further details are given.
[0119] Reference below Fig.14 , for the above Fig.13 The task scheduling method shown is illustrated by an example. Fig.14 Schematic diagram of a task scheduling method applied to a multi-node system provided by an embodiment of the present application. Fig.14 As shown, the multi-node system includes multiple nodes: node 0, node 1 and node 2. Each node has an independent data flow graph. For multi-node parallel applications, data is distributed on each node.
[0120] Take the scheduling unit of node 0 executing the asynchronous communication task to send data as an example: the scheduling unit of node 0 runs the bound thread to execute the asynchronous communication task in the task queue, that is, calls the asynchronous communication interface to send data to node 1, and node 0 can return without waiting for node 1 to complete receiving; after the scheduling unit executes a task loop, it checks whether node 1 has completed data reception, that is, whether it has received the successful reception message fed back by node 1. If data reception is completed, it indicates that the current asynchronous communication task does not meet the scheduling conditions, and the loop ends. If data reception is not completed, it indicates that the current asynchronous communication task meets the scheduling conditions, and the target statement is called to suspend the execution of the current asynchronous communication task. The execution information of the task is stored in the stack space of the application, waiting to be re-executed, and other tasks in the task queue are executed, thereby reducing the occupation of hardware resources.
[0121] Take the scheduling unit of node 0 executing the asynchronous communication task to receive data as an example: the scheduling unit of node 0 runs the bound thread to execute the asynchronous communication task in the task queue, that is, calls the asynchronous communication interface to receive data from node 2, and node 0 can return without waiting for node 1 to complete sending; after the scheduling unit executes a task loop, it checks whether node 0 has completed data reception. If data reception is completed, it indicates that the current asynchronous communication task does not meet the scheduling conditions, and the loop ends. If data reception is not completed, it indicates that the current asynchronous communication task meets the scheduling conditions, calls the target statement, suspends the execution of the current asynchronous communication task, and stores the execution information of the task in the stack space of the application, waiting to be re-executed, and executes other tasks in the task queue, thereby reducing the occupation of hardware resources.
[0122] It can be seen that when the task scheduling system provided by the present application is applied to a multi-node system, the task scheduling system can suspend the execution of the current task during the execution of an asynchronous communication task and execute other tasks instead to reduce the occupation of hardware resources. In this process, the suspended task is constantly reawakened and checked to see whether the remote data has arrived, thereby avoiding busy threads and deadlock situations, thereby improving the task execution efficiency of the application.
[0123] Fig.15 1 is a schematic diagram of the structure of a task scheduling device provided in an embodiment of the present application. The task scheduling device can be implemented as part or all of the functions of the scheduling unit in the aforementioned task scheduling system through software, hardware, or a combination of both. Fig.15 As shown, the task scheduling device is configured in a scheduling unit of a task scheduling system. The task scheduling system includes at least one scheduling unit, each scheduling unit is bound to a thread, and the device includes a first running module 1501, a second running module 1502 and a third running module 1503.
[0124] A first running module 1501, used to run a bound thread to execute a first task in a task queue, where the task queue is used to store a plurality of to-be-executed tasks of an application program, where the plurality of to-be-executed tasks are created based on a data flow graph of the application program;
[0125] The second running module 1502 is used to suspend the execution of the first task and run the thread to execute the second task in the task queue if the first task meets the scheduling condition;
[0126] The third running module 1503 is used to run the thread to continue executing the first task if the second task is successfully executed and the first task no longer meets the scheduling condition.
[0127] In some embodiments, the second running module 1502 is used to: suspend the execution of the first task and store the execution information of the first task in the stack space of the application; the third running module 1503 is used to: obtain the execution information from the stack space and run the thread to continue executing the first task.
[0128] In some embodiments, the second operation module 1502 is used for any of the following:
[0129] If it is determined based on the task code of the first task that the first task satisfies the scheduling condition, suspending execution of the first task;
[0130] If it is determined based on the event monitor that the first task meets the scheduling condition, execution of the first task is suspended, and the event monitor is used to monitor the target event occurring during the execution of the first task.
[0131] In some embodiments, the second operation module 1502 is used to:
[0132] If, during the execution of the first task, the target statement is read from the task code of the first task, the execution of the first task is suspended;
[0133] The target statement indicates that the successful execution of the first task depends on other asynchronous tasks, or that the successful execution of the first task depends on target resources that have not yet been acquired.
[0134] In some embodiments, the second operation module 1502 is used to:
[0135] If a notification message sent by the event monitor is obtained during the execution of the first task, the execution of the first task is suspended;
[0136] The notification message indicates that a target event occurs during the execution of the first task, or that the number of times the target event occurs is greater than or equal to a target threshold.
[0137] In some embodiments, the third operation module 1503 is further used to:
[0138] If the second task is successfully executed and the first task continues to meet the scheduling condition, running the thread to execute at least one third task in the task queue;
[0139] After each third task is successfully executed, it is checked whether the first task continues to meet the scheduling conditions. If so, the thread is run to execute the next third task. If not, the thread is run to continue to execute the first task.
[0140] In some embodiments, the task structure of each task to be executed includes a thread identifier of the task to be executed, and the thread structure of each thread includes a pointer, which is used to obtain the thread identifier of the task to be executed during the execution of the task to be executed to distinguish different tasks.
[0141] In some embodiments, the task scheduling system is configured in a multi-node system, each node in the multi-node system includes at least one scheduling unit, and the device further includes a fourth operation module for:
[0142] The scheduling unit of the first node runs a thread to execute a fourth task in the task queue, where the fourth task indicates data interaction with the second node;
[0143] If the fourth task meets the scheduling condition, suspend the execution of the fourth task and run the thread to execute the fifth task in the task queue;
[0144] If the fifth task is executed successfully and the fourth task no longer meets the scheduling condition, the thread is run to continue executing the fourth task.
[0145] In some embodiments, the fourth task indicates sending data to the second node;
[0146] The fourth operation module is used to suspend the execution of the fourth task if it is determined that the second node has not yet received the data sent by the first node.
[0147] In some embodiments, the fourth task indicates receiving data from the second node;
[0148] The fourth running module is used to suspend the execution of the fourth task if it is determined that no data has been received from the second node.
[0149] Through the above device, for the task queue created based on the data flow graph of the application, when the scheduling unit runs the bound thread to execute a task in the task queue, if the task meets the scheduling conditions, the task will be suspended and other tasks in the task queue will be executed instead. After the other tasks are successfully executed, the suspended task will continue to be executed. In this way, the data flow model is used to create tasks, ensuring the task parallelism of the application, and it is compatible with the multi-threaded model, realizing task interruption under the data flow model, avoiding the occurrence of thread busy waiting and deadlock, reducing additional resource overhead, and effectively improving the task execution efficiency of the application.
[0150] In addition, in the above device, the first operation module 1501, the second operation module 1502 and the third operation module 1503 can be implemented by software or hardware. Exemplarily, the implementation of the first operation module 1501 is described below by taking the first operation module 1501 as an example. Similarly, the implementation of other modules can refer to the implementation of the first operation module 1501.
[0151] As an example of a software functional unit, the first operation module 1501 may include code running on a computing instance. Among them, the computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Further, the above-mentioned computing instance may be one or more. For example, the first operation module 1501 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code can be distributed in the same region (region) or in different regions. Furthermore, the multiple hosts / virtual machines / containers used to run the code can be distributed in the same availability zone (AZ) or in different AZs, each AZ including a data center or multiple data centers with close geographical locations. Among them, usually a region can include multiple AZs.
[0152] Similarly, multiple hosts / virtual machines / containers used to run the code can be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Usually, a VPC is set up in a region. For cross-region communication between two VPCs in the same region and between VPCs in different regions, a communication gateway needs to be set up in each VPC to achieve interconnection between VPCs through the communication gateway.
[0153] As an example of a hardware functional unit, the first operation module 1501 may include at least one computing device. Alternatively, the first operation module 1501 may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.
[0154] The multiple computing devices included in the first operation module 1501 can be distributed in the same region or in different regions. The multiple computing devices included in the first operation module 1501 can be distributed in the same AZ or in different AZs. Similarly, the multiple computing devices included in the first operation module 1501 can be distributed in the same VPC or in multiple VPCs. The multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.
[0155] It should be noted that the task scheduling device provided in the above embodiment only uses the division of the above functional modules as an example when performing task scheduling. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the task scheduling device provided in the above embodiment and the task scheduling method embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0156] In this application, the terms "first", "second", etc. are used to distinguish between identical or similar items with substantially the same effects and functions. It should be understood that there is no logical or temporal dependency between "first", "second", and "nth", nor is the quantity and execution order limited. It should also be understood that although the following description uses the terms first, second, etc. to describe various elements, these elements should not be limited by the terms. These terms are only used to distinguish one element from another. For example, without departing from the scope of the various described examples, the first task can be referred to as the second task, and similarly, the second task can be referred to as the first task. Both the first task and the second task can be tasks, and in some cases, can be separate and different tasks.
[0157] The term "at least one" in this application means one or more, and the term "plurality" in this application means two or more, for example, a plurality of tasks means two or more tasks.
[0158] The above description is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0159] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of program structure information. The program structure information includes one or more program instructions. When the program instructions are loaded and executed on a computing device, all or part of the processes or functions in the embodiments of the present application are generated.
[0160] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0161] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A task scheduling method, characterized in that: A scheduling unit applied to a task scheduling system, the task scheduling system comprising at least one scheduling unit, each scheduling unit being bound to a thread, the method comprising: Running the bound thread to execute a first task in a task queue, wherein the task queue is used to store a plurality of tasks to be executed of an application program, wherein the plurality of tasks to be executed are created based on a data flow graph of the application program; If the first task meets the scheduling condition, suspend the execution of the first task and run the thread to execute the second task in the task queue; If the second task is executed successfully and the first task no longer satisfies the scheduling condition, the thread is run to continue executing the first task.
2. The method according to claim 1, characterized in that: The suspending execution of the first task includes: suspending execution of the first task, and storing execution information of the first task in the stack space of the application; The running the thread to continue executing the first task includes: acquiring the execution information from the stack space, and running the thread to continue executing the first task.
3. The method according to claim 1 or 2, characterized in that: If the first task satisfies the scheduling condition, suspending execution of the first task includes any of the following: If it is determined based on the task code of the first task that the first task satisfies the scheduling condition, suspending execution of the first task; If it is determined based on an event monitor that the first task satisfies the scheduling condition, execution of the first task is suspended, and the event monitor is used to monitor a target event occurring during execution of the first task.
4. The method according to claim 3, characterized in that If it is determined based on the task code of the first task that the first task satisfies the scheduling condition, suspending execution of the first task includes: If a target statement is read from the task code of the first task during the execution of the first task, suspending the execution of the first task; The target statement indicates that the successful execution of the first task depends on other asynchronous tasks, or that the successful execution of the first task depends on target resources that have not yet been acquired.
5. The method according to claim 3, characterized in that: If it is determined based on the event monitor that the first task satisfies the scheduling condition, suspending execution of the first task includes: If a notification message sent by the event monitor is obtained during the execution of the first task, suspending the execution of the first task; The notification message indicates that the target event occurs during the execution of the first task, or that the number of occurrences of the target event is greater than or equal to a target threshold.
6. The method according to any one of claims 1 to 5, characterized in that The method further comprises: If the second task is executed successfully and the first task continues to satisfy the scheduling condition, running the thread to execute at least one third task in the task queue; After each of the third tasks is successfully executed, check whether the first task continues to meet the scheduling condition. If so, run the thread to execute the next third task. If not, run the thread to continue executing the first task.
7. The method according to any one of claims 1 to 6, characterized in that The task structure of each task to be executed includes the thread identifier of the task to be executed, and the thread structure of each thread includes a pointer, which is used to obtain the thread identifier of the task to be executed during the execution of the task to be executed to distinguish different tasks.
8. The method according to any one of claims 1 to 7, characterized in that The task scheduling system is configured in a multi-node system, each node in the multi-node system includes at least one scheduling unit, and the method further includes: The scheduling unit of the first node runs the thread to execute a fourth task in the task queue, where the fourth task indicates data interaction with the second node; If the fourth task meets the scheduling condition, suspend the execution of the fourth task, and run the thread to execute the fifth task in the task queue; If the fifth task is executed successfully and the fourth task no longer satisfies the scheduling condition, the thread is run to continue executing the fourth task.
9. The method according to claim 8, characterized in that The fourth task indicates sending data to the second node; If the fourth task satisfies the scheduling condition, suspending execution of the fourth task includes: if it is determined that the second node has not yet received the data sent by the first node, suspending execution of the fourth task.
10. The method according to claim 8, characterized in that The fourth task indicates receiving data from the second node; If the fourth task satisfies the scheduling condition, suspending execution of the fourth task includes: if it is determined that no data has been received from the second node, suspending execution of the fourth task.
11. A task scheduling device, characterized in that: A scheduling unit configured in a task scheduling system, the task scheduling system includes at least one scheduling unit, each scheduling unit is bound to a thread, and the device includes: A first running module, used for running the bound thread to execute a first task in a task queue, wherein the task queue is used for storing a plurality of to-be-executed tasks of an application program, wherein the plurality of to-be-executed tasks are created based on a data flow graph of the application program; A second running module, configured to suspend execution of the first task and run the thread to execute a second task in the task queue if the first task meets a scheduling condition; The third running module is used to run the thread to continue executing the first task if the second task is successfully executed and the first task no longer meets the scheduling condition.
12. The device according to claim 11, characterized in that The second running module is used to: suspend the execution of the first task and store the execution information of the first task in the stack space of the application program; The third running module is used to: obtain the execution information from the stack space, and run the thread to continue executing the first task.
13. The device according to claim 11 or 12, characterized in that The second operation module is used for any of the following: If it is determined based on the task code of the first task that the first task satisfies the scheduling condition, suspending execution of the first task; If it is determined based on an event monitor that the first task satisfies the scheduling condition, execution of the first task is suspended, and the event monitor is used to monitor a target event occurring during execution of the first task.
14. The device according to claim 13, characterized in that The second operation module is used to: If a target statement is read from the task code of the first task during the execution of the first task, suspending the execution of the first task; The target statement indicates that the successful execution of the first task depends on other asynchronous tasks, or that the successful execution of the first task depends on target resources that have not yet been acquired.
15. The device according to claim 13, characterized in that The second operation module is used to: If a notification message sent by the event monitor is obtained during the execution of the first task, suspending the execution of the first task; The notification message indicates that the target event occurs during the execution of the first task, or that the number of occurrences of the target event is greater than or equal to a target threshold.
16. The device according to any one of claims 11 to 15, characterized in that The third operation module is also used for: If the second task is executed successfully and the first task continues to satisfy the scheduling condition, running the thread to execute at least one third task in the task queue; After each of the third tasks is successfully executed, check whether the first task continues to meet the scheduling condition. If so, run the thread to execute the next third task. If not, run the thread to continue executing the first task.
17. The device according to any one of claims 11 to 16, characterized in that The task structure of each task to be executed includes the thread identifier of the task to be executed, and the thread structure of each thread includes a pointer, which is used to obtain the thread identifier of the task to be executed during the execution of the task to be executed to distinguish different tasks.
18. The device according to any one of claims 11 to 17, characterized in that The task scheduling system is configured in a multi-node system, each node in the multi-node system includes at least one scheduling unit, and the device further includes a fourth operation module, which is used to: The scheduling unit of the first node runs the thread to execute a fourth task in the task queue, where the fourth task indicates data interaction with the second node; If the fourth task meets the scheduling condition, suspend the execution of the fourth task, and run the thread to execute the fifth task in the task queue; If the fifth task is executed successfully and the fourth task no longer satisfies the scheduling condition, the thread is run to continue executing the fourth task.
19. The device according to claim 18, characterized in that The fourth task indicates sending data to the second node; The fourth running module is used to suspend the execution of the fourth task if it is determined that the second node has not yet received the data sent by the first node.
20. The device according to claim 18, characterized in that The fourth task indicates receiving data from the second node; The fourth running module is used to suspend the execution of the fourth task if it is determined that no data has been received from the second node.
21. A computing device, characterized in that The computing device includes a processor and a memory, wherein the memory is used to store at least one section of program code, and the at least one section of program code is loaded by the processor and executes the task scheduling method according to any one of claims 1 to 10.
22. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store at least one section of program code, and the at least one section of program code is used to execute the task scheduling method according to any one of claims 1 to 10.
23. A computer program product, characterized in that When the computer program product is executed on a computing device, the computing device is caused to execute the task scheduling method according to any one of claims 1 to 10.
Citation Information
Cited By
Thread resource release method and device, equipment, medium and program product
CN119781995A
Runtime task scheduling method and system based on hardware abstraction layer, medium and product
CN121614242A