A task scheduling method, system, computing device and readable storage medium
By introducing multiple schedulers, executors and coordination servers into the task scheduling system, and using mechanisms such as task queues and time wheel containers, decentralized scheduling and parallel processing of tasks are achieved, and the imbalance of task load in the existing system is solved. , task loss and excessive system load problems, and improve the system's processing power and reliability.
Patent Information
- Application Number
- CN202010659344.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-09
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2040-07-09
AI Technical Summary
The existing task scheduling system has problems such as unbalanced task load, loss of tasks and excessive system load in the cluster environment, resulting in paralysis of the scheduling system.
A task scheduling method is designed. By introducing multiple schedulers, executors, coordination servers and data storage devices into the task scheduling system, and using mechanisms such as task queues, time wheel containers and task executor queues, the decentralization of tasks is achieved. Scheduling and parallel processing.
Through decentralized scheduling and parallel processing, the problems of unbalanced task load and excessive system load are avoided, the processing capacity and reliability of the system are improved, and the on-time execution of tasks and correct feedback of results are ensured.
Smart Images

Figure CN111949386B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing, and in particular to a task scheduling method, system, computing device and readable storage medium. Background Art
[0002] Task scheduling is very common in business systems. As business diversification leads to different business systems, a unified task scheduling system is needed to manage the task scheduling of each department's business and ensure the normal operation of each department's business.
[0003] There are many ways to implement task scheduling. Common technologies include quartz, spring task, timer, etc., but they are all suitable for single-machine scheduling and not suitable for distributed deployment in a cluster environment. To solve this problem, many open source frameworks have been derived. A typical representative is the secondary development of xxl-job based on the quartz framework. This method is used in the early stage of the merchant platform because the amount of task data in the business system is small, the system executors of the business are also few, and the application scenario is simple. In the cluster environment scheduling machine, all task scheduling is triggered by one of the machines, and the executor is called in the form of remote RPC. Task scheduling is simple, fast and effective. However, this method is not suitable for scenarios with more than 10,000 tasks. Based on the quartz framework, the bottom layer obtains the DB lock in a "preemptive" manner, and the node that successfully seizes the lock is responsible for scheduling all tasks. This leads to a large disparity in node load. Because the number of tasks is large, the node that successfully seizes the lock cannot be processed within the specified time, so that some tasks cannot be scheduled at the specified time. At the same time, when the number of tasks is large, because the executor has been calling the scheduling system through remote RPC, and too many tasks cannot be completed, and the subsequent executor remote RPC feedback results, the scheduling system load is too high, which will eventually cause the scheduling system to paralyze.
[0004] Later, it developed into adding all tasks to the memory thread pool of the preempted machine, and the thread pool started a new thread to remotely call the business executor through RPC. The executor received the scheduling instruction and placed all the task instructions in the memory thread pool. The thread pool then started a new thread to execute the task. After the task was completed, the task execution result was added to the memory thread pool, and the thread pool started a new thread. The remote RPC call scheduling system informed the final execution result. The main disadvantage of this solution is the task loss problem. Since the scheduling tasks are added to the memory thread pool of the machine that successfully preempted the scheduling node, if the task is not completed, the scheduling instance is blocked for some reason and cannot be informed to the executor. All subsequent task instructions and task execution results are also added to the current machine's memory thread pool. If the executor is blocked, all unexecuted tasks cannot be executed, and the executed tasks cannot feedback the results, resulting in subsequent retries and error alarms of the scheduling system. Summary of the invention
[0005] To this end, the present invention provides a task scheduling method, system, computing device and readable storage medium, in an effort to solve or at least alleviate the above problems.
[0006] According to one aspect of the present invention, a task scheduling method is provided, which is suitable for execution in a task scheduling system. The task scheduling system includes multiple schedulers, multiple executors, a coordination server and a data storage device, and the data storage device includes a predetermined number of task queues. The method includes receiving a task to be processed, wherein the task includes an executor, an execution time, and a task identifier, and storing the task in association with the executor in the task queue according to the task identifier; the scheduler obtains the task within the first predetermined time from the corresponding task queue at a first predetermined time, and inserts it into a time wheel container according to the execution time; the scheduler obtains the task at the current moment in the time wheel container at a second predetermined time, and inserts the obtained task into the task executor queue of the executor associated with the task, and the task executor queue is created by the coordination server; the executor obtains the task from the task executor queue for processing, and adds the task execution result to the task result queue, and the task result queue is created by the coordination server; the scheduler obtains the task execution result in the task result queue and stores it in the data storage device.
[0007] Optionally, the task scheduling method according to the present invention further includes: when a scheduler fails, a predetermined number of task queues in the data storage device are reallocated to the remaining non-faulty schedulers.
[0008] Optionally, in the task scheduling method according to the present invention, the scheduler includes multiple scheduler instances, and the scheduler obtains the tasks within the first predetermined time from the corresponding task queue at every first predetermined time, and inserts them into the time wheel container according to the execution time, including: the scheduler instance seizes the pre-pull task lock; if the pre-pull task lock is seized, the scheduler instance obtains the task in the task queue corresponding to the scheduler; if the execution time of the task is less than or equal to the current time minus the first predetermined time, it is discarded; if the execution time of the task is between the current time minus the first predetermined time and the current time, the task is inserted into the task execution queue of the executor corresponding to the task; if the execution time of the task is between the current time and the current time plus the first predetermined time, the task is inserted into the time wheel container.
[0009] Optionally, in the task scheduling method according to the present invention, if the execution time of the task is between the current time minus the first predetermined time and the current time, inserting the task into the task execution queue of the executor corresponding to the task also includes: calculating the next execution time of the task, and if the next execution time of the task is within the current time plus the first predetermined time, adding the task to the time wheel container; and persisting the next execution time of the task to a data storage device.
[0010] Optionally, in the task scheduling method according to the present invention, the executor includes multiple executor instances, and the executor obtains the task from the task executor queue for processing, including: the executor instance detects whether its own processing capability meets the processing conditions; if the processing conditions are met, the executor instance preempts the executor to pull the task lock, and if the preemption is successful, the task is obtained from the task executor queue for processing according to its own processing capability; if the processing conditions are not met, the executor sleeps and waits for a third predetermined time and performs the next detection.
[0011] Optionally, in the task scheduling method according to the present invention, the processing conditions include: the number of available threads and remaining memory of the executor instance.
[0012] Optionally, in the task scheduling method according to the present invention, the task includes a priority, and obtaining the task from the task executor queue for processing further includes: processing the task according to the priority of the task obtained from the task executor queue.
[0013] Optionally, in the task scheduling method according to the present invention, the scheduler obtains the task execution result in the task result queue and stores it in the data storage device, including: the scheduler instance detects whether its own processing capability meets the processing conditions; if the processing conditions are met, the scheduler instance preempts the pull result task lock, if the preemption is successful, it obtains the task execution result from the task result queue according to its own processing capability, and stores the task execution result in the data storage device.
[0014] Optionally, in the task scheduling method according to the present invention, the time span of the annular time wheel container is greater than the first predetermined time.
[0015] Optionally, in the task scheduling method according to the present invention, the coordination server is zookeeper.
[0016] According to another aspect of the present invention, there is provided a task scheduling system, comprising a plurality of schedulers, a plurality of executors, a coordination server and a data storage device, wherein the data storage device comprises a predetermined number of task queues, all of which are assigned to all schedulers, and the data storage device is suitable for storing received tasks to be processed and task execution results, wherein the parameters included in the task include the executor, the execution time and the task identifier, and the data storage device stores the tasks in association with the executors in the task queue according to the task identifier when storing the tasks; the scheduler is suitable for obtaining the tasks within the first predetermined time from the corresponding task queue at intervals of a first predetermined time, and inserting them into a time wheel container according to the execution time, obtaining the tasks at the current moment in the time wheel container at intervals of a second predetermined time, and inserting the tasks into the task executor queue of the executor associated with the task, obtaining the task execution results in the task result queue, and storing them in the data storage device; the executor is suitable for obtaining the tasks from the task executor queue for processing, and sending the task execution results to the task result queue; the coordination server is suitable for creating a task executor queue and a task result queue.
[0017] Optionally, in the task scheduling system according to the present invention, the data storage device is also suitable for when all task queues are allocated to all schedulers: when a scheduler fails, a predetermined number of task queues in the data storage device are reallocated to the remaining non-faulty schedulers.
[0018] Optionally, in the task scheduling system according to the present invention, the scheduler includes multiple scheduler instances, and the scheduler is also suitable for obtaining tasks within a first predetermined time from the corresponding task queue at every first predetermined time, and inserting them into the time wheel container according to the execution time: the scheduler instance preempts the pre-pull task lock; if the pre-pull task lock is preempted, the scheduler instance obtains the task in the task queue corresponding to the scheduler; if the execution time of the task is less than the current time minus the first predetermined time, it is discarded; if the execution time of the task is between the current time minus the first predetermined time and the current time, the task is inserted into the task execution queue of the executor corresponding to the task; if the execution time of the task is between the current time and the current time plus the first predetermined time, the task is inserted into the time wheel container.
[0019] Optionally, in the task scheduling system according to the present invention, the scheduler is also suitable for calculating the next execution time of the task if the execution time of the task is between the current time minus the first predetermined time and the current time; adding the task to the time wheel container if the next execution time of the task is within the current time plus the first predetermined time; and persisting the next execution time of the task in a data storage device.
[0020] Optionally, in the task scheduling system according to the present invention, the executor is also suitable for obtaining tasks from the task executor queue for processing: the executor instance detects whether its own processing capability meets the processing conditions; if the processing conditions are met, the executor instance preempts the executor to pull the task lock, and if the preemption is successful, it obtains the task from the task executor queue for processing according to its own processing capability; if the processing conditions are not met, it sleeps and waits for a third predetermined time and performs the next detection.
[0021] According to another aspect of the present invention, there is provided a computing device, comprising: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be suitable for execution by the at least one processor, and the program instructions include instructions for executing any one of the above task scheduling methods.
[0022] According to another aspect of the present invention, a readable storage medium is provided, which, when the program instructions are read and executed by a computing device, enables the computing device to execute any one of the above task scheduling methods.
[0023] According to the task scheduling scheme of the present invention, a task database is created to contain a predetermined number of task queues. The received tasks to be processed are distributed to all task queues according to the task ID, ensuring that the amount of tasks on each task queue is not much different, and all task queues are dispersed to all schedulers in the corresponding scheduling system. Each scheduler corresponds to a fixed task queue. When the scheduling task is triggered, only the tasks in the corresponding task queue are pulled. All schedulers work in parallel to avoid all tasks falling on one machine, thus achieving decentralization and solving the problem that all machines in the cluster environment of the current framework can only schedule tasks by preempting the DB lock. At the same time, the present invention reduces the pressure of database operations by obtaining messages within a predetermined time, inserting them into a time wheel container, and reading the time wheel regularly, and pulls tasks by multiple executors working in parallel, solving the performance pressure problem of centralized scheduling by the scheduler.
[0024] If a scheduler fails during the operation of the scheduling system, the task queue will be reallocated to a non-faulty scheduler to ensure that the task is not lost. At the same time, the priority of the task is taken into account during task execution to ensure that high-priority tasks are executed first. Furthermore, the executor obtains tasks on demand when executing tasks, which improves the processing capacity of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] To achieve the above and related purposes, certain illustrative aspects are described herein in conjunction with the following description and accompanying drawings, which indicate various ways in which the principles disclosed herein can be practiced, and all aspects and their equivalents are intended to fall within the scope of the claimed subject matter. The above and other purposes, features and advantages of the present disclosure will become more apparent by reading the following detailed description in conjunction with the accompanying drawings. Throughout the present disclosure, the same reference numerals generally refer to the same parts or elements.
[0026] Figure 1 A block diagram of a task scheduling system 100 according to an embodiment of the present invention is shown;
[0027] Figure 2 A block diagram of a computing device 200 according to one embodiment of the present invention is shown;
[0028] Figure 3 A flowchart of a task scheduling method 300 according to an embodiment of the present invention is shown;
[0029] Figure 4 A flowchart of a scheduler pulling tasks according to an embodiment of the present invention is shown;
[0030] Figure 5 A flowchart of an executor scheduling task according to an embodiment of the present invention is shown;
[0031] Figure 6 A flow chart showing the scheduler persisting task execution results according to an embodiment of the present invention. DETAILED DESCRIPTION
[0032] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0033] Figure 1 The block diagram of the task scheduling system according to the embodiment of the present invention is shown. The task scheduling system includes a plurality of schedulers 110, a plurality of executors 120, a coordination server 130 and a data storage device 140. The scheduler 110 is in communication connection with the data storage device 140. Each scheduler and each executor works in parallel. It should be noted that Figure 1 The task scheduling system in the embodiment is only exemplary. In a specific practical situation, the system 100 may have different numbers of schedulers 110 and executors 120. The present invention does not limit the number of each device in the task scheduling system 100.
[0034] The data storage device 140 is used to store the pending tasks received by the scheduling system, which includes multiple task queues. When the scheduling system receives the pending tasks, it will also evenly add the received tasks to all the task queues in the data storage device. The message body of the received task contains information such as the executor, execution time, and task identifier corresponding to the task. The task identifier can be considered as the task serial number. The tasks are added to different task queues according to the task serial number. According to one embodiment of the present invention, the task with serial number 1 is added to task queue 1, the task with serial number 2 is added to task queue 2, and so on. The tasks are added cyclically so that all received tasks are distributed in different task queues. This embodiment is only an illustrative description. In specific practice, different rules can be set for how to allocate tasks according to specific circumstances, and the present invention does not limit this.
[0035] Each scheduler 110 in the scheduling system is fixed to a portion of the task queues in the data storage device 140, and all task queues are assigned to all schedulers. According to one embodiment of the present invention, when a scheduler fails, the task queues are reallocated to the remaining non-faulty schedulers to prevent the failed scheduler from being unable to pull tasks from its corresponding task queue, which ultimately causes the task to fail to execute. The scheduler pulls tasks from the corresponding task queue at predetermined time intervals, and the execution time of the pulled tasks is within the range of the current time plus the predetermined time interval. For example, it pulls tasks once every 40 seconds, and the execution time of the pulled tasks is within 40 seconds. The scheduler is preset with a time wheel container, and the pulled tasks are first inserted into the time wheel container ( Figure 1 (not shown), the scheduler is also preset with a timer, which is used to read the task in the time wheel slot corresponding to the current moment from the time wheel container at regular intervals, and insert the acquired task into the task executor queue 131. This mechanism reduces the operation of the data storage device, reduces the pressure of reading data in the data storage device, and completes the second-level scheduling task locally, ensuring more efficient task scheduling. Another function of the scheduler 110 is to pull the execution result of the task from the result task queue 132 and update it to the data storage device 140.
[0036] The executor 120 is responsible for executing the task, obtaining the task from the executor queue 131, obtaining the task according to its own available threads and memory usage, calling the corresponding callback logic after obtaining the task, and pushing the processing result to the task result queue.
[0037] The scheduling system is also provided with a coordination server 130. The scheduler 110 and the executor 120 can join the scheduling system by registering with the coordination server. At the same time, the coordination scheduler 130 is also responsible for creating and managing the task executor queue 131 and the task result queue 132. According to one embodiment of the present invention, the coordination scheduler 130 can be implemented by zookeeper.
[0038] Each scheduler and each executor in the scheduling system works in parallel, achieving decentralization and avoiding the aggregation of all task queues, which would lead to performance problems caused by the executors pulling tasks. This solves the performance pressure problem caused by centralized scheduling by the scheduler. Each executor pulls tasks on demand, improving the system's launch capacity and performance bottlenecks.
[0039] The scheduler 110, the executor 120, the coordination server 130 and the data storage device in the above task scheduling system can all be implemented by computing devices. Figure 2 1 shows a block diagram of a computing device 200 according to an embodiment of the present invention. It should be noted that: Figure 2 The computing device 200 shown is only an example. In practice, the computing device used to implement the task scheduling method of the present invention can be any type of device, and its hardware configuration can be different from the above. Figure 2 The computing device 200 shown is the same as Figure 2 The computing device 200 shown is different. In practice, the computing device used to implement the data processing method of the present invention can be Figure 2 The hardware components of the computing device 200 shown are increased or deleted, and the present invention does not limit the specific hardware configuration of the computing device.
[0040] like Figure 2 As shown, in a basic configuration 202, computing device 200 typically includes a system memory 206 and one or more processors 204. A memory bus 208 may be used for communication between processor 204 and system memory 206.
[0041] Depending on the desired configuration, the processor 204 can be any type of processor, including but not limited to: a microprocessor (μP), a microcontroller (μC), a digital information processor (DSP), or any combination thereof. The processor 204 can include one or more levels of cache such as a primary cache 210 and a secondary cache 212, a processor core 214, and registers 216. An example processor core 214 can include an arithmetic logic unit (ALU), a floating point unit (FPU), a digital signal processing core (DSP core), or any combination thereof. An example memory controller 218 can be used with the processor 204, or in some implementations, the memory controller 218 can be an internal part of the processor 204.
[0042] Depending on the desired configuration, the system memory 206 can be any type of memory, including but not limited to: volatile memory (such as RAM), non-volatile memory (such as ROM, flash memory, etc.) or any combination thereof. The physical memory in the computing device generally refers to the volatile memory RAM, and the data in the disk needs to be loaded into the physical memory before it can be read by the processor 204. The system memory 206 may include an operating system 220, one or more applications 222, and program data 224. In some embodiments, the application 222 may be arranged to execute instructions on the operating system by one or more processors 204 using program data 224. The operating system 220 may be, for example, Linux, Windows, etc., which includes program instructions for processing basic system services and performing tasks that depend on hardware. The application 222 includes program instructions for implementing various user-desired functions, and the application 222 may be, for example, a browser, instant messaging software, a software development tool (such as an integrated development environment IDE, a compiler, etc.), etc., but is not limited thereto. When the application 222 is installed in the computing device 200, a driver module may be added to the operating system 220.
[0043] When the computing device 200 starts running, the processor 204 reads and executes the program instructions of the operating system 220 from the memory 206. The application 222 runs on the operating system 220 and uses the interfaces provided by the operating system 220 and the underlying hardware to implement various functions desired by the user. When the user starts the application 222, the application 222 is loaded into the memory 206, and the processor 204 reads and executes the program instructions of the application 222 from the memory 206.
[0044] The computing device 200 may also include an interface bus 240 that facilitates communication from various interface devices (e.g., output devices 242, peripheral interfaces 244, and communication devices 246) to the basic configuration 202 via the bus / interface controller 230. Example output devices 142 include a graphics processing unit 248 and an audio processing unit 250. They can be configured to facilitate communication with various external devices such as a display or speakers via one or more A / V ports 252. Example peripheral interfaces 244 may include a serial interface controller 254 and a parallel interface controller 256, which may be configured to facilitate communication with external devices such as input devices (e.g., keyboards, mice, pens, voice input devices, touch input devices) or other peripherals (e.g., printers, scanners, etc.) via one or more I / O ports 258. Example communication devices 246 may include a network controller 260, which may be arranged to facilitate communication with one or more other computing devices 262 via a network communication link via one or more communication ports 264.
[0045] A network communication link can be an example of a communication medium. Communication media can generally be embodied as computer-readable instructions, data structures, program modules in a modulated data signal such as a carrier wave or other transmission mechanism, and can include any information delivery medium. A "modulated data signal" can be a signal in which one or more of its data sets or its changes can be carried out in a manner that encodes information in the signal. As non-limiting examples, communication media can include wired media such as a wired network or a dedicated line network, and various wireless media such as sound, radio frequency (RF), microwave, infrared (IR) or other wireless media. The term computer-readable medium used herein can include both storage media and communication media.
[0046] In the computing device 200 according to the present invention, the application 222 includes instructions for executing the task scheduling method 300 of the present invention, and the instructions can instruct the processor 204 to execute the task scheduling method 300 of the present invention.
[0047] Figure 3 A flowchart of a task scheduling method 300 according to an embodiment of the present invention is shown. The method 300 is executed in a computing device to complete the task scheduling process and record the scheduling result in a data storage device.
[0048] exist Figure 3Before the step S310 shown, the scheduling system needs to be started. During the startup of the scheduling system, the scheduler 110 registers with the coordination server 130 by obtaining the scheduler registration lock, obtains the corresponding task queue in the data storage device 140 based on the task queue allocation algorithm, registers the IP address, port number, scheduler name and corresponding task queue of the current scheduler to the coordination server, and stores them in the data storage device; similarly, the executor 120 registers with the coordination server 130 by obtaining the executor registration lock, registers the IP address, port number and executor name of the current executor to the coordination server, and stores them in the data storage device. According to one embodiment of the present invention, the scheduler adopts an average allocation method when obtaining the corresponding task queue, and the data storage device is implemented by a ring slot (slot), the number of slots is 1024, there are 4 schedulers in the task scheduling system, and each scheduler corresponds to 256 slots. This embodiment is only an exemplary description, and the present invention does not limit the number of slots of the data storage device, the number of schedulers and the allocation method.
[0049] According to another embodiment of the present invention, when a scheduler fails, the card slots are reallocated. Continuing with the above embodiment, when a scheduler fails, 1024 card slots are evenly reallocated to the remaining non-faulty schedulers in an even distribution manner. The first scheduler corresponds to the 1-342 card slots, the second scheduler corresponds to the 343-683 card slots, and the third scheduler corresponds to the 684-1024 card slots.
[0050] like Figure 3 As shown, method 300 begins at step S310, where the task scheduling system receives tasks to be processed, each of which carries information such as the priority information, task ID, executor, execution handler, routing strategy, timeout, task type, executor IP, etc. of the task, and modulos the number of task queues in the data storage device according to the task ID in the task, and assigns the task to the corresponding task queue. Continuing with the example of 1024 card slots in the data storage device, the corresponding relationship between the task and the slot persisted in the data storage device according to the task ID is expanded as shown in Table 1.
[0051] Table 1
[0052]
[0053] According to step S320, the scheduler completes the process of pulling tasks from the data storage device. The specific process of pulling tasks is implemented by the task scheduling thread. At regular intervals, tasks with execution time within a certain period are obtained from the corresponding task queue. For example, the task queues corresponding to the current scheduler are queues 1-queue 20. When pulling tasks, only tasks in queues 1-queue 20 are pulled, and only tasks with execution time within a fixed time are pulled. For example, tasks with execution time within the next 10 seconds are pulled every 10 seconds. Whether to insert the task into the time wheel container is determined based on the execution time of the pulled task. The time wheel container is a circular queue for storing tasks. According to one embodiment of the present invention, the time span corresponding to each slot on the time wheel is 1 second, and the cycle of the entire time wheel is larger than the execution time span of the pulled task. Taking the pulling of tasks within 10 seconds as an example, the cycle of the time wheel cannot be less than 10 seconds to ensure that the pulled task can be inserted into the appropriate slot position of the time wheel container according to the different execution times.
[0054] The scheduler obtains the task at the current moment from the time wheel container through step S330 and inserts it into the task executor queue. Continuing with the above example, the time span of each slot on the time wheel is 1 second, then the task in the next slot is read every second, and the task is inserted into the task executor queue 131 of the corresponding executor according to the executor corresponding to the task. According to one embodiment of the present invention, this step can be implemented by a timer.
[0055] Step S330 implements the process of the executor obtaining tasks from the task executor queue for processing and returning results. Each executor can deploy multiple instances, each of which will start a thread for looping and pulling tasks, and generate a thread pool with a fixed number of working threads to execute tasks. The number of threads is configurable. When pulling tasks, the executor instance pulls tasks on demand based on the number of remaining idle threads and memory. When processing tasks, the executor processes them in order of priority, first processing high-priority tasks, and adding the processed results to the task result queue 132.
[0056] The execution results in the task result queue are updated to the data storage device by the scheduler in step S350. When the scheduler instance pulls the task results, it also pulls them on demand based on its own idle threads and memory for persistence.
[0057] Figure 4 The flowchart of the scheduler pulling tasks according to an embodiment of the present invention is shown, which is also a detailed description of the above step S320.
[0058] The scheduler can deploy multiple scheduler instances. The process of the scheduler instance pulling tasks begins in step S410. Each scheduler instance obtains the opportunity to pull tasks by preempting the pre-pull task lock. If the pre-pull task lock fails to be preempted, it continues to wait for the pre-pull task lock to be preempted.
[0059] If the preemption is successful, the process goes to step S420 to pull tasks whose execution time is within the predetermined time. According to an embodiment A of the present invention, tasks whose execution time is within 30 seconds are pulled. The current time is 11:27:30, and 5 tasks are pulled. The execution time of task 1 is 11:26:50, the execution time of task 2 is 11:26:55, the execution time of task 3 is 11:27:15, the execution time of task 4 is 11:27:25, and the execution time of task 5 is 11:27:40.
[0060] Then enter step S430 to determine whether the task execution time is less than or equal to the current time minus the first scheduled time. Continuing with example A, if the judgment results of task 1 and task 2 are true, enter step S440, discard the task, ignore this scheduling, and wait for the next scheduling.
[0061] If the judgment result of Task 3, Task 4, and Task 5 in step S430 is false, then go to step S450 to determine whether the task execution time is less than or equal to the current time. In this step, if the judgment result of Task 5 is false, then go directly to step S490 to add Task 5 to the time wheel container.
[0062] If the judgment result of task 3 and task 4 in S450 is false, the process goes to step S460 to directly trigger this scheduling, and puts task 3 and task 4 into the task execution queue of the corresponding executor according to the executor corresponding to them.
[0063] Then, the process proceeds to step S470 to calculate the next execution time of task 3 and task 4. According to one embodiment of the present invention, the next execution time of task 3 is 11:27:45, and the next execution time of task 4 is 11:30:00.
[0064] Then, the process proceeds to step S480 to determine whether the next execution time of the task is within the scheduled time.
[0065] If the judgment result of step S480 is true, go to step S485. In example A, the next execution time of task 3 is within the scheduled time of 30 seconds, so task 3 is added to the time wheel container to complete the next scheduling, and the next scheduling information of task 3 is persisted to the data storage device. The next scheduling time of task 4 is not within 30 seconds and is not processed.
[0066] Figure 5A flowchart of an executor scheduling task according to an embodiment of the present invention is shown. Figure 3 Further refinement of S340.
[0067] The executor can deploy multiple instances. When scheduling tasks, the executor instance will generate a thread pool for executing tasks. The number of threads is configurable. The process starts at step S510. The executor instance determines whether the idle threads and memory of the current executor instance meet the preset conditions. According to one embodiment of the present invention, if the current executor instance does not have idle threads for executing tasks, it is necessary to wait for a certain period of time for the next judgment. The specific waiting time can be configured, and the present invention does not limit this.
[0068] According to another embodiment of the present invention, the current executor instance has 50 idle threads and 70% of the memory remaining, which meets the execution conditions, and then enters step S520, the executor instance preempts the pull task lock. If the preemption fails, it continues to wait for obtaining the pull task lock.
[0069] If the preemption is successful, enter step S530 and pull tasks according to the processing capacity of the current executor instance. According to one embodiment of the present invention, the executor instance can process 50 tasks based on its processing capacity. In this case, 50 tasks are pulled this time. The number of pulled tasks corresponding to the remaining processing capacity of the specific executor is not limited by the present invention. The pulled tasks need to be deleted from the task executor queue.
[0070] When processing tasks, the executor processes them according to the priority order of the tasks, and processes the tasks with higher priority first. In a specific example, the execution time of tasks A, B and C is the same, but the priority of task A is 2, the priority of task B is 3, and the priority of task C is 1 (the priority gradually decreases from 1 to 3), then the order of task processing is task C, task A, and task B. After the executor instance processes the tasks, it will proceed to step S540 and insert the task execution results into the task result queue. The task result queue does not correspond to the executor.
[0071] Figure 6 A flowchart showing the results of executing a persistent task by a scheduler according to an embodiment of the present invention is shown. Figure 3 Further refinement of step S350.
[0072] The process of the scheduler persisting the task execution results begins at step S610. The scheduler instance detects its own processing capabilities, including the number of available threads and memory usage. According to one embodiment of the present invention, if the detection result is that the processing conditions are not met, the scheduler will sleep for a certain period of time and wait for the next detection. The present invention does not limit the specific waiting time. According to a specific example, the waiting time can be 1 second.
[0073] If the processing condition of the scheduler instance meets the processing condition, the process proceeds to step S620 to seize the pull result task lock. If the seizure fails, the process continues to wait for obtaining the pull result lock.
[0074] If the preemption is successful, the process proceeds to step S630, and the task execution results are obtained from the task result queue as needed based on the processing capability. For example, if the processing capability of the scheduler instance can pull 100 task results for persistence, then 100 task execution results are pulled this time and persisted in the data storage device.
[0075] According to the task scheduling scheme of the present invention, a task database is created to contain a predetermined number of task queues. The received tasks to be processed are distributed to all task queues according to the tasks, ensuring that the amount of tasks on each task queue is not much different, and all task queues are dispersed to all schedulers in the corresponding scheduling system. Each scheduler corresponds to a fixed task queue. When a scheduling task is triggered, only the tasks in the corresponding task queue are pulled. All schedulers work in parallel to avoid all tasks falling on one machine, thus achieving decentralization and solving the problem that all machines in the cluster environment of the current framework can only schedule tasks by one instance of the node that successfully seizes the DB lock. At the same time, the present invention reduces the pressure of database operations by obtaining messages within a predetermined time, inserting them into a time wheel container, and reading the time wheel regularly, and pulls tasks by multiple executors working in parallel, solving the performance pressure problem of centralized scheduling by the scheduler.
[0076] If a scheduler fails during the operation of the scheduling system, the task queue will be reallocated to a non-faulty scheduler to ensure that the task is not lost. At the same time, the priority of the task is taken into account during task execution to ensure that high-priority tasks are executed first. Furthermore, the executor obtains tasks on demand when executing tasks, which improves the processing capacity of the system.
[0077] The various techniques described herein may be implemented in combination with hardware or software, or a combination thereof. Thus, the method and apparatus of the present invention, or some aspects or parts of the method and apparatus of the present invention may be in the form of program codes (i.e., instructions) embedded in a tangible medium, such as a removable hard disk, a USB flash drive, a floppy disk, a CD-ROM, or any other machine-readable storage medium, wherein when the program is loaded into a machine such as a computer and executed by the machine, the machine becomes a device for practicing the present invention.
[0078] In the case where the program code is executed on a programmable computer, the computing device generally includes a processor, a storage medium readable by the processor (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device. The memory is configured to store the program code; the processor is configured to execute the task scheduling method of the present invention according to the instructions in the program code stored in the memory.
[0079] By way of example and not limitation, readable media include readable storage media and communication media. Readable storage media stores information such as computer readable instructions, data structures, program modules or other data. Communication media generally embody computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and include any information transfer medium. Any combination of the above is also included within the scope of readable media.
[0080] In the description provided herein, algorithms and displays are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the examples of the present invention. According to the above description, it is obvious that the structure required for constructing such systems. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages can be utilized to implement the content of the present invention described herein, and the above description of specific languages is for the purpose of disclosing the best mode of the present invention.
[0081] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0082] It should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed invention requires more features than those explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.
[0083] Those skilled in the art will appreciate that the modules or units or components of the devices in the examples disclosed herein may be arranged in the devices described in the embodiment, or alternatively may be located in one or more devices different from the devices in the examples. The modules in the foregoing examples may be combined into one module or may be divided into multiple submodules.
[0084] The present invention also includes:
[0085] A6. A method as described in A5, wherein the processing conditions include: the number of available threads and remaining memory of the executor instance.
[0086] A7. The method as described in A5, wherein the task includes a priority, and the obtaining of the task from the task executor queue for processing further comprises:
[0087] Process the tasks obtained from the task executor queue according to their priority.
[0088] A8. A method as described in any one of A1-A7, wherein the scheduler obtains the task execution results in the task result queue and stores them in the data storage device, comprising:
[0089] The scheduler instance detects whether its processing capacity meets the processing conditions;
[0090] If the processing conditions are met, the scheduler instance preempts the pull result task lock. If the preemption is successful, the scheduler instance obtains the task execution result from the task result queue according to its own processing capability, and stores the task execution result in the data storage device.
[0091] A9. A method as described in any one of A1-A8, wherein the time span of the annular time wheel container is greater than the first predetermined time.
[0092] A10. A method as described in any one of A1-A9, wherein the coordination server is zookeeper.
[0093] B14. The task scheduling system as described in B13, wherein the scheduler is further adapted to:
[0094] If the execution time of the task is between the current time minus the first scheduled time and the current time, calculate the next execution time of the task;
[0095] If the next execution time of the task is within the current time plus the first predetermined time, then the task is added to the time wheel container;
[0096] And the next execution time of the task is persisted in the data storage device.
[0097] B15. A task scheduling system as described in any one of B11 to B14, wherein the executor is further adapted to, when obtaining a task from a task executor queue for processing:
[0098] The executor instance detects whether its processing capacity meets the processing conditions;
[0099] If the processing conditions are met, the executor instance preempts the executor to pull the task lock. If the preemption is successful, it obtains the task from the task executor queue for processing according to its own processing capacity;
[0100] If the processing condition is not met, the system will sleep and wait for a third predetermined time before performing the next detection.
[0101] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0102] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0103] In addition, some of the embodiments are described herein as methods or combinations of method elements that can be implemented by a processor of a computer system or by other devices that perform the functions. Therefore, a processor with necessary instructions for implementing the method or method elements forms a device for implementing the method or method elements. In addition, the elements described herein of the device embodiments are examples of devices for implementing the functions performed by the elements for the purpose of implementing the invention.
[0104] As used herein, unless otherwise specified, the use of ordinal numbers "first," "second," "third," etc. to describe common objects merely indicates that different instances of similar objects are involved, and is not intended to imply that the objects so described must have a given order in time, space, order, or in any other manner.
[0105] Although the present invention has been described according to a limited number of embodiments, it will be apparent to those skilled in the art, with the benefit of the above description, that other embodiments may be envisioned within the scope of the invention thus described. In addition, it should be noted that the language used in this specification is selected primarily for readability and teaching purposes, rather than for explaining or defining the subject matter of the present invention. Therefore, many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the appended claims. The disclosure of the present invention is illustrative, not restrictive, with respect to the scope of the present invention, which is defined by the appended claims.
Claims
1. A task scheduling method, the task scheduling method is suitable for execution in a task scheduling system, the task scheduling system includes multiple schedulers, multiple executors, a coordination server and a data storage device, the scheduler includes multiple scheduler instances, the data storage device includes a predetermined number of task queues, wherein: The method comprises, Receive a task to be processed, the task including an executor, an execution time, and a task identifier, and store the task in a task queue in association with the executor according to the task identifier; The scheduler obtains tasks within the first scheduled time from the corresponding task queue at intervals of the first scheduled time, and inserts the tasks into the time wheel container according to the execution time, specifically including: the scheduler instance seizes the pre-pull task lock, if the pre-pull task lock is seized, the scheduler instance obtains the tasks in the task queue corresponding to the scheduler, if the execution time of the task is less than or equal to the current time minus the first scheduled time, then the task is discarded, if the execution time of the task is between the current time minus the first scheduled time and the current time, then the task is inserted into the task execution queue of the executor corresponding to the task, if the execution time of the task is between the current time and the current time plus the first scheduled time, then the task is inserted into the time wheel container, wherein, if the execution time of the task is between the current time minus the first scheduled time and the current time, then the task is inserted into the task execution queue of the executor corresponding to the task also includes: calculating the next execution time of the task, if the next execution time of the task is within the current time plus the first scheduled time, then the task is added to the time wheel container, and the next execution time of the task is persisted in the data storage device; The scheduler obtains the current task in the time wheel container at every second predetermined time, and inserts the obtained task into the task executor queue of the executor associated with the task, wherein the task executor queue is created by the coordination server; The executor obtains the task from the task executor queue for processing, and adds the task execution result to the task result queue, wherein the task result queue is created by the coordination server, wherein the executor includes multiple executor instances, and the executor obtains the task from the task executor queue for processing, including: the executor instance detects whether its own processing capacity meets the processing conditions, if the processing conditions are met, the executor instance seizes the executor to pull the task lock, if the seizure is successful, then the task is obtained from the task executor queue for processing according to its own processing capacity, if the processing conditions are not met, then it sleeps and waits for a third predetermined time, and performs the next detection; The scheduler obtains the task execution results in the task result queue and stores them in the data storage device; When a scheduler fails, a predetermined number of task queues in the data storage device are reallocated to the remaining non-faulty schedulers.
2. The method of claim 1, wherein: The processing conditions include: the number of available threads and remaining memory of the executor instance.
3. The method of claim 1, wherein: The task includes a priority, and the acquiring of the task from the task executor queue for processing further includes: Process the tasks obtained from the task executor queue according to their priority.
4. The method of claim 1, wherein: The scheduler obtains the task execution results in the task result queue and stores them in the data storage device, including: The scheduler instance detects whether its processing capacity meets the processing conditions; If the processing conditions are met, the scheduler instance preempts the pull result task lock. If the preemption is successful, the scheduler instance obtains the task execution result from the task result queue according to its own processing capability, and stores the task execution result in the data storage device.
5. The method of claim 1, wherein: The time span of the time wheel container is greater than the first predetermined time.
6. The method of claim 1, wherein: The coordination server is zookeeper.
7. A task scheduling system, comprising a plurality of schedulers, a plurality of executors, a coordination server and a data storage device, wherein: The data storage device comprises a predetermined number of task queues, all of which are assigned to all schedulers. The data storage device is suitable for storing received tasks to be processed and task execution results, wherein the parameters included in the task include an executor, an execution time, and a task identifier. When storing tasks, the data storage device associates the tasks with the executors according to the task identifiers and stores them in the task queues. The data storage device is also suitable for reallocating the predetermined number of task queues in the data storage device to the remaining non-faulty schedulers when all task queues are assigned to all schedulers and a scheduler fails. The scheduler includes multiple scheduler instances, which are suitable for obtaining tasks within a first predetermined time from a corresponding task queue at a first predetermined time interval, and inserting the tasks into a time wheel container according to the execution time, obtaining the tasks at the current time in the time wheel container at a second predetermined time interval, and inserting the tasks into the task executor queue of the executor associated with the task, obtaining the task execution results in the task result queue, and storing them in a data storage device. The scheduler obtains the tasks within the first predetermined time from the corresponding task queue at a first predetermined time interval, and inserts the tasks into the time wheel container according to the execution time. Specifically, the scheduler instance seizes the pre-pull task lock. If the pre-pull task lock is seized, the scheduler instance obtains the tasks in the task queue corresponding to the scheduler. If the execution time of the task is less than or equal to If the execution time of the task is between the current time minus the first scheduled time and the current time, the task is discarded; if the execution time of the task is between the current time minus the first scheduled time and the current time, the task is inserted into the task execution queue of the executor corresponding to the task; if the execution time of the task is between the current time and the current time plus the first scheduled time, the task is inserted into the time wheel container, wherein if the execution time of the task is between the current time minus the first scheduled time and the current time, the task is inserted into the task execution queue of the executor corresponding to the task further includes: calculating the next execution time of the task; if the next execution time of the task is within the current time plus the first scheduled time, the task is added to the time wheel container, and the next execution time of the task is persisted in the data storage device; The executor is adapted to obtain tasks from the task executor queue for processing and send the task execution results to the task result queue, wherein the executor includes multiple executor instances, and the executor obtains tasks from the task executor queue for processing, including: the executor instance detects whether its own processing capacity meets the processing conditions, if the processing conditions are met, the executor instance seizes the executor to pull the task lock, if the seizure is successful, then the task is obtained from the task executor queue for processing according to its own processing capacity, if the processing conditions are not met, then it sleeps and waits for a third predetermined time, and performs the next detection; The coordination server is suitable for creating a task executor queue and a task result queue.
8. A computing device comprising: at least one processor; as well as A memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, and the program instructions include instructions for executing the method according to any one of claims 1 to 6.
9. A readable storage medium storing program instructions, when the program instructions are read and executed by a computing device, the computing device executes the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Multi-queue multi-priority big data task management system and method for achieving big data task management by utilizing system
CN104657214A
Timed task scheduling optimization method and system based on memory database in container
CN111274013A