A task scheduling method and device

By judging the availability of the registration center in the task scheduling system and using historical scheduling or re-formulating the scheduling plan, the problem of insufficient stability and availability of the task scheduling system in the existing technology is solved, and the fault tolerance of the system and the efficiency of task execution are improved. reliability.

CN113342508BActive Publication Date: 2024-08-23HUNAN HAPPLY SUNSHINE INTERACTIVE ENTERTAINMENT MEDIA CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110769168.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-07
Publication Date
2024-08-23
Estimated Expiration
2041-07-07

AI Technical Summary

Technical Problem

The existing task scheduling system has poor stability and usability. Especially when the registration center (such as MySQL database or Zookeeper) fails, it will seriously affect the system's operational capabilities.

Method used

In the task scheduling method, the availability of the registration center is judged on the target business server. When the registration center is unavailable, the historical scheduling method is used to process the tasks to be executed; when the registration center is available, it is judged whether the scheduling plan needs to be re-formulated, and if necessary Initiate the master node election process and formulate a new scheduling plan to improve the reliability of task execution.

Benefits of technology

It reduces the dependence on the registration center, improves the stability and availability of the task scheduling system, and ensures that tasks can still be processed in time when the registration center fails.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113342508B
    Figure CN113342508B
Patent Text Reader

Abstract

The present invention provides a task scheduling method and device. Each time a task to be executed is executed, it is determined whether a registration center is available; if it is not available, the task to be executed is processed according to the cached historical scheduling method; if it is available, it is determined whether to re-formulate a scheduling plan; if it does not need to re-formulate a scheduling plan and it is a master node, the task to be executed is executed and other slave nodes are triggered to execute the task to be executed; if it is necessary to re-formulate a scheduling plan, a master node election process is initiated to the registration center; if it becomes the master node after initiating the master node election process, a new scheduling plan is formulated, the task to be executed is executed and the slave node specified by the new scheduling plan is triggered to execute the task to be executed; if it does not need to re-formulate a scheduling plan and it is a slave node, or, if it is a slave node after initiating the master node election process, a trigger signal sent by the master node is received to execute the task to be executed. The dependence on the registration center is reduced, and the stability and availability of the task scheduling system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] When Internet applications develop to a certain scale, it is usually necessary to abstract a task scheduling system to perform task scheduling. The current task scheduling systems are usually divided into two categories: centralized task scheduling systems (such as xxl-job) and decentralized task scheduling systems (such as Elastic-job).

[0003] However, the operation of xxl-job depends on the availability of the MySQL database. When the MySQL database fails, the task scheduling capability of xxl-job will be seriously affected. The operation of Elastic-job depends on the availability of Zookeeper. When the entire Zookeeper cluster fails, Elastic-job will be unavailable. In other words, the existing task scheduling system has poor stability and poor availability. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a task scheduling method and device to solve the problems of poor stability and poor availability of the existing task scheduling system.

[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0006] A first aspect of an embodiment of the present invention discloses a task scheduling method, which is applicable to a target business server, where the target business server is any business server in a business server cluster, and the method includes:

[0007] Each time a pre-configured task to be executed starts, determine whether the registration center is available;

[0008] If the registration center is unavailable, the task to be executed is processed according to a historical scheduling method pre-cached in the target service server, where the historical scheduling method is a method for processing the task to be executed in a previous scheduling cycle;

[0009] If the registration center is available, judging whether to re-formulate a scheduling plan for the task to be executed based on the status of all business servers in the business server cluster, wherein the scheduling plan is used to specify the business servers in the business server cluster that need to execute the task to be executed;

[0010] If the scheduling plan is not re-formulated, the following steps are performed;

[0011] If the scheduling plan is re-formulated, a master node election process is initiated to the registration center, and the other service servers in the service server cluster compete for the master node, and the following steps are performed;

[0012] The following steps include:

[0013] Determine whether the target service server is a master node;

[0014] If the target business server is a master node and the scheduling scheme is not re-formulated, the task to be executed is executed, and all slave nodes specified by the scheduling scheme are triggered to execute the task to be executed, and each of the available slave nodes corresponds to any business server in the business server cluster;

[0015] If the target business server is the master node and the scheduling scheme is re-formulated, a new scheduling scheme is formulated according to all available slave nodes in the registration center, the tasks to be executed are executed, and all slave nodes specified by the new scheduling scheme are triggered to execute the tasks to be executed;

[0016] If the target business server is a slave node, it receives a trigger signal sent by the master node and executes the task to be executed.

[0017] Preferably, if the registration center is available, judging whether to re-formulate the scheduling plan of the task to be executed based on the status of all business servers in the business server cluster includes:

[0018] If the registration center is available, determining whether to add or reduce a business server in the business server cluster based on the status of all business servers in the business server cluster;

[0019] If a business server is added or reduced in the business server cluster, determining to re-formulate a scheduling plan for the task to be executed;

[0020] If no new service server is added or reduced in the service server cluster, it is determined not to redefine the scheduling plan.

[0021] Preferably, if the scheduling scheme is reformulated, a master node election process is initiated to the registration center to compete for the master node with other service servers in the service server cluster, including:

[0022] If the scheduling plan is to be re-formulated, a master node election process is initiated to the registration center, and it is determined whether the task allocation mark and task global information of the task to be executed exist in the registration center;

[0023] If the task allocation mark and / or the task global information exists in the registration center, register the server information of the target service server with the registration center, so that the target service server becomes a slave node;

[0024] If the task allocation mark and the task global information do not exist in the registration center, set the task allocation mark and register the task global information to the registration center, and register the server information of the target business server to the registration center to make the target business server a master node.

[0025] Preferably, if the target business server is a master node and the scheduling scheme is re-formulated, a new scheduling scheme is formulated according to all available slave nodes in the registration center, the tasks to be executed are executed, and all slave nodes specified by the new scheduling scheme are triggered to execute the tasks to be executed, including:

[0026] If the target business server is the master node and the scheduling plan is re-formulated, the IP addresses of all available slave nodes in the registration center are captured, and a new scheduling plan is formulated according to a preset algorithm;

[0027] executing the task to be performed,

[0028] For each slave node specified by the new scheduling scheme, a trigger signal is sent to the slave node according to the IP of the slave node, so that the slave node executes the task to be executed.

[0029] Preferably, each time a pre-configured task to be executed starts to be executed, determining whether the registration center is available includes:

[0030] Query the health indicators of the registry center each time a pre-configured task to be executed begins;

[0031] Whether the registration center is available is determined according to the health indicator.

[0032] Preferably, if the registration center is unavailable, the to-be-executed task is processed according to a historical scheduling method pre-cached in the target service server, including:

[0033] If the registration center is unavailable, determining whether the target service server has executed the task to be executed in the last scheduling cycle according to the historical scheduling mode pre-cached in the target service server;

[0034] If the target service server has not executed the task to be executed in the last scheduling period, the task to be executed is not executed;

[0035] If the target service server executes the task to be executed in the last scheduling period, the task to be executed is executed.

[0036] Preferably, it also includes:

[0037] The execution information of the task to be executed is uploaded to a preset database.

[0038] Preferably, after formulating a new scheduling scheme according to all available slave nodes in the registration center, the method further includes:

[0039] The new scheduling plan is uploaded to the registration center.

[0040] A second aspect of an embodiment of the present invention discloses a task scheduling device, which is applicable to a target business server, and the target business server is any business server in a business server cluster, and the device includes:

[0041] A first judgment unit is used to judge whether the registration center is available each time a pre-configured task to be executed starts to be executed;

[0042] A first processing unit, configured to process the to-be-executed task according to a historical scheduling method pre-cached in the target service server if the registration center is unavailable, wherein the historical scheduling method is a method of processing the to-be-executed task in a previous scheduling cycle;

[0043] A second judgment unit is used to judge whether to re-formulate a scheduling scheme for the task to be executed based on the status of all business servers in the business server cluster if the registration center is available, wherein the scheduling scheme is used to specify the business server in the business server cluster that needs to execute the task to be executed;

[0044] The second processing unit is configured to execute the following steps if the scheduling scheme is not re-formulated; if the scheduling scheme is re-formulated, initiate a master node election process to the registration center, compete for the master node with other business servers in the business server cluster, and execute the following steps;

[0045] The following steps include:

[0046] Determine whether the target service server is a master node;

[0047] If the target business server is a master node and the scheduling scheme is not re-formulated, the task to be executed is executed, and all slave nodes specified by the scheduling scheme are triggered to execute the task to be executed, and each of the available slave nodes corresponds to any business server in the business server cluster;

[0048] If the target business server is the master node and the scheduling scheme is re-formulated, a new scheduling scheme is formulated according to all available slave nodes in the registration center, the tasks to be executed are executed, and all slave nodes specified by the new scheduling scheme are triggered to execute the tasks to be executed;

[0049] If the target business server is a slave node, it receives a trigger signal sent by the master node and executes the task to be executed.

[0050] Preferably, the second judgment unit is specifically used to: if the registration center is available, determine whether new business servers are added or reduced in the business server cluster based on the status of all business servers in the business server cluster; if new business servers are added or reduced in the business server cluster, determine to re-formulate the scheduling plan for the task to be executed; if no new business servers are added or reduced in the business server cluster, determine not to re-formulate the scheduling plan.

[0051] Based on the above-mentioned embodiment of the present invention, a task scheduling method and device are provided. The method is applicable to a target business server, and the target business server is any business server in a business server cluster. The method is as follows: when the task to be executed starts to be executed each time, it is determined whether the registration center is available; if the registration center is not available, the task to be executed is processed according to the historical scheduling method cached in the target business server; if the registration center is available, it is determined whether to re-formulate the scheduling plan for the task to be executed; if the scheduling plan does not need to be re-formulated and it is a master node, the task to be executed is executed and other slave nodes are triggered to execute the task to be executed; if the scheduling plan needs to be re-formulated, a master node election process is initiated to the registration center; if it becomes the master node after initiating the master node election process, a new scheduling plan is formulated, the task to be executed is executed and all slave nodes specified by the new scheduling plan are triggered to execute the task to be executed; if the scheduling plan does not need to be re-formulated and it is a slave node, or if it becomes a slave node after initiating the master node election process, a trigger signal sent by the master node is received to execute the task to be executed. Reduce the dependence on the registration center and improve the stability and availability of the task scheduling system. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0053] Figure 1 A flowchart of a task scheduling method provided by an embodiment of the present invention;

[0054] Figure 2 A schematic diagram of the connection between the configuration layer, execution layer, support layer and storage layer provided in an embodiment of the present invention;

[0055] Figure 3 Another flow chart of a task scheduling method provided by an embodiment of the present invention;

[0056] Figure 4 Another flow chart of a task scheduling method provided by an embodiment of the present invention;

[0057] Figure 5 A flowchart of the process of initiating a master node election to a registration center provided by an embodiment of the present invention;

[0058] Figure 6 Another flow chart of the process of initiating master node election to the registration center provided by an embodiment of the present invention;

[0059] Figure 7 A structural block diagram of a task scheduling device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0060] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0061] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.

[0062] As can be seen from the background technology, the categories of existing task scheduling systems are generally divided into centralized task scheduling systems such as xxl-job and decentralized task scheduling systems such as Elastic-job. However, the operation of xxl-job depends on the availability of the MySQL database. When the MySQL database fails, the task scheduling capability of xxl-job will be seriously affected. The operation of Elastic-job depends on the availability of Zookeeper. When the entire Zookeeper cluster fails, Elastic-job will be unavailable. That is, the existing task scheduling system has poor stability and poor availability.

[0063] Therefore, an embodiment of the present invention provides a task scheduling method and device, which is applicable to a target business server belonging to any business server in a business server cluster. Each time the task to be executed starts, the registration center is monitored to see whether it is available. When the registration center is not available, the task to be executed is processed using a pre-cached historical scheduling method. When the registration center is available, it is determined whether it is necessary to re-formulate the scheduling plan for the task to be executed. If it is not necessary to re-formulate the scheduling plan and it is a master node, the task to be executed is executed and other slave nodes are triggered to execute the task to be executed; if it is necessary to re-formulate the scheduling plan, a master node election process is initiated to the registration center; if it becomes the master node after initiating the master node election process, a new scheduling plan is formulated, the task to be executed is executed and all slave nodes specified by the new scheduling plan are triggered to execute the task to be executed; if it is not necessary to re-formulate the scheduling plan and it is a slave node, or if it becomes a slave node after initiating the master node election process, it receives the trigger signal sent by the master node and executes the task to be executed. Reduce the dependence on the registration center to improve the stability and availability of the task scheduling system.

[0064] It should be noted that the English abbreviations and their meanings involved in the embodiments of the present invention are explained in advance through the following content.

[0065] SDK: Software Development Kit, software development kit.

[0066] SideCar: A distributed task scheduling client (provided in the form of an SDK), usually integrated into a business server, also known as a task node.

[0067] It should be noted here that in the same task, nodes are divided into master nodes and slave nodes, but the identity of the same node in different tasks may be different. For example, in task A, node 1 is the master node, and in task B, node 1 is the slave node.

[0068] Executor: Task executor, which implements the Executor interface provided by SideCar for the business server. Executor is the execution subject of the task.

[0069] Gateway: Gateway provides data upload results to SideCar and an operation interface for editing tasks to the Control Panel.

[0070] ControlPanel: console, that is, management background.

[0071] Job Status Management: Task status management, mainly providing an interface for interacting with the database.

[0072] Monitor: Monitoring and management module, mainly used for alarm and collection of reported data indicators.

[0073] See also Figure 1 , shows a flowchart of a task scheduling method provided by an embodiment of the present invention, the task scheduling method is applicable to a target business server, the target business server is any business server in a business server cluster, the task scheduling method includes:

[0074] Step S101: When a pre-configured task to be executed starts to be executed each time, it is determined whether the registration center is available. If the registration center is not available, step S102 is executed; if the registration center is available, step S103 is executed.

[0075] It should be noted that the task configuration of the task to be executed is pre-configured. Specifically, a support layer can be defined, through which the task configuration of various tasks can be completed (the task configuration of the task is configured using the Control Panel). At the same time, the support layer also provides functions such as gateway (Gateway), task status management (Job Status Management), task exception compensation and task monitoring (Monitor).

[0076] It can be understood that the tasks to be executed are executed according to a preset cycle. The business server (including the target business server) mainly includes the SideCar and Executor mentioned above, and the business server is set in a predefined execution layer. When the SideCar of the target business server is started, it listens to events from the registration center, for example: listening to task configuration change events such as modification, suspension and manual execution.

[0077] In the specific implementation of step S101, each time the task to be executed starts, the SideCar of the target business server determines whether the registration center is available. If the registration center is not available, step S102 is executed, and if the registration center is available, step S103 is executed.

[0078] It should be noted that all business servers in the business server cluster can be used as nodes and registered to the registration center (such as Zookeeper) through connection. Each node has a connection-level health check and is uploaded to the above-mentioned support layer. Therefore, in some specific embodiments, the SideCar of the target business server queries the health index of the registration center each time the task to be executed starts, and determines whether the registration center is available based on the health index. The health index is obtained by summarizing the connection health status of all nodes collected by the support layer.

[0079] The registration center mentioned above can be set in a predefined configuration layer. The configuration layer mainly uses the registration center to complete node leader election (that is, the election of the master node mentioned in the following steps), task allocation (equivalent to the scheduling plan mentioned in the following steps) and configuration changes (configuration of tasks in the Control Panel, such as creating new tasks, modifying tasks, starting tasks and stopping tasks).

[0080] It can be understood that node master election specifically means: multiple task nodes (that is, SideCars of multiple business servers) compete for a distributed lock, and the business server that competes for the distributed lock is the master node. It should be noted that each pre-configured task needs to select a master node, rather than all tasks sharing one master node.

[0081] Step S102: Processing the tasks to be executed according to the historical scheduling method pre-cached in the target service server.

[0082] It should be noted that the historical scheduling method is the way to handle pending tasks in the previous scheduling cycle. All nodes will be triggered by a cache task by the scheduled task framework (such as Quartz) to cache the way to handle pending tasks in the previous scheduling cycle. The purpose is to allow each node (that is, each business server) to record whether the pending tasks in the previous scheduling cycle were executed by itself.

[0083] In the process of implementing step S102, if it is determined that the registration center is unavailable, the SideCar of the target business server determines whether the target business server executes the task to be executed in the previous scheduling cycle according to the historical scheduling method pre-cached in the target business server; if the target business server did not execute the task to be executed in the previous scheduling cycle, the task to be executed will not be executed (equivalent to skipping); if the target business server executed the task to be executed in the previous scheduling cycle, the task to be executed will be executed.

[0084] For example, if the target business server is business server A, and business server A determines that the registration center is unavailable, it determines whether it has executed the task to be executed in the last scheduling cycle. If it is determined that it has executed the task to be executed in the last scheduling cycle, it executes the task to be executed; if it is determined that it has not executed the task to be executed in the last scheduling cycle, it skips it.

[0085] Step S103: Based on the status of all business servers in the business server cluster, determine whether to re-formulate the scheduling plan for the task to be executed. If the scheduling plan is not to be re-formulated, execute step S105 and subsequent steps. If the scheduling plan is to be re-formulated, execute step S104.

[0086] It should be noted that the scheduling scheme is used to specify the business servers in the business server cluster that need to execute the tasks to be executed, that is, to allocate the tasks to be executed to certain business servers in the business server cluster for execution (ie, task allocation).

[0087] In the process of implementing step S103, if the target business server determines that the registration center is available, based on the status of all business servers in the business server cluster, it is determined whether a new business server is added or reduced in the business server cluster (that is, it is determined whether a business server in the business server cluster has changed). If a new business server is added or reduced in the business server cluster, it is determined to re-formulate a scheduling plan for the tasks to be executed (equivalent to the need to re-assign the tasks to be executed), and step S104 is executed. If no new business server is added or reduced in the business server cluster, it is determined not to re-formulate a scheduling plan, and step S105 and subsequent steps are executed.

[0088] Step S104: Initiate a master node election process to the registration center, compete with other business servers in the business server cluster for the master node, and execute step S105 and subsequent steps.

[0089] In the process of implementing step S104, if the target business server determines to re-formulate the scheduling plan, the target business server initiates a master node election process to the registration center and competes with other business servers in the business server cluster for the master node. After the master node election process is completed, the target business server becomes the master node or slave node.

[0090] It is understandable that the business server that becomes the master node needs to complete the formulation of the scheduling plan (that is, task allocation), register the global task information of the tasks to be executed, set the task allocation mark of the tasks to be executed, and clean up the tasks.

[0091] It should be noted that task cleaning specifically means that the master node takes the slave node offline so that the tasks on the offline slave node are not executed.

[0092] The task allocation mark is specifically used to indicate that a scheduling plan is being formulated (that is, task allocation is being performed). Specifically, for concurrent safety considerations, a corresponding task allocation mark needs to be set when formulating a task scheduling plan, indicating that the task is undergoing a scheduling plan.

[0093] Step S105: Determine whether the target service server is a master node. If the target service server is a master node and the scheduling plan is not re-formulated, execute step S106; if the target service server is a master node and the scheduling plan is re-formulated, execute step S107; if the target service server is a slave node, execute step S108.

[0094] In the process of implementing step S105, after the target business server initiates the master node election process to the registration center, it can be determined whether the target business server is the master node. At this time, if the target business server is the master node and the scheduling plan is not re-formulated, step S106 is executed; if the target business server is the master node and the scheduling plan is re-formulated, step S107 is executed; if the target business server is a slave node, step S108 is executed.

[0095] It is understandable that if the target business server is a slave node, regardless of whether a new scheduling plan is required, step S108 is executed, and the task to be executed is executed as long as a trigger signal sent by the master node is received.

[0096] Step S106: If the target business server is a master node and the scheduling plan is not re-formulated, the task to be executed is executed, and all slave nodes specified by the scheduling plan are triggered to execute the task to be executed.

[0097] It should be noted that each available slave node corresponds to any business server in the business server cluster.

[0098] In the process of implementing step S106, if the target business server is the master node and the scheduling plan is not re-formulated, it means that the current scheduling plan does not need to be changed. At this time, the target business server executes the task to be executed and triggers all slave nodes specified by the scheduling plan to execute the task to be executed according to the scheduling plan (equivalent to the originally formulated scheduling plan).

[0099] For each slave node specified by the scheduling scheme, the target business server sends a trigger signal to the slave node through the registration center according to the IP of the slave node, so that the slave node executes the task to be executed.

[0100] It should be noted that the service servers in the service server cluster are pre-registered in the registration center, and the registration center contains the registration information of all pre-registered service servers (including the IP addresses of the service servers).

[0101] Specifically, the SideCar of the target business server is triggered by a scheduled task framework (such as quartz), and the Executor executor of the target business server executes the task to be executed.

[0102] Step S107: If the target business server is the master node and the scheduling plan is re-formulated, a new scheduling plan is formulated according to all available slave nodes in the registration center, the tasks to be executed are executed, and all slave nodes specified by the new scheduling plan are triggered to execute the tasks to be executed.

[0103] In the process of implementing step S107, if the target business server is the master node and the scheduling plan is re-formulated, the target business server captures the IP addresses of all available slave nodes in the registration center, and selects the node that needs to execute the task to be executed according to a preset algorithm (such as polling, hash, random and failover algorithms), thereby formulating a new scheduling plan, which specifies which business servers in the business server cluster need to execute the task to be executed (that is, specify the Job Owner).

[0104] After the target business server formulates a new scheduling plan, the SideCar of the target business server is triggered by the scheduled task framework (such as quartz), and the Executor executor of the target business server executes the task to be executed.

[0105] For each slave node specified by the new scheduling scheme, the target business server sends a trigger signal to the slave node through the registration center according to the IP of the slave node, so that the slave node executes the task to be executed. In other words, the target business server triggers the executor executors of all slave nodes specified by the new scheduling scheme through the registration center to execute the task to be executed.

[0106] It should be noted that the service servers in the service server cluster are pre-registered in the registration center, and the registration center contains the registration information of all pre-registered service servers (including the IP addresses of the service servers).

[0107] Preferably, after the target business server completes the execution of the task to be executed, the SideCar of the target business server reports the execution information of the task to be executed (such as the task execution start time, end time, execution status, time consumption, etc.) to the Gateway of the support layer, and uploads the execution information of the task to be executed to a preset database (such as Redis) through the Gateway of the support layer. It is understandable that the database is set in a predefined storage layer. When the support layer and / or storage layer fails, the execution information of the task to be executed cannot be uploaded to the database. At this time, the target business server can cache the execution information of the task to be executed in the local queue, and upload the execution information of the task to be executed to the storage layer for storage after the support layer and storage layer are normal.

[0108] It should be noted that after other slave nodes execute the tasks to be executed, they also need to upload the execution information of the tasks to be executed to the storage layer. For details, please refer to the above-mentioned target business server uploading the execution information of the tasks to be executed, which will not be repeated here.

[0109] Preferably, after the target business server formulates a new scheduling plan, the new scheduling plan is uploaded to the registration center.

[0110] Step S108: Receive the trigger signal sent by the master node and execute the task to be executed.

[0111] In the process of implementing step S108, if the target business server is a slave node, regardless of whether the scheduling plan needs to be re-formulated, when the target business server receives the trigger signal sent by the master node (the master node in this case is other business servers in the business server cluster), the target business server executes the task to be executed and uploads the execution information of the task to be executed to the storage layer. The specific uploading method can be found in the content of step S107 and will not be repeated here.

[0112] In an embodiment of the present invention, each time a task to be executed begins to be executed, the registration center is monitored to see whether it is available. When the registration center is not available, the task to be executed is processed using a pre-cached historical scheduling method. When the registration center is available, it is determined whether it is necessary to re-formulate the scheduling plan for the task to be executed. If it is not necessary to re-formulate the scheduling plan and it is the master node, the task to be executed is executed and other slave nodes are triggered to execute the task to be executed. If it is necessary to re-formulate the scheduling plan, a master node election process is initiated to the registration center. After initiating the master node election process, if it becomes the master node, a new scheduling plan is formulated, the task to be executed is executed and all slave nodes specified by the new scheduling plan are triggered to execute the task to be executed. If it is not necessary to re-formulate the scheduling plan and it is a slave node, or if it becomes a slave node after initiating the master node election process, it receives the trigger signal sent by the master node and executes the task to be executed. Reduce dependence on the registration center and improve the stability and availability of the task scheduling system.

[0113] To facilitate understanding of the above embodiments of the present invention Figure 1 The configuration layer, execution layer, support layer and storage layer mentioned in each step are Figure 2 The connection diagram between the configuration layer, execution layer, support layer and storage layer is shown for explanation.

[0114] like Figure 2 The configuration layer 100 is provided with a registration center such as Zookeeper, the execution layer 200 is provided with a business server, each business server includes at least an Executor and a SideCar, the support layer 300 is provided with a Gateway, a Control Panel, a Job Status Management and a Monitor, and the storage layer 400 is provided with a database such as Redis.

[0115] The configuration layer 100 is connected to the execution layer 200 and the support layer 300 respectively, the execution layer 200 is connected to the support layer 300 , and the support layer 300 is connected to the storage layer 400 .

[0116] It is understood that in order to better explain the above embodiments of the present invention Figure 1 The contents of each step in Figure 3 and Figure 4 The contents shown are explained by way of example.

[0117] See also Figure 3 , shows another flow chart of a task scheduling method provided by an embodiment of the present invention, including the following steps:

[0118] Step S301: The administrator logs in to the Control Panel and creates a new task to be executed.

[0119] In the specific implementation of step S301, after logging into the console, the administrator can create a new task to be executed, for example, a new "task executed every 5 seconds" is created. At this time, the task to be executed can be started, and the basic information of the task to be executed is saved in the registration center.

[0120] Step S302: After the SideCar of the target business server is started, it registers the online node with the registration center and completes the master election to become the master node.

[0121] Step S303: The target business server determines the namespace controller of the task to be executed.

[0122] It should be noted that the namespace controller is a namespace, which is used to distinguish different tasks.

[0123] Step S304: The target business server monitors the registration center and formulates a scheduling plan.

[0124] In the specific implementation of step S304, when formulating the scheduling plan, it mainly includes two steps: allocating tasks and allocating JobOwner.

[0125] It should be noted that if no scheduling plan is formulated for the task to be executed (that is, equivalent to no task assignment mark), the default value of the scheduling plan is 1, and a Job Owner needs to be assigned at this time.

[0126] Step S305: The target service server uploads the scheduling plan to the registration center.

[0127] See also Figure 4 , shows another flow chart of a task scheduling method provided by an embodiment of the present invention, the task scheduling method is applicable to a target business server, and the task scheduling method includes the following steps:

[0128] Step S401: Each time a task to be executed starts to be executed, it is determined whether the registration center is available. If the registration center is available, step S402 is executed. If the registration center is not available, the Executor is executed to process the task to be executed according to the historical scheduling method pre-cached in the target business server.

[0129] Step S402: Determine whether to re-formulate the scheduling plan of the task to be executed. If the scheduling plan of the task to be executed is to be re-formulated, execute step S403; if the scheduling plan of the task to be executed is not to be re-formulated, execute step S404.

[0130] Step S403: Initiate the master node election process to the registration center and determine whether the master node election process is completed. If the master node election process is completed, execute step S404. If the master node election process is not completed, sleep for 100ms and return to execute the step of determining whether the master node election process is completed.

[0131] Step S404: Determine whether the target service server is a master node. If the target service server is not a master node, execute step S405; if the target service server is a master node, execute step S406.

[0132] Step S405: Determine whether the scheduling plan for the task to be executed is being formulated. If the scheduling plan for the task to be executed is being formulated, sleep for 100ms and return to execute step S405. If the scheduling plan for the task to be executed has been formulated and a trigger signal sent by the master node is received, execute the Executor to execute the task to be executed.

[0133] Step S406: Write the task allocation mark into the registration center.

[0134] Step S407: completing the task allocation of tasks to be executed.

[0135] In the specific implementation of step S407, the task allocation of the tasks to be executed is mainly divided into two situations: one situation is that if the scheduling plan does not need to be re-formulated and the target business server is the master node, the task allocation of the tasks to be executed is directly completed according to the original scheduling plan. The other situation is that if the scheduling plan needs to be re-formulated and the target business server is the master node, a new scheduling plan for the tasks to be executed is formulated at this time, and the task allocation of the tasks to be executed is completed according to the new scheduling plan.

[0136] Step S408: According to the IP of the slave node specified by the scheduling scheme or the new scheduling scheme, determine whether each slave node is executing the task to be executed. If it is executing the task to be executed, then end; if it is not executing the task to be executed, trigger each slave node to execute the Executor to execute the task to be executed.

[0137] It is understandable that the IP of each slave node can be obtained from the registration center, and the storage layer can be queried based on the IP to determine whether each slave node is executing the task to be executed.

[0138] It should be noted that Figure 4 The contents of each step are for illustration only.

[0139] The above embodiments of the present invention Figure 1 The process of the target service server electing the master node in step S104 is described in detail in Figure 5, shows a flowchart of a process of initiating a master node election by a registration center provided in an embodiment of the present invention, including the following steps:

[0140] Step S501: Initiate the master node election process to the registration center and determine whether there is a task assignment mark and task global information of the task to be executed in the registration center. If there is a task assignment mark and / or task global information in the registration center, execute step S502; if there is no task assignment mark and task global information in the registration center, execute step S503.

[0141] In the specific implementation of step S501, after the target business server initiates the master node election process to the registration center, it is determined whether the registration center already has the task allocation mark of the task to be executed and the registered task global information set by other business servers. If the registration center already has the task allocation mark and / or task global information of the task to be executed, step S502 is executed; if the registration center does not have the task allocation mark and task global information of the task to be executed, step S503 is executed.

[0142] Step S502: registering the server information of the target service server with the registration center, making the target service server a slave node.

[0143] In the process of implementing step S502, if the registration center already has the task assignment mark and / or task global information of the task to be executed, the target business server registers the server information of the target business server with the registration center, persists the server information of the target business server in the registration center, and makes the target business server a slave node.

[0144] Step S503: Setting the task allocation mark to the registration center and registering the task global information, and registering the server information of the target service server to the registration center, so that the target service server becomes the master node.

[0145] In the process of implementing step S503, if the task assignment mark and task global information of the task to be executed do not exist in the registration center, the target business server sets the task assignment mark of the task to be executed to the registration center and registers the task global information of the task to be executed, and registers the server information of the target business server with the registration center, persists the task assignment mark of the task to be executed in the registration center, and persists the task global information of the task to be executed and the server information of the target business server in the registration center, so that the target business server becomes the master node.

[0146] To better explain how the target service server competes for the master node with other service servers in the service server cluster (or how multiple service servers compete for the master node), Figure 6Another flowchart of initiating the master node election process to the registration center is provided for illustration.

[0147] It should be noted that in Figure 6 The figure takes two business servers (business server A and business server B) as an example to explain if there is an election for the master node, and the election result is that business server A becomes the master node. The following steps S601-S611 are steps for business server A to initiate the master node election process to the registration center, and steps S612-S622 are steps for business server B to initiate the master node election process to the registration center.

[0148] It is worth noting that Figure 6 The startup sequence of the business server A, the registration center, and the business server B shown in the figure is: the registration center starts first, followed by the business server A, and the business server B starts last. Finally, the business server A becomes the master node, and the business server A first sets the task allocation mark of the task to be executed and registers the task global information of the task to be executed in the registration center. The business server B learns from the information fed back by the registration center that the task allocation mark of the task to be executed and the task global information of the task to be executed already exist, so the business server B is the slave node.

[0149] Figure 6 Another flowchart of initiating the master node election process to the registration center is provided, including the following steps:

[0150] Step S601: Business server A monitors the registration center.

[0151] Step S602: Business server A initiates a master node election process to the registration center.

[0152] Step S603: The registration center conducts master node election.

[0153] Step S604: Business server A becomes the master node.

[0154] Step S605: Business server A sets a task allocation mark for the task to be executed and sends it to the registration center.

[0155] Step S606: The registration center makes the task allocation mark of the task to be executed permanent.

[0156] Step S607: Business server A registers the task global information of the task to be executed.

[0157] Step S608: The registration center persists the global task information of the task to be executed.

[0158] Step S609: Business server A registers the server information of business server A.

[0159] Step S610: The registration center makes the server information of the business server A permanent.

[0160] Step S611: Business server A waits for the task to be executed to run.

[0161] Step S612: Business server B monitors the registration center.

[0162] Step S613: Business server B initiates a master node election process to the registration center.

[0163] Step S614: The registration center conducts master node election.

[0164] Step S615: Business server B becomes a slave node.

[0165] Step S616: Business server B sets a task allocation mark for the task to be executed and sends it to the registration center.

[0166] Step S617: the registration center determines that the task allocation mark of the task to be executed already exists, and does not persist the task allocation mark of the task to be executed sent by the business server B.

[0167] Step S618: Business server B registers the task global information of the task to be executed.

[0168] Step S619: the registration center determines that the task global information of the task to be executed already exists, and does not persist the task global information of the task to be executed registered by the business server B.

[0169] Step S620: Business server B registers the server information of business server B.

[0170] Step S621: The registration center makes the server information of the business server B permanent.

[0171] Step S622: Business server B waits for the task to be executed to run.

[0172] In an embodiment of the present invention, the target business server monitors the registration center, and initiates a master node election process to the registration center each time a task to be executed is executed. After the master node election process is completed, the target business server becomes a master node or a slave node. If the target business server is a master node, a new scheduling plan is formulated according to all available slave nodes in the registration center to execute the task to be executed, and all slave nodes specified by the new scheduling plan are triggered to execute the task to be executed. If the target business server is a slave node, it receives a trigger signal sent by the master node and executes the task to be executed. Reduce the dependence on the registration center and improve the stability and availability of the task scheduling system.

[0173] Corresponding to a task scheduling method provided by the above embodiment of the present invention, see Figure 7 , the embodiment of the present invention also provides a structural block diagram of a task scheduling device, the task scheduling device is applicable to a target business server, the target business server is any business server in a business server cluster, the task scheduling device includes: a first judgment unit 701, a first processing unit 702, a second judgment unit 703 and a second processing unit 704;

[0174] The first judging unit 701 is used to judge whether the registration center is available each time a pre-configured task to be executed starts to be executed.

[0175] In a specific implementation, the first judgment unit 701 is specifically used to: query the health indicator of the registration center each time the pre-configured task to be executed starts to be executed; and judge whether the registration center is available according to the health indicator.

[0176] The first processing unit 702 is configured to process the to-be-executed task according to a historical scheduling method pre-cached in the target service server if the registration center is unavailable, where the historical scheduling method is a method of processing the to-be-executed task in a previous scheduling cycle.

[0177] In the specific implementation, the first processing unit 702 is specifically used to: if the registration center is unavailable, determine whether the target business server executes the task to be executed in the previous scheduling cycle based on the historical scheduling method pre-cached in the target business server; if the target business server did not execute the task to be executed in the previous scheduling cycle, then do not execute the task to be executed; if the target business server executed the task to be executed in the previous scheduling cycle, then execute the task to be executed.

[0178] The second judgment unit 703 is used to judge whether to re-formulate a scheduling plan for the task to be executed based on the status of all business servers in the business server cluster if the registration center is available. The scheduling plan is used to specify the business servers in the business server cluster that need to execute the task to be executed.

[0179] In the specific implementation, the second judgment unit 703 is specifically used for: if the registration center is available, based on the status of all business servers in the business server cluster, determining whether new business servers are added or reduced in the business server cluster; if new business servers are added or reduced in the business server cluster, determining to re-formulate the scheduling plan for the tasks to be executed; if no new business servers are added or reduced in the business server cluster, determining not to re-formulate the scheduling plan.

[0180] The second processing unit 704 is configured to execute the following steps if the scheduling plan is not to be re-formulated; if the scheduling plan is to be re-formulated, initiate a master node election process to the registration center, compete for the master node with other business servers in the business server cluster, and execute the following steps;

[0181] The following steps include:

[0182] Determine whether the target business server is a primary node;

[0183] If the target business server is the master node and the scheduling plan is not re-formulated, the pending tasks are executed and all slave nodes specified by the scheduling plan are triggered to execute the pending tasks. Each available slave node corresponds to any business server in the business server cluster;

[0184] If the target business server is the master node and the scheduling plan is re-formulated, a new scheduling plan is formulated based on all available slave nodes in the registration center, the pending tasks are executed, and all slave nodes specified by the new scheduling plan are triggered to execute the pending tasks;

[0185] If the target business server is a slave node, it receives the trigger signal sent by the master node and executes the task to be executed.

[0186] In the specific implementation, the second processing unit 704 is specifically used for: if the target business server is the master node and the scheduling plan is re-formulated, the IP addresses of all available slave nodes in the registration center are captured, and a new scheduling plan is formulated according to a preset algorithm; executing the tasks to be executed, for each slave node specified by the new scheduling plan, a trigger signal is sent to the slave node according to the IP address of the slave node, so that the slave node executes the tasks to be executed.

[0187] In an embodiment of the present invention, each time a task to be executed begins to be executed, the registration center is monitored to see whether it is available. When the registration center is not available, the task to be executed is processed using a pre-cached historical scheduling method. When the registration center is available, it is determined whether it is necessary to re-formulate the scheduling plan for the task to be executed. If it is not necessary to re-formulate the scheduling plan and it is the master node, the task to be executed is executed and other slave nodes are triggered to execute the task to be executed. If it is necessary to re-formulate the scheduling plan, a master node election process is initiated to the registration center. After initiating the master node election process, if it becomes the master node, a new scheduling plan is formulated, the task to be executed is executed and all slave nodes specified by the new scheduling plan are triggered to execute the task to be executed. If it is not necessary to re-formulate the scheduling plan and it is a slave node, or if it becomes a slave node after initiating the master node election process, it receives the trigger signal sent by the master node and executes the task to be executed. Reduce dependence on the registration center and improve the stability and availability of the task scheduling system.

[0188] Preferably, combined Figure 7 The content shown, the second processing unit 704 for initiating the master node election process to the registration center includes: a determination module, a first registration module and a second registration module, and the execution principle of each module is as follows:

[0189] The determination module is used to initiate the master node election process to the registration center if the scheduling plan is re-formulated, and to determine whether there are task allocation tags and task global information of the tasks to be executed in the registration center.

[0190] The first registration module is used to register the server information of the target business server with the registration center if there is a task allocation mark and / or task global information in the registration center, so that the target business server becomes a slave node.

[0191] The second registration module is used to set the task allocation mark and register the task global information to the registration center if the task allocation mark and task global information do not exist in the registration center, and register the server information of the target business server with the registration center to make the target business server the main node.

[0192] In an embodiment of the present invention, the target business server monitors the registration center, and initiates a master node election process to the registration center each time a task to be executed is executed. After the master node election process is completed, the target business server becomes a master node or a slave node. If the target business server is a master node, a new scheduling plan is formulated according to all available slave nodes in the registration center to execute the task to be executed, and all slave nodes specified by the new scheduling plan are triggered to execute the task to be executed. If the target business server is a slave node, it receives a trigger signal sent by the master node and executes the task to be executed. Reduce the dependence on the registration center and improve the stability and availability of the task scheduling system.

[0193] Preferably, combined Figure 7 The task scheduling device further includes:

[0194] The first uploading unit is used to upload the execution information of the task to be executed to a preset database.

[0195] Preferably, combined Figure 7 The task scheduling device further includes:

[0196] The second uploading unit is used to upload the new scheduling plan to the registration center.

[0197] In summary, an embodiment of the present invention provides a task scheduling method and device. In the embodiment of the present invention, each time the execution of a task to be executed begins, the registration center is monitored to see whether it is available. When the registration center is not available, the task to be executed is processed using a pre-cached historical scheduling method. When the registration center is available, it is determined whether it is necessary to re-formulate the scheduling scheme for the task to be executed. If the scheduling scheme does not need to be re-formulated and it is a master node, the task to be executed is executed and other slave nodes are triggered to execute the task to be executed. If the scheduling scheme needs to be re-formulated, a master node election process is initiated to the registration center. If it becomes the master node after initiating the master node election process, a new scheduling scheme is formulated, the task to be executed is executed and all slave nodes specified by the new scheduling scheme are triggered to execute the task to be executed. If it does not need to re-formulate the scheduling scheme and it is a slave node, or if it becomes a slave node after initiating the master node election process, it receives a trigger signal sent by the master node and executes the task to be executed. Reduce the dependence on the registration center and improve the stability and availability of the task scheduling system.

[0198] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.

[0199] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0200] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A task scheduling method, characterized in that: The method is applicable to a target service server, which is any service server in a service server cluster. The method includes: Each time a pre-configured task to be executed starts, determine whether the registration center is available; If the registration center is unavailable, the task to be executed is processed according to a historical scheduling method pre-cached in the target service server, where the historical scheduling method is a method for processing the task to be executed in a previous scheduling cycle; If the registration center is available, judging whether to re-formulate a scheduling plan for the task to be executed based on the status of all business servers in the business server cluster, wherein the scheduling plan is used to specify the business servers in the business server cluster that need to execute the task to be executed; If the scheduling plan is not re-formulated, the processing flow is executed; If the scheduling plan is re-formulated, a master node election process is initiated to the registration center, the master node is elected with other service servers in the service server cluster, and the processing flow is executed; The processing flow includes: Determine whether the target service server is a master node; If the target business server is a master node and the scheduling scheme is not re-formulated, the task to be executed is executed, and all slave nodes specified by the scheduling scheme are triggered to execute the task to be executed, and each of the available slave nodes corresponds to any business server in the business server cluster; If the target business server is the master node and the scheduling scheme is re-formulated, a new scheduling scheme is formulated according to all available slave nodes in the registration center, the tasks to be executed are executed, and all slave nodes specified by the new scheduling scheme are triggered to execute the tasks to be executed; If the target business server is a slave node, it receives a trigger signal sent by the master node and executes the task to be executed.

2. The method according to claim 1, characterized in that If the registration center is available, judging whether to re-formulate a scheduling plan for the task to be executed based on the status of all business servers in the business server cluster includes: If the registration center is available, determining whether to add or reduce a business server in the business server cluster based on the status of all business servers in the business server cluster; If a business server is added or reduced in the business server cluster, determining to re-formulate a scheduling plan for the task to be executed; If no new service server is added or reduced in the service server cluster, it is determined not to redefine the scheduling plan.

3. The method according to claim 1, characterized in that If the scheduling plan is re-formulated, a master node election process is initiated to the registration center to compete for the master node with other service servers in the service server cluster, including: If the scheduling plan is to be re-formulated, a master node election process is initiated to the registration center, and it is determined whether the task allocation mark and task global information of the task to be executed exist in the registration center; If the task allocation mark and / or the task global information exists in the registration center, register the server information of the target service server with the registration center, so that the target service server becomes a slave node; If the task allocation mark and the task global information do not exist in the registration center, set the task allocation mark and register the task global information to the registration center, and register the server information of the target business server to the registration center to make the target business server a master node.

4. The method according to claim 1, characterized in that If the target business server is the master node and the scheduling scheme is re-formulated, a new scheduling scheme is formulated according to all available slave nodes in the registration center, the tasks to be executed are executed, and all slave nodes specified by the new scheduling scheme are triggered to execute the tasks to be executed, including: If the target business server is the master node and the scheduling plan is re-formulated, the IP addresses of all available slave nodes in the registration center are captured, and a new scheduling plan is formulated according to a preset algorithm; executing the task to be performed, For each slave node specified by the new scheduling scheme, a trigger signal is sent to the slave node according to the IP of the slave node, so that the slave node executes the task to be executed.

5. The method according to claim 1, characterized in that Each time a pre-configured task to be executed starts, it is determined whether the registration center is available, including: Query the health indicators of the registry center each time a pre-configured task to be executed begins; Whether the registration center is available is determined according to the health indicator.

6. The method according to claim 1, characterized in that If the registration center is unavailable, the to-be-executed task is processed according to the historical scheduling method pre-cached in the target service server, including: If the registration center is unavailable, determining whether the target service server has executed the task to be executed in the last scheduling cycle according to the historical scheduling mode pre-cached in the target service server; If the target service server has not executed the task to be executed in the last scheduling period, the task to be executed is not executed; If the target service server executes the task to be executed in the last scheduling period, the task to be executed is executed.

7. The method according to claim 1, characterized in that Also includes: The execution information of the task to be executed is uploaded to a preset database.

8. The method according to claim 1, characterized in that After formulating a new scheduling scheme according to all available slave nodes in the registration center, the method further includes: The new scheduling plan is uploaded to the registration center.

9. A task scheduling device, characterized in that: The device is applicable to a target service server, and the target service server is any service server in a service server cluster. The device includes: A first judgment unit is used to judge whether the registration center is available each time a pre-configured task to be executed starts to be executed; A first processing unit, configured to process the to-be-executed task according to a historical scheduling method pre-cached in the target service server if the registration center is unavailable, wherein the historical scheduling method is a method of processing the to-be-executed task in a previous scheduling cycle; A second judgment unit is used to judge whether to re-formulate a scheduling scheme for the task to be executed based on the status of all business servers in the business server cluster if the registration center is available, wherein the scheduling scheme is used to specify the business server in the business server cluster that needs to execute the task to be executed; The second processing unit is configured to execute the processing flow if the scheduling plan is not re-formulated; if the scheduling plan is re-formulated, initiate a master node election process to the registration center, compete for the master node with other business servers in the business server cluster, and execute the processing flow; The processing flow includes: Determine whether the target service server is a master node; If the target business server is a master node and the scheduling scheme is not re-formulated, the task to be executed is executed, and all slave nodes specified by the scheduling scheme are triggered to execute the task to be executed, and each of the available slave nodes corresponds to any business server in the business server cluster; If the target business server is the master node and the scheduling scheme is re-formulated, a new scheduling scheme is formulated according to all available slave nodes in the registration center, the tasks to be executed are executed, and all slave nodes specified by the new scheduling scheme are triggered to execute the tasks to be executed; If the target business server is a slave node, it receives a trigger signal sent by the master node and executes the task to be executed.

10. The device according to claim 9, characterized in that The second judgment unit is specifically used to: if the registration center is available, determine whether new business servers are added or reduced in the business server cluster based on the status of all business servers in the business server cluster; if new business servers are added or reduced in the business server cluster, determine to re-formulate the scheduling plan for the task to be executed; if no new business servers are added or reduced in the business server cluster, determine not to re-formulate the scheduling plan.