Distributed task scheduling system, method, device, medium and product
By using the Redis database and ZooKeeper monitoring mechanism in the distributed task scheduling system, the problems of scheduling delay and low efficiency in traditional methods are solved, and efficient task scheduling and failover are achieved.
Patent Information
- Application Number
- CN202410267910.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-08
- Publication Date
- 2024-10-18
AI Technical Summary
Traditional distributed task scheduling methods have problems with scheduling delays and low efficiency in large-scale scheduling scenarios, especially for second-level tasks, and the database lock mechanism increases task scheduling delays.
Use the Redis database as the scheduler, pull scheduling tasks from the Redis database through the task scheduling module, and obtain thread execution tasks from the thread pool, use ZooKeeper client and cluster manager threads to monitor task execution status, and implement distributed lock mechanisms to Avoid preemption and failover.
It improves the efficiency and accuracy of distributed task scheduling, reduces scheduling delays, and achieves precise timing triggering and failover of tasks.
Smart Images

Figure CN118796502A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a distributed task scheduling system, method, device, medium and product. Background Art
[0002] At present, both Internet applications and enterprise-level applications inevitably need some scheduled tasks to trigger the execution of tasks. As the number of enterprise systems increases, they gradually evolve from single applications to microservice clusters. In distributed cluster systems, the main problems are: repeated execution of tasks, no unified scheduled task configuration and scheduling, task node failover, task execution monitoring, etc. A series of functions need to be solved through distributed task scheduling.
[0003] Traditional distributed task scheduling is based on the database scheduler implementation of the job scheduling framework (Quartz framework), and relies on database locks to implement distributed task scheduling. This method will significantly increase scheduling delays in large-scale scheduling scenarios, especially for second-level tasks. Despite horizontal expansion of nodes, the scheduling delay of second-level tasks will not decrease, and the overall scheduling performance has not improved significantly, but has become worse. At the same time, in the process of implementing distributed task scheduling, the database scheduler will start a transaction when accessing the database, which will cause the relational database (MySQL database) to lock the table, aggravating the task scheduling delay. Therefore, the traditional distributed task scheduling method will result in a slower speed of distributed task scheduling and a lower accuracy for timed triggered tasks, resulting in lower efficiency of distributed task scheduling. Summary of the invention
[0004] The present invention provides a distributed task scheduling system, method, device, medium and product, which are used to solve the problem of low efficiency of distributed task scheduling in the prior art.
[0005] In a first aspect, the present invention provides a distributed task scheduling system, including a scheduling resource management module and a task scheduling module;
[0006] The task scheduling module is used to pull the first scheduling task from the remote dictionary service Redis database;
[0007] The scheduling resource management module is used to obtain a thread from a thread pool and use the thread to execute the first scheduling task.
[0008] In one embodiment, the task scheduling module includes a task pulling unit and a task monitoring unit:
[0009] The task pulling unit is used to obtain a task scheduling request, and based on the task scheduling request, pull the first scheduling task from the Redis database;
[0010] The task monitoring unit is used to start a ZooKeeper client thread and a cluster manager thread in response to the task scheduling request, and monitor the execution status of the first scheduling task based on the ZooKeeper client thread and the cluster manager thread; the ZooKeeper client thread is used to monitor the state change of the thread and send the state change of the thread to the cluster manager thread; the cluster manager thread is used to manage the first scheduling task associated with the thread based on the state change of the thread.
[0011] In one embodiment, the task monitoring unit is further used to:
[0012] Based on the monitoring by the ZooKeeper client thread, the thread assigned by the first scheduling task is in an abnormal offline state;
[0013] Sending information that the thread is in an abnormal offline state to the cluster manager thread based on the ZooKeeper client thread;
[0014] Based on the cluster manager thread, information that the thread is in an abnormal offline state and the first scheduling task are sent to the scheduling resource management module.
[0015] In one embodiment, the scheduling resource management module is further used to:
[0016] Removing the thread from the thread pool;
[0017] The remaining threads are obtained from the thread pool, and the remaining threads are used to execute the first scheduling task; the remaining threads refer to the remaining idle threads in the thread pool except the thread in the abnormal offline state.
[0018] In one embodiment, the distributed task scheduling system further includes a scheduling task registration module and a scheduling type change module;
[0019] The scheduling task registration module is used to write the approved first scheduling task into the Redis database; the first scheduling task refers to a task to be executed based on the scheduling type of the Redis database;
[0020] The scheduling type changing module is used to change the scheduling type of the second scheduling task to the scheduling type of the first scheduling task; the scheduling type of the second scheduling task is task scheduling based on a relational database.
[0021] In a second aspect, the present invention further provides a distributed task scheduling method, comprising:
[0022] Pull the first scheduling task from the remote dictionary service Redis database;
[0023] A thread is obtained from a thread pool, and the thread is used to execute the first scheduling task.
[0024] In one embodiment, the distributed task scheduling method further includes:
[0025] When responding to the task scheduling request, a ZooKeeper client thread and a cluster manager thread are started, and the execution status of the first scheduling task is monitored based on the ZooKeeper client thread and the cluster manager thread.
[0026] In a third aspect, the present invention provides a device, comprising an electronic device, wherein the electronic device comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the distributed task scheduling method as described in any one of the above are implemented.
[0027] In a fourth aspect, the present invention further provides a medium, comprising a non-transitory computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of any of the above-mentioned distributed task scheduling methods are implemented.
[0028] In a fifth aspect, the present invention also provides a product, comprising a computer program product, wherein the computer program product comprises a computer program, wherein the computer program can be stored on a non-transitory computer-readable storage medium, and wherein when the computer program is executed by the processor, the steps of any of the above-described distributed task scheduling methods are implemented.
[0029] The distributed task scheduling system, method, device, medium and product provided by the present invention periodically pull the first scheduling task from the Redis database through the task scheduling module, further obtain the thread from the thread pool through the scheduling resource management module, and use the thread to execute the first scheduling task. Since the Redis database is a high-performance database based on memory and can provide faster reading and writing speeds, the first scheduling task is stored in the memory of Redis, and the task scheduling module can quickly read data in the Redis database. In addition, during the scheduling process, the distributed task scheduling system can refine the acquisition and response triggers through the distributed lock mechanism provided by the Redis database to avoid the delay of precise scheduling caused by preempting the distributed lock, and realize the precise scheduling of the timed triggered tasks, thereby improving the efficiency of distributed task scheduling. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0031] Figure 1 This is one of the structural diagrams of the distributed task scheduling system provided by the present invention;
[0032] Figure 2 It is a structural diagram of the task scheduling module provided by the present invention;
[0033] Figure 3 This is the second structural diagram of the distributed task scheduling system provided by the present invention;
[0034] Figure 4 It is a flow chart of the distributed task scheduling method provided by the present invention;
[0035] Figure 5 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are 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.
[0037] The terms "first", "second", etc. in the present invention are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention can be implemented in an order other than those illustrated or described herein.
[0038] Combine the following Figure 1-Figure 5 The distributed task scheduling system, method, device, medium and product provided by the present invention are described.
[0039] It should be noted that the distributed task scheduling system provided in the embodiment of the present invention is mainly based on large-scale scheduling scenarios. In order to meet the needs of pulling scheduled tasks, a scheduler based on the Redis database is introduced, and a customized scheduler based on the Redis database of the Quartz framework is implemented to replace the default relational database (Mysql database) scheduler, thereby improving query efficiency and ensuring the accuracy of the execution of scheduled tasks.
[0040] It should be further explained that the distributed task scheduling system provided by the embodiment of the present invention can realize scheduling management configuration and core scheduling services. The scheduling management configuration specifically includes services such as permissions, data management, task registration and detection review, management task scheduling operation status, scheduling task report and scheduling task execution log, and the core scheduling service specifically includes services such as access control, cluster management, service management, regulation management, configuration management, and scheduled tasks. The system's own operation log is collected, analyzed and stored through the log collection module, and all system logs such as operation abnormality logs are connected to the log platform for unified log management and analysis.
[0041] Figure 1 This is one of the structural diagrams of the distributed task scheduling system provided by the present invention. Figure 1 As shown, the distributed task scheduling system provided by the present invention includes a scheduling resource management module and a task scheduling module.
[0042] The task scheduling module is used to pull the first scheduling task from the remote dictionary service Redis database;
[0043] The scheduling resource management module is used to obtain a thread from a thread pool and use the thread to execute the first scheduling task.
[0044] Specifically, when the time for executing the first scheduled task arrives, the task scheduling module receives the task scheduling request sent by the timer. Based on the task scheduling request, the task scheduling module pulls the first scheduled task from the Redis database and sends the first scheduled task to the scheduling resource management module.
[0045] It should be noted that the task scheduling module provided in the embodiment of the present invention includes a task pulling unit. It can be considered that the above-described scheduler based on the Redis database is implemented in accordance with the Quartz standard interface specification and combined with the data structure encapsulation defined in the Redis database. For example: by writing a class to implement the JobStore interface of Quartz, this class is responsible for handing over the creation, reading, updating and deletion operations corresponding to the trigger (Trigger), task (Job) and task details (JobDetail) to Redis for implementation; according to the needs of Quartz, using the data structure of Redis, design a suitable data structure to store the information of Trigger, Job and JobDetail; in the implemented JobStore interface, write the corresponding code to implement the creation, reading, updating and deletion operations of the data structure in Redis, ensuring that the Job and Trigger can be managed; integrate the implemented JobStore with the Quartz framework to implement an independent scheduler based on the Redis database, and store the task scheduling information based on the Quartz framework in the Redis database.
[0046] Furthermore, after the scheduling resource management module receives the first scheduling task to be executed, it obtains a thread from the thread pool and uses the thread to execute the first scheduling task. In fact, after the scheduling resource management module receives the first scheduling task to be executed, it obtains a thread from the thread pool, and further triggers the search for the first scheduling task to be executed in the task queue through a single thread, thereby avoiding thread locks and delays caused by thread locks.
[0047] It should be noted that after the distributed task scheduling is implemented, if the trigger misses the scheduled trigger time of a task, the distributed task scheduling system will call the MisfireHandler thread used to handle the missed task scheduling. The MisfireHandler thread will update the Redis database and modify the scheduled time of the untriggered task to the current time as the next execution time of the untriggered task, so as to trigger the task again, thereby realizing the task overtime compensation mechanism.
[0048] The distributed task scheduling system provided by the present invention periodically pulls the first scheduling task from the Redis database through the task scheduling module, further obtains the thread from the thread pool through the scheduling resource management module, and uses the thread to execute the first scheduling task. Since the Redis database is a high-performance database based on memory and can provide faster reading and writing speeds, the first scheduling task is stored in the memory of Redis, and the task scheduling module can quickly read data in the Redis database. In addition, during the scheduling process, the distributed task scheduling system can refine the acquisition and response triggers through the distributed lock mechanism provided by the Redis database to avoid the delay of precise scheduling caused by preempting the distributed lock, and realize the precise scheduling of the timed triggered tasks, thereby improving the efficiency of distributed task scheduling.
[0049] Further, Figure 2 Schematic diagram of the structure of the task scheduling module provided by the present invention. Figure 2 As shown, the task scheduling module provided by the present invention includes a task pulling unit and a task monitoring unit.
[0050] The task pulling unit is used to obtain a task scheduling request, and based on the task scheduling request, pull the first scheduling task from the Redis database;
[0051] The task monitoring unit is used to start a ZooKeeper client thread and a cluster manager thread in response to the task scheduling request, and monitor the execution status of the first scheduling task based on the ZooKeeper client thread and the cluster manager thread; the ZooKeeper client thread is used to monitor the state change of the thread and send the state change of the thread to the cluster manager thread; the cluster manager thread is used to manage the first scheduling task associated with the thread based on the state change of the thread.
[0052] Specifically, when the time for executing the first scheduled task arrives, the task pulling unit will receive the task scheduling request sent by the timer. Further, the task pulling unit will pull the first scheduled task from the Redis database based on the task scheduling request, and send the first scheduled task to the scheduling resource management module.
[0053] When the task pull unit responds to the task scheduling request, the task monitoring unit starts the ZooKeeper client thread and the cluster manager thread to monitor the execution status of the first scheduled task executed by the scheduling resource management module using the thread. Among them, the ZooKeeper client thread is used to monitor the state change of the thread and send the state change of the thread to the cluster manager thread. The cluster manager thread is used to manage the first scheduled task associated with the thread based on the state change of the thread.
[0054] Further, the task monitoring unit monitors the execution status of the thread on the first scheduling task based on the ZooKeeper client thread. The execution status of the thread on the first scheduling task can be a normal online state, a normal offline state, and an abnormal offline state. When the execution status is in a normal online state, it means that the thread is executing the first scheduling task. When the execution status is in a normal offline state, it means that the thread has completed the first scheduling task. When the execution status is in an abnormal offline state, it means that the thread has not executed the first scheduling task.
[0055] Furthermore, the task monitoring unit sends the execution status of the first scheduling task to the cluster manager thread based on the ZooKeeper client thread.
[0056] Further, after the cluster manager thread receives the execution status of the first scheduled task, the task monitoring unit manages the first scheduled task associated with the thread based on the cluster manager thread. If the execution status of the thread for the first scheduled task is in a normal online state, the cluster manager thread will continue to wait for the first scheduled task to complete scheduling; if the execution status is in a normal offline state, the cluster manager thread will restore the first scheduled task to the waiting scheduling queue to perform the task recovery operation; if the execution status is in an abnormal offline state, the cluster manager thread will notify the scheduling resource management module of the information that the thread is in an abnormal offline state, so that the scheduling resource management module can reallocate available threads to execute the first scheduled task.
[0057] Furthermore, the task monitoring unit is also used for:
[0058] Based on the monitoring by the ZooKeeper client thread, the thread assigned by the first scheduling task is in an abnormal offline state;
[0059] Sending information that the thread is in an abnormal offline state to the cluster manager thread based on the ZooKeeper client thread;
[0060] Based on the cluster manager thread, information that the thread is in an abnormal offline state and the first scheduling task are sent to the scheduling resource management module.
[0061] Specifically, the task monitoring unit monitors, based on the ZooKeeper client thread, that the thread assigned to the first scheduling task is in an abnormal offline state.
[0062] Furthermore, the task monitoring unit sends information that the thread is in an abnormal offline state to the cluster manager thread based on the ZooKeeper client thread.
[0063] Furthermore, the task monitoring unit sends information that the thread is in an abnormal offline state and the first scheduling task to the scheduling resource management module based on the cluster manager thread, so that the scheduling resource management module can reallocate available threads to execute the first scheduling task.
[0064] Furthermore, the scheduling resource management module is also used to:
[0065] Removing the thread from the thread pool;
[0066] The remaining threads are obtained from the thread pool, and the remaining threads are used to execute the first scheduling task; the remaining threads refer to the remaining idle threads in the thread pool except the thread in the abnormal offline state.
[0067] Specifically, after the scheduling resource management module receives the information that the thread is in an abnormal offline state, the scheduling resource management module removes the thread from the thread pool to avoid causing the first scheduling task to fail to execute again.
[0068] Furthermore, the scheduling resource management module obtains the remaining threads from the thread pool and uses the remaining threads to execute the first scheduling task, wherein the remaining threads refer to the remaining idle threads in the thread pool except for the thread in the abnormal offline state. Therefore, the abnormal offline state of the thread is monitored by the task monitoring unit in the task scheduling module, and the thread in the abnormal offline state is further removed by the scheduling resource management module, and the first scheduling task is reallocated to the remaining threads so that the remaining threads execute the first scheduling task. In this way, the scheduling task failover can be realized to avoid the first scheduling task from being unable to continue to execute when the thread is in the abnormal offline state.
[0069] Figure 3 This is the second structural diagram of the distributed task scheduling system provided by the present invention. Figure 3 As shown, the distributed task scheduling system provided by the present invention includes a scheduling task registration module and a scheduling type change module.
[0070] The scheduling task registration module is used to write the approved first scheduling task into the Redis database; the first scheduling task refers to a task to be executed based on the scheduling type of the Redis database;
[0071] The scheduling type changing module is used to change the scheduling type of the second scheduling task to the scheduling type of the first scheduling task; the scheduling type of the second scheduling task is task scheduling based on a relational database.
[0072] Specifically, the distributed task scheduling system has a visual operation entrance for scheduling task registration, and the user can register the scheduling task through the visual operation entrance. Therefore, it can be understood that the user creates a business of registering the scheduling task through the visual operation entrance for scheduling task registration.
[0073] Furthermore, the scheduling task registration module writes the first scheduling task to be approved into the Mysql database, and sets the status of the first scheduling task to be approved to pending approval, wherein the first scheduling task is the task after the first scheduling task to be approved is approved, and the first scheduling task refers to a task to be executed of a scheduling type based on the Redis database.
[0074] Furthermore, after the user undergoes internal review, if the first scheduling task to be approved is approved, the user sets the first scheduling task to be approved through the visual operation portal for scheduling task registration.
[0075] Furthermore, the scheduling task registration module sets the state of the first scheduling task to running, and writes the first scheduling task into the Redis database.
[0076] Therefore, during the scheduling task registration process, both the Mysql database and the Redis database will contain the scheduling task information. During the distributed task scheduling process, the distributed task scheduling system will use the corresponding scheduler to pull the scheduling task from the database according to the scheduling type of the scheduling task.
[0077] It should be noted that, considering Redis as a middleware for non-reliable persistent storage, the system adds data consistency auditing and synchronization between the Redis database and the MySQL database, and the field qrtzinfo_state in the trigger_bak table of the MySQL database is the basis for the approved scheduling tasks. Synchronization is reflected in two aspects: 1. Task quantity consistency synchronization: Synchronize and compare the differences that do not exist in Redis, and synchronize to Redis scheduling; 2. Task status consistency synchronization: Synchronize the specific status (task pause and task running) of the tasks existing in Redis and MySQL. The synchronization trigger mechanism is reflected in three aspects: 1. Manual trigger synchronization: Add menu system settings to the page, and add the synchronization cache task function (display list and synchronization button); 2. Timed trigger synchronization: Automatic synchronization at an interval of 2 hours; 3. Service startup parameters start triggering synchronization once: Add configuration parameters and start triggering once. This synchronization trigger mechanism is mainly used to solve the following two scenarios: 1. Redis cluster is unavailable, migrate to the newly allocated Redis cluster, and the scheduling task needs to be synchronized to Redis; 2. Redis cluster loses the newly registered scheduling task in some extreme scenarios, and needs to be synchronized to Redis.
[0078] Furthermore, the distributed task scheduling system has a visual operation entry for changing the scheduling type, and the user can use the visual operation entry to change the scheduling type corresponding to the scheduling task. Therefore, it can be understood that the user creates a business of changing the scheduling type through the visual operation entry for changing the scheduling type, and the business will include the scheduling task that needs to change the scheduling type. Therefore, the business of changing the scheduling type can be to change the scheduling type of the first scheduling task to the scheduling type of the first scheduling task, or to change the scheduling type of the second scheduling task to the scheduling type of the second scheduling task, wherein the scheduling type of the first scheduling task is task scheduling based on the Redis database, and the scheduling type of the second scheduling task is task scheduling based on the relational database.
[0079] Furthermore, the scheduling type changing module changes the scheduling type of the first scheduling task to the scheduling type of the second scheduling task, or changes the scheduling type of the second scheduling task to the scheduling type of the first scheduling task according to business requirements.
[0080] Figure 4 Schematic diagram of the distributed task scheduling method provided by the present invention. Figure 4 The distributed task scheduling method provided by the present invention may include:
[0081] Step 100: Pull the first scheduling task from the remote dictionary service Redis database;
[0082] Step 200: Obtain a thread from a thread pool, and use the thread to execute the first scheduling task.
[0083] Specifically, when the time for executing the first scheduled task arrives, the task scheduling module will receive a task scheduling request sent by the timer. Based on the task scheduling request, the task scheduling module will pull the first scheduled task from the Redis database and send the first scheduled task to the scheduling resource management module.
[0084] It should be noted that the task scheduling module provided in the embodiment of the present invention includes a task pulling unit. It can be considered that the above-described scheduler based on the Redis database is implemented in accordance with the Quartz standard interface specification and combined with the data structure encapsulation defined in the Redis database. For example: by writing a class to implement the JobStore interface of Quartz, this class is responsible for handing over the creation, reading, updating and deletion operations corresponding to the trigger (Trigger), task (Job) and task details (JobDetail) to Redis for implementation; according to the needs of Quartz, using the data structure of Redis, design a suitable data structure to store the information of Trigger, Job and JobDetail; in the implemented JobStore interface, write the corresponding code to implement the creation, reading, updating and deletion operations of the data structure in Redis, ensuring that the Job and Trigger can be managed; integrate the implemented JobStore with the Quartz framework to implement an independent scheduler based on the Redis database, and store the task scheduling information based on the Quartz framework in the Redis database.
[0085] Furthermore, after the scheduling resource management module receives the first scheduling task to be executed, it obtains a thread from the thread pool and uses the thread to execute the first scheduling task. In fact, after the scheduling resource management module receives the first scheduling task to be executed, it obtains a thread from the thread pool, and further triggers the search for the first scheduling task to be executed in the task queue through a single thread, thereby avoiding thread locks and delays caused by thread locks.
[0086] It should be noted that after the distributed task scheduling is implemented, if the trigger misses the scheduled trigger time of a task, the distributed task scheduling system will call the MisfireHandler thread used to handle the missed task scheduling. The MisfireHandler thread will update the Redis database and modify the scheduled time of the untriggered task to the current time as the next execution time of the untriggered task, so as to trigger the task again, thereby realizing the task overtime compensation mechanism.
[0087] The distributed task scheduling method provided by the present invention periodically pulls the first scheduling task from the Redis database through the task scheduling module, further obtains the thread from the thread pool through the scheduling resource management module, and uses the thread to execute the first scheduling task. Since the Redis database is a high-performance database based on memory and can provide faster reading and writing speeds, the first scheduling task is stored in the memory of Redis, and the task scheduling module can quickly read data in the Redis database. In addition, during the scheduling process, the distributed task scheduling system can refine the acquisition and response triggers through the distributed lock mechanism provided by the Redis database to avoid the delay of precise scheduling caused by preempting the distributed lock, and realize the precise scheduling of the timed triggered tasks, thereby improving the efficiency of distributed task scheduling.
[0088] Furthermore, the distributed task scheduling method provided by the present invention may also include:
[0089] When responding to the task scheduling request, a ZooKeeper client thread and a cluster manager thread are started, and the execution status of the first scheduling task is monitored based on the ZooKeeper client thread and the cluster manager thread.
[0090] Specifically, when the time for executing the first scheduled task arrives, the task pulling unit will receive the task scheduling request sent by the timer. Further, the task pulling unit will pull the first scheduled task from the Redis database based on the task scheduling request, and send the first scheduled task to the scheduling resource management module.
[0091] When the task pull unit responds to the task scheduling request, the task monitoring unit starts the ZooKeeper client thread and the cluster manager thread to monitor the execution status of the first scheduled task executed by the scheduling resource management module using the thread. Among them, the ZooKeeper client thread is used to monitor the state change of the thread and send the state change of the thread to the cluster manager thread. The cluster manager thread is used to manage the first scheduled task associated with the thread based on the state change of the thread.
[0092] Further, the task monitoring unit monitors the execution status of the thread on the first scheduling task based on the ZooKeeper client thread. The execution status of the thread on the first scheduling task can be a normal online state, a normal offline state, and an abnormal offline state. When the execution status is in a normal online state, it means that the thread is executing the first scheduling task. When the execution status is in a normal offline state, it means that the thread has completed the first scheduling task. When the execution status is in an abnormal offline state, it means that the thread has not executed the first scheduling task.
[0093] Furthermore, the task monitoring unit sends the execution status of the first scheduling task to the cluster manager thread based on the ZooKeeper client thread.
[0094] Further, after the cluster manager thread receives the execution status of the first scheduled task, the task monitoring unit manages the first scheduled task associated with the thread based on the cluster manager thread. If the execution status of the thread for the first scheduled task is in a normal online state, the cluster manager thread will continue to wait for the first scheduled task to complete scheduling; if the execution status is in a normal offline state, the cluster manager thread will restore the first scheduled task to the waiting scheduling queue to perform the task recovery operation; if the execution status is in an abnormal offline state, the cluster manager thread will notify the scheduling resource management module of the information that the thread is in an abnormal offline state, so that the scheduling resource management module can reallocate available threads to execute the first scheduled task.
[0095] The distributed task scheduling method provided by the present invention monitors the task execution status by combining the ZooKeeper client thread and the cluster manager thread, thereby realizing real-time monitoring and management of the task execution process, thereby improving system stability and optimizing system performance.
[0096] Figure 5 is a schematic diagram of the structure of the electronic device provided by the present invention, such as Figure 5 As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute the distributed task scheduling method, which includes: pulling a first scheduling task from a remote dictionary service Redis database; obtaining a thread from a thread pool, and using the thread to execute the first scheduling task.
[0097] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0098] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the distributed task scheduling method provided in the above-mentioned embodiments, and the method includes: pulling a first scheduling task from a remote dictionary service Redis database; obtaining a thread from a thread pool, and using the thread to execute the first scheduling task.
[0099] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the distributed task scheduling method provided in the above-mentioned embodiments, the method comprising: pulling a first scheduling task from a remote dictionary service Redis database; obtaining a thread from a thread pool, and using the thread to execute the first scheduling task.
[0100] The device embodiments described above are merely illustrative, 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 paying creative labor.
[0101] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0102] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A distributed task scheduling system, characterized in that: Including scheduling resource management module and task scheduling module; The task scheduling module is used to pull the first scheduling task from the remote dictionary service Redis database; The scheduling resource management module is used to obtain a thread from a thread pool and use the thread to execute the first scheduling task.
2. The distributed task scheduling system according to claim 1, characterized in that: The task scheduling module includes a task pulling unit and a task monitoring unit: The task pulling unit is used to obtain a task scheduling request, and based on the task scheduling request, pull the first scheduling task from the Redis database; The task monitoring unit is used to start a ZooKeeper client thread and a cluster manager thread in response to the task scheduling request, and monitor the execution status of the first scheduling task based on the ZooKeeper client thread and the cluster manager thread; the ZooKeeper client thread is used to monitor the state change of the thread and send the state change of the thread to the cluster manager thread; the cluster manager thread is used to manage the first scheduling task associated with the thread based on the state change of the thread.
3. The distributed task scheduling system according to claim 2, characterized in that: The task monitoring unit is further used for: Based on the monitoring by the ZooKeeper client thread, the thread assigned by the first scheduling task is in an abnormal offline state; Sending information that the thread is in an abnormal offline state to the cluster manager thread based on the ZooKeeper client thread; Based on the cluster manager thread, information that the thread is in an abnormal offline state and the first scheduling task are sent to the scheduling resource management module.
4. The distributed task scheduling system according to claim 2, characterized in that: The scheduling resource management module is also used for: Removing the thread from the thread pool; The remaining threads are obtained from the thread pool, and the remaining threads are used to execute the first scheduling task; the remaining threads refer to the remaining idle threads in the thread pool except the thread in the abnormal offline state.
5. The distributed task scheduling system according to claim 1, characterized in that: The distributed task scheduling system also includes a scheduling task registration module and a scheduling type change module; The scheduling task registration module is used to write the approved first scheduling task into the Redis database; the first scheduling task refers to a task to be executed based on the scheduling type of the Redis database; The scheduling type changing module is used to change the scheduling type of the second scheduling task to the scheduling type of the first scheduling task; the scheduling type of the second scheduling task is task scheduling based on a relational database.
6. A distributed task scheduling method, characterized in that: include: Pull the first scheduling task from the remote dictionary service Redis database; A thread is obtained from a thread pool, and the thread is used to execute the first scheduling task.
7. The distributed task scheduling method according to claim 6, characterized in that: Also includes: When responding to the task scheduling request, a ZooKeeper client thread and a cluster manager thread are started, and the execution status of the first scheduling task is monitored based on the ZooKeeper client thread and the cluster manager thread.
8. A device, comprising an electronic device, the electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the distributed task scheduling method according to any one of claims 5 to 7 are implemented.
9. A medium, comprising a non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the distributed task scheduling method according to any one of claims 5 to 7 are implemented.
10. A product, comprising a computer program product, wherein the computer program product comprises a computer program, characterized in that When the computer program is executed by a processor, the steps of the distributed task scheduling method according to any one of claims 5 to 7 are implemented.
