Timed task batch processing system

By using Redis's ZSet data structure and task management module in the scheduled task system, the stability and data security issues in large-volume scheduled task processing are solved, dynamic management and efficient processing are achieved, and the system is ensured to be centralized at the task time point. stable operation and data security.

CN118585302APending Publication Date: 2024-09-03SICHUAN HONGMEI INTELLIGENT TECH CO LTD

Patent Information

Application Number
CN202410746463.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-11
Publication Date
2024-09-03

AI Technical Summary

Technical Problem

It is difficult to effectively manage and process large batches of scheduled tasks with existing technology. Especially when task time points are concentrated, system stability and data security are difficult to guarantee, and tasks cannot be dynamically added, edited, and deleted.

Method used

The ZSet data structure of Redis is used to store scheduled tasks, and the task management module is used to realize the functions of adding, editing, and deleting. The task monitoring module is used to load tasks that are about to expire in advance, and the task distribution processing module is combined with the task distribution processing module to process tasks according to the policy, and the high performance of Redis is used. Performance characteristics and data durability ensure system stability and data security.

Benefits of technology

It achieves system stability and reliability in large-volume scheduled task scenarios, dynamically manages tasks, avoids system crashes and data loss, and improves task processing efficiency and data security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118585302A
    Figure CN118585302A
Patent Text Reader

Abstract

The invention discloses a timed task batch processing system comprising a task management module used for realizing task adding, editing and deleting functions; the task monitoring module is used for loading a task to be executed into the ZSet in advance and synchronously calculating the task quantity of each time point; the task distribution processing module carries out processing according to a strategy configured by the task; and the task preloading module is used for evaluating how long the task needs to be loaded in advance into the ZSet according to the peak value quantity of the business. According to the method, the service scene of a large batch of timed tasks is solved, the functions of dynamically adding, editing and deleting the tasks are provided, and the mode of preloading and obtaining in batches is provided for the situation that the task time is relatively concentrated at certain time points in the actual scene, so that the system stability and reliability are guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and more particularly to a timed task batch processing system. Background Art

[0002] Since the business often involves demand scenarios for timing or countdown tasks, and tasks can be freely added, edited, and deleted at any time, a unified scheduled task processing system is needed to manage them. As the scale of the business increases, the number of related scheduled tasks is also increasing synchronously, and such scheduled tasks are often strongly related to user habits. There are more tasks at a certain time, and fewer tasks at other times. For example, there are more task data at 8 am, 6 pm, and 9 pm, and there are no or fewer tasks at other times. For such business scenarios, all scheduled tasks need to be executed at the time when the tasks are concentrated, and the system must be stable and reliable. The system cannot be allowed to run at high load when the number of tasks is small. How to implement scheduled task processing, usually we can achieve it in the following ways:

[0003] The first method is to use a delay queue. A delay queue is a queue used to store elements that need to be processed at a specified time point. It can usually be implemented using a queue data structure (such as an array or a linked list) or with the help of a message middleware (such as RabbitMQ or Kafka). Calculate the delay time for task execution and put the task into the delay queue. When the delay time arrives, the delay queue will take the message or task out of the queue and process it accordingly. However, in the face of the requirement that scheduled tasks can be edited and deleted, the delay queue often cannot handle it well. When using a queue data structure as a delay queue, the data will be stored in memory. The increase in data volume will occupy a large amount of system memory, and system failures will cause data in memory to be lost. Using a message middleware as a delay queue can avoid message loss, but messages placed in the middleware cannot be deleted or withdrawn for editing.

[0004] The second method is to use the existing open source scheduled task processing framework, such as Quartz, XXL-JOB, SpringTask, etc. This series of frameworks have complete functions of adding, editing, and deleting tasks, as well as task status tracking. Tasks can be stored in the database and will not be lost. However, this type of framework is often only suitable for large scheduled task processing with a fixed number and clear time. The creation of tasks is strongly related to the functions to be achieved by the system and is defined by the developer. It is not competent for large-scale scheduled task processing that can be freely changed by end users.

[0005] In response to the problems of the above two methods, the following patents provide their own solutions. The following is an analysis of the technical solutions adopted by these patents:

[0006] "Scheduled Task Scheduling Method and Scheduled Task Processing Method", patent number CN201910326565.1, this application relates to a method and device for scheduling scheduled tasks. The method includes: taking the operating cycle of each scheduled task in the database, and determining the target scheduled task from each scheduled task according to the operating cycle; comparing the estimated running time of the target scheduled task with the preset duration index value, and determining whether the target scheduled task has a dependency lock; when the estimated running time of the target scheduled task is less than the preset duration index value and there is no dependency lock, determining the running mode of the target scheduled task; sending the metadata of the target scheduled task to the task queue of the scheduling end corresponding to the running mode, wherein the metadata of the target scheduled task is used to instruct the scheduling end to call the execution server to execute the target scheduled task according to the metadata. The use of this method can realize the decoupling of the scheduling and execution of scheduled tasks, avoiding the generation of performance bottlenecks in the business system.

[0007] The above invention mainly uses a database to store scheduled tasks, ensuring that task data will not be lost, and obtains scheduled tasks from the database to determine whether the estimated duration is met. If it is met, the scheduled task is placed in the task queue for scheduling by the scheduler. This method decouples scheduling and execution, and can increase the system's concurrent processing capacity for timing. However, it is necessary to constantly query the database to obtain tasks for comparison. When the task distribution period is uneven, the tasks queried at a time point with more tasks may far exceed the amount that the system can bear, which can easily cause the system to crash, and cannot solve the business scenario of a large number of normally distributed scheduled tasks.

[0008] "A method for executing a scheduled task and a scheduled task server", patent number CN201710413230.4, the present invention provides a method for executing a scheduled task and a scheduled task server, the scheduled task execution method includes: the scheduled task server queries a pre-created scheduled task record table, the scheduled task record table is used to record the execution parameters of the last scheduled task execution; the scheduled task server determines the number of executions of the scheduled task based on the execution parameters of the last scheduled task execution and the execution parameters of this scheduled task; the scheduled task server executes the scheduled task according to the number of executions of the scheduled task, and updates the execution parameters of the last scheduled task execution. Using the technical solution provided by the present invention, when the scheduled task fails to execute and the scheduled task is restarted, the scheduled task can still be automatically executed from the place where the last scheduled task execution failed, avoiding data loss, without manual participation, and improving the execution efficiency and data security of the scheduled task.

[0009] The above invention mainly stores the scheduled tasks in a record table in advance, records the status of the tasks, executes the scheduled tasks according to the record table, and can continue to execute from the last failed point according to the record table when a failure occurs. This invention is mainly used in business scenarios where statistics are collected on a scheduled basis, and solves the problem of restarting and automatically continuing from the last position when a task fails. However, this invention cannot be applied to business scenarios where a large number of tasks of a certain magnitude are performed at the same time point.

[0010] "Timed Task Processing Method and Device", patent number CN201810084155.6, the embodiment of the present invention provides a timed task processing method and device, wherein the timed task processing method includes: monitoring the timed task through the I / O multiplexing model corresponding to the queue maintenance thread of the timed task; after monitoring the new timed task, activating the queue maintenance thread through the I / O multiplexing model; reading the data of the timed task and writing it to the activated queue maintenance thread, wherein the data of the timed task includes: the task data of the timed task and the timing time of the timed task; according to the timing time of the timed task, adding the timed task to the timed task queue maintained by the queue maintenance thread, wherein the timed tasks in the timed task queue are arranged from small to large according to the timing time; at the timing time of each timed task in the timed task queue, triggering the task distribution thread to distribute the corresponding timed task. Through the embodiment of the present invention, the accurate matching and processing of the triggering time of the timed task is realized.

[0011] The above invention uses queues to maintain scheduled tasks, where the queues are arranged from small to large in terms of time. In order to increase the concurrency of processing at the same time, the I / O multiplexing model is used to design the monitoring task, and the activation thread is written to process when the task time is met. This invention can well solve the scenario of a large number of scheduled tasks with the same time, use the I / O multiplexing feature to reduce system consumption, increase the processing speed of expired tasks, and can process large quantities of data at the same time. However, this invention has the risk of data loss. The scheduled tasks are stored in the queue, and the data in the queue will be lost after a system failure. Summary of the invention

[0012] The purpose of the present invention is to provide a scheduled task batch processing system to solve the problems in the background technology.

[0013] In order to achieve the above object, the present invention adopts the following technical solutions:

[0014] A scheduled task batch processing system, comprising:

[0015] Task management module: The task management module is used to realize the functions of adding, editing and deleting tasks;

[0016] Task monitoring module: The task monitoring module will load the tasks to be executed into ZSet in advance and synchronously calculate the task volume at each time point;

[0017] The task distribution processing module processes tasks according to the strategies configured for the tasks;

[0018] The task preloading module evaluates how long it takes to load tasks into the ZSet in advance based on the peak number of services.

[0019] In some embodiments, when the task is deleted from the database, the data in the ZSet is deleted synchronously.

[0020] In some embodiments, the task monitoring module will start the scheduled task, regularly inquire whether there are tasks due, and take out the due tasks and distribute them to the task distribution processing module.

[0021] In some embodiments, the task distribution processing module processes according to the strategy configured for the task, which is divided into three types: business self-implementation processing strategy, push to business corresponding message queue and Http callback, which is selected according to its own business and usage scenario.

[0022] In some embodiments, whether the execution needs to be triggered again is determined based on the frequency and time configured for the scheduled task, and the task status and time are updated.

[0023] In some embodiments, each task contains basic information including: task number, task source, task type, original time, execution frequency, number of minutes from 0 o'clock, next trigger time, number of retries, and task expiration execution strategy.

[0024] In some embodiments, each member of a ZSet is required to set a score, which is calculated based on a timed interval.

[0025] Compared with the prior art, the present invention has the following beneficial effects:

[0026] The present invention provides a reliable and low-cost way to solve the business scenario of large-scale scheduled tasks, provides the functions of dynamically adding, editing and deleting tasks, and proposes a pre-loading and batch acquisition method to ensure system stability and reliability in view of the fact that the task time is relatively concentrated at certain time points in the actual scenario. The high-performance characteristics of Redis are fully utilized, and the ZSet data structure is used to store pre-loaded scheduled tasks. The scheduled time is used as the ZSet score. When polling, the data with a score within the time range is the expired data. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 : Schematic diagram of the core module of the present invention;

[0028] Figure 2 : Schematic diagram of basic information of the task;

[0029] Figure 3 : Functional diagram of task monitoring module;

[0030] Figure 4 :Schematic diagram of ZSet data score calculation method. DETAILED DESCRIPTION

[0031] In order to make the purpose, technical solutions and advantages of the present application clearer, the technical solutions in the embodiments of the present application will be described in more detail below in conjunction with the drawings in the preferred embodiments of the present application. In the drawings, the same or similar reference numerals throughout represent the same or similar parts or parts with the same or similar functions. The described embodiments are part of the embodiments of the present application, not all of the embodiments. The embodiments described below with reference to the drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limitations on the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.

[0032] The embodiments of the present application are described in detail below with reference to the accompanying drawings.

[0033] The following will be combined with the figures to describe in detail a scheduled task batch processing system involved in the embodiment of the present application. It should be noted that the following embodiments are only used to explain the present application and do not constitute a limitation on the present application.

[0034] Embodiment 1:

[0035] See also Figure 1 A scheduled task batch processing system includes: a task management module, which is used to realize the functions of adding, editing and deleting tasks; a task monitoring module, which will load the tasks to be executed into ZSet in advance and synchronously calculate the task volume at each time point; a task distribution processing module, which processes according to the strategy configured for the task; and a task preloading module, which will evaluate how long it takes to load the task into ZSet in advance according to the peak number of the business.

[0036] The core of the present invention is to realize the addition, editing, deletion and monitoring of scheduled tasks, which mainly includes a task management module, a task monitoring module, a task preloading module and a task distribution processing module. The task management module realizes the functions of adding, editing and deleting tasks, adding or deleting tasks from the database, and synchronously deleting the data in the ZSet when deleting.

[0037] The task monitoring module will load the tasks to be executed into ZSet in advance, and synchronously calculate the task volume at each time point. The time point is calculated in minutes, so the time granularity of the scheduled task is minutes, which can meet the needs of most scheduled business scenarios. If it is set to seconds, it will increase the operating burden of the system. The task monitoring module will start a scheduled task, ask whether there is a task due every minute, and take out the processing strategy for the distribution of due tasks.

[0038] The task preloading module can process according to the strategy configured for the task, which is divided into three types: business self-implementation processing strategy, push to the business corresponding message queue and Http callback, which can be selected according to its own business and usage scenario. Synchronously determine whether it needs to be triggered again according to the frequency and time configured for the scheduled task, and then update the task status and time.

[0039] The task preloading module can evaluate how long it takes to load tasks into ZSet in advance based on the peak number of businesses. By default, it loads task data that will be executed within 10 minutes. The purpose of this function is to load data that was not previously in ZSet into ZSet. At the same time, it can effectively avoid the problem of delayed task triggering caused by database reading taking a long time when a large amount of data needs to be read at the same time.

[0040] ZSet is an ordered set, a set of strings ordered by their associated scores. All members in the set are sorted by their score values. The members of ZSet are unique, but the score values ​​can be repeated. The complexity of adding, deleting, and searching is O(1). The maximum number of members is 2. 32 -1 (about 4.2 billion), a ZSet collection can store a massive number of tasks.

[0041] As a commonly used KV cache middleware, Redis has the characteristics of single-threaded high concurrency and is suitable for use in massive data scenarios. The memory-based operation mode makes the read and write operations very fast. According to official data, it can process more than 100,000 read and write operations per second. Rdis's ZSet underlying data structure uses a compressed list (ziplist) and a skip list (skiplist). The advantage of a compressed list is that it takes up less memory, but the disadvantage is that when data needs to be modified, the entire compressed list may need to be rewritten, resulting in lower performance. The advantage of a skip list is that it has higher performance in finding and modifying data, but it also takes up more memory.

[0042] Redis will dynamically switch between the two underlying structures of ZSet, compression list and jump list, according to the actual situation, to find a balance between memory usage and performance. Therefore, ZSet using Redis can meet the performance requirements and peak business storage requirements. Compared with other middlewares such as RabbitMQ and Kafka that can be used to process timing scenarios, the learning cost and actual application cost are relatively low. At the same time, Redis's natural support for data synchronization to disk can ensure that data is not lost. After the service is down and restarted, data can be loaded from the disk, ensuring the safety and reliability of the application without data loss.

[0043] The present invention defines that each task needs to contain basic information including: task number, task source, task type, original time, execution frequency, number of minutes from 0 o'clock, next trigger time, number of retries, and task expiration execution strategy.

[0044] The task number is the unique identifier of each task, and the corresponding task can be located later based on the number.

[0045] The task source is used to distinguish the business from which the scheduled task is generated, which facilitates project management.

[0046] Task types include timing and countdown. Countdown is converted into timing to trigger. The time point of task execution needs to be calculated in advance. At the same time, countdown task will only be executed once.

[0047] The original time is the trigger time of the task itself, for example: 2024-04-01 13:01 or 8:00, which is the basis for calculating the next trigger time.

[0048] The execution frequency determines the trigger period of the task, such as weekly, monthly, daily or self-selected trigger time.

[0049] The time from zero is the key to calculating the ZSet score. This information determines the time of the day when the task is triggered.

[0050] The next trigger time is the most recent execution time of the task, which will be on a certain day of a certain month of a certain year. ZSet will generate different ZSet data structures based on days as the time unit.

[0051] The number of retries is designed to increase fault tolerance when the task execution strategy fails.

[0052] The execution strategy information will determine the direction of the task post-processing after the task expires, which is divided into custom, message queue and Http callback. The above is only the basic information of the task, and you can freely design and add corresponding information to enrich the task content.

[0053] In the present invention, each member of the ZSet needs to be set with a score, which is calculated from the time of the timing, and the specific method is as follows Figure 4 As shown, M represents the estimated peak number, P represents the number of minutes from the current time point to midnight, A represents a random number, and C represents the number of tasks counted at the current time point. The score is approximately equal to the trigger time of the task. During scheduled polling, the current time range to be taken, that is, the score range, will be calculated. Tasks within this range are due tasks. In order to avoid too many scheduled tasks at a certain time, which affects the query performance of RedisZSet, the tasks at this time point are obtained in batches. For example, if there are 10,000 tasks at 8 o'clock, the number of minutes from 8 o'clock to midnight is 480, and the number of minutes from 8:01 to midnight is 540. There are 10,000 tasks between 480 and 540, and 1,000 tasks are taken in batches each time. In order to make the data more discrete, the score of the current task is calculated based on the statistical data volume to determine the peak number. The score and number are accumulated in sequence starting from 0.

[0054] When applying, you can choose to integrate the device into the business or make it an independent timing system for all timing businesses according to the actual timing business volume. When storing Redis ZSet, each day will be used as the dimension generated by the key. For example, if the day is 2024-04-01, the key is 20240401, and the tasks on the same day will be placed in the corresponding ZSet, which means that up to 2 32 -1 (about 4.2 billion) tasks, one ZSet is enough to support a large amount of business, so the actual application cost is relatively low. The original data of the task is stored in the database, which can prevent data loss after Redis crashes and becomes unavailable. The data that failed to be written to Redis can still be loaded by querying the database, ensuring the security and reliability of the data. In order to prevent the impact of a single service crash, the timing service system can be deployed in a cluster. If one service crashes, other services are still running, greatly improving the reliability of the system.

[0055] This patent uses the ZSet data storage structure based on Redis as the storage container of task data. When a large number of scheduled tasks need to be executed at the same time, they can be quickly and timely retrieved and distributed to task processors for processing, so as to achieve the timing processing of large batches of scheduled tasks at a relatively low cost. The core parts are as follows Figure 1 shown.

[0056] In order to prevent the loss of scheduled tasks and track the status of tasks, tasks need to be stored in the database. Based on actual business needs, the information that tasks need to contain is summarized. Each task needs to contain basic information including: task number, task source, task type, original time, execution frequency, time from 0 o'clock, next trigger time, number of retries, and task expiration execution strategy. Figure 2 shown.

[0057] The task monitoring module is an important functional design of this patent. It is responsible for pre-loading the tasks to be executed by the database at a certain time or the tasks to be executed when the user adds them into the ZSet storage structure of Redis, and counting the amount of task data near each time point (in minutes) as the basis for batch acquisition when the task expires. It regularly rotates to obtain the expired data and hands it over to the processing strategy for distribution and processing. The overall process is as follows: Figure 3 shown.

[0058] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A scheduled task batch processing system, characterized in that: include: Task management module: The task management module is used to realize the functions of adding, editing and deleting tasks; Task monitoring module: The task monitoring module will load the tasks to be executed into ZSet in advance and synchronously calculate the task volume at each time point; The task distribution processing module processes tasks according to the strategies configured for the tasks; The task preloading module evaluates how long it takes to load tasks into the ZSet in advance based on the peak number of services.

2. A scheduled task batch processing system according to claim 1, characterized in that: When the task is deleted from the database, the data in the ZSet is deleted synchronously.

3. A scheduled task batch processing system according to claim 1, characterized in that: The task monitoring module will start the scheduled task, regularly inquire whether there are any tasks due, and take out the due tasks and distribute them to the task distribution processing module.

4. A scheduled task batch processing system according to claim 1, characterized in that: The task distribution processing module processes tasks according to the strategies configured by the tasks, which are divided into three types: business self-implementation processing strategy, push to business corresponding message queue and Http callback. You can choose according to your own business and usage scenarios.

5. A scheduled task batch processing system according to claim 1, characterized in that: Determine whether to trigger execution again based on the frequency and time configured for the scheduled task, and update the task status and time.

6. A scheduled task batch processing system according to claim 1, characterized in that: Each task contains basic information including: task number, task source, task type, original time, execution frequency, number of minutes from 0 o'clock, next trigger time, number of retries, and task expiration execution strategy.

7. A scheduled task batch processing system according to claim 1, characterized in that: Each member of a ZSet needs to have a score set, which is calculated by the timer.

Citation Information

Patent Citations

  • Timed task execution method and timed task server

    CN107368360A

  • Timed task scheduling method and timed task processing method

    CN109992390A

  • Timing task processing method and device

    CN110096340A

Cited By

  • Learning report pushing method and device, storage medium and computer equipment

    CN121151456A

  • Method and equipment for loading timed task

    CN122412115A

  • A method and apparatus for loading a timing task

    CN122412115B