A method and apparatus for performing a timing task

By writing and reading identifier data into a distributed database, valid distributed programs are identified and scheduled tasks are allocated, thus solving the high availability and performance issues of single-node scheduled tasks under large data volumes and achieving load balancing and efficient execution.

CN115237579BActive Publication Date: 2026-02-24ICLOUDSHIELD SECURITY TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210973779.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-15
Publication Date
2026-02-24
Estimated Expiration
2042-08-15

AI Technical Summary

Technical Problem

In existing technologies, single-node scheduled tasks cannot be executed due to excessive data volume or load, resulting in serious issues with high availability, performance, and load. In particular, when the data volume increases from tens of thousands to tens of millions, the pressure on the server from a single-node program increases significantly, which may trigger the OOM Killer strategy.

Method used

By writing the first identifier data into the field of each distributed program in the distributed database, the valid distributed programs are read and determined. Based on the sorting results, the scheduled task data is allocated, so that each valid distributed program processes the corresponding data at the scheduled task execution time. Invalid programs are dynamically cleaned up, thereby achieving distributed processing and load balancing.

Benefits of technology

It enables efficient execution of scheduled tasks under large data volumes and complex business scenarios, avoids task failures caused by single-node failures, dynamically cleans up invalid programs, balances the load, and improves system availability and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115237579B_ABST
    Figure CN115237579B_ABST
Patent Text Reader

Abstract

The application relates to a timing task execution method and device. First, first identification data is written into a first field corresponding to each initial distributed program in a first database, then data stored in the first field corresponding to each initial distributed program in the first data is read to obtain second identification data; then, at least one valid distributed program is determined from all initial distributed programs according to the second identification data; and finally, the timing task data corresponding to each valid distributed program is determined according to the sorting result of all valid distributed programs, so that each valid distributed program processes the corresponding timing task data when the timing task execution time point is reached. The embodiment of the application can realize distributed processing, dynamically clean up invalid distributed programs and balance the load.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, specifically to a method and apparatus for executing timed tasks. Background Technology

[0002] Scheduled tasks execute at fixed time intervals, and current technologies often employ a single-node approach. When data volume is small and business logic is simple, single-node scheduled tasks generally function correctly. However, as data volume increases and business logic becomes more complex, traditional single-node programs reveal numerous problems. First, there's the issue of high availability: if the single-node program fails, all scheduled tasks will fail. Second, there are performance issues: tasks that originally executed every ten minutes will experience increased computational and processing pressure as data volume and business logic grow, eventually taking longer than ten minutes to complete. This not only affects the current processing result but also the processing of the next task, leading to data corruption and program unavailability. Third, there are load issues: when data volume increases from tens of thousands to tens of millions, the CPU and memory usage of a single-node program will increase exponentially. In severe cases, Linux systems may even trigger the OutOfMemoryError (OOM) killer. Summary of the Invention

[0003] In view of this, one of the technical problems solved by the embodiments of the present invention is to provide a method and apparatus for executing scheduled tasks, which solves the problem in the prior art that single-node scheduled tasks cannot be executed due to excessive data volume or load.

[0004] The first aspect of this application discloses a method for executing a scheduled task, including:

[0005] Write the first identifier data into the first field corresponding to each initial distributed program in the first database. The data written into the first field corresponding to each initial distributed program this time is different from the data written last time.

[0006] Read the data stored in the first field corresponding to each initial distributed program in the first database to obtain the second identifier data;

[0007] Based on the second identifier data, at least one valid distributed program is identified from all the initial distributed programs;

[0008] Based on the sorting results of all valid distributed programs, determine the timed task data corresponding to each valid distributed program, so that when the time point for executing the timed task arrives, each valid distributed program processes the corresponding timed task data.

[0009] The second aspect of this application discloses a timed task execution device, comprising:

[0010] The writing module is used to write the first identifier data into the first field corresponding to each initial distributed program in the first database. The data written into the first field corresponding to each initial distributed program this time is different from the data written last time.

[0011] The reading module is used to read the data stored in the first field corresponding to each initial distributed program in the first database to obtain the second identifier data;

[0012] The first determining module is used to determine at least one valid distributed program from all the initial distributed programs based on the second identification data;

[0013] The second determining module is used to determine the timed task data corresponding to each valid distributed program based on the sorting result of all valid distributed programs, so that when the time point for executing the timed task is reached, each valid distributed program processes the corresponding timed task data.

[0014] The scheduled task execution method and apparatus of this application first writes first identifier data into the first field corresponding to each initial distributed program in the first database. Then, it reads the data stored in the first field corresponding to each initial distributed program in the first data to obtain second identifier data. Next, based on the second identifier data, at least one valid distributed program is determined from all the initial distributed programs. Then, based on the sorting result of all valid distributed programs, the scheduled task data corresponding to each valid distributed program is determined so that when the scheduled task execution time point is reached, each valid distributed program processes the corresponding scheduled task data. Compared with the prior art, the embodiments of this application can realize distributed processing and dynamically clean up invalid distributed programs to balance the load. Attached Figure Description

[0015] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0016] Figure 1 This is a flowchart illustrating a scheduled task execution method disclosed in Embodiment 1 of this application;

[0017] Figure 2 This is a flowchart illustrating a timed task execution method disclosed in Embodiment 2 of this application;

[0018] Figure 3 This is a flowchart illustrating a timed task execution method disclosed in Embodiment 3 of this application;

[0019] Figure 4 This is a schematic diagram of the structure of a timed task execution device disclosed in Embodiment 4 of this application. Detailed Implementation

[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0021] It should be noted that the terms "first," "second," "third," and "fourth," etc., used in the specification and claims of this application are used to distinguish different objects, not to describe a specific order. The terms "comprising" and "having," and any variations thereof, in the embodiments of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.

[0022] Example 1

[0023] like Figure 1 As shown, Figure 1 This is a schematic flowchart illustrating a timed task execution method disclosed in Embodiment 1 of this application. The method includes:

[0024] Step S101: Write the first identifier data into the first field corresponding to each initial distributed program in the first database. The data written into the first field corresponding to each initial distributed program this time is different from the data written last time.

[0025] In this embodiment, the execution entity of this method can exist independently of the distributed program, or it can be integrated with the distributed program.

[0026] In this embodiment, all initial distributed programs can be deployed on different computers or on the same computer to jointly execute scheduled tasks, thereby balancing the load of each initial distributed program and improving performance.

[0027] In this embodiment, the first identification data is used to identify each initial distributed program. The specific identification format is not limited and can be letters or numbers.

[0028] In this embodiment, the writing method of writing the first identifier data into the first field corresponding to each initial distributed program in the first database is not limited. The data corresponding to each initial distributed program in the first identifier data is written into the first field corresponding to each initial distributed program in the first database in a parallel manner, or the data corresponding to each initial distributed program in the first identifier data is written into the first field corresponding to each initial distributed program in the first database in a serial manner.

[0029] In this embodiment, the first database stores at least each initial distributed program and its corresponding first identifier data. The type of the first database is not limited, but a non-relational key-value database is preferred, which has fast query speed, large data storage capacity and supports high concurrency. It can be Redis, Voldemort or Riak.

[0030] In this embodiment, in order to uniquely identify each initial distributed program in the first database, the method further includes the following step before step S101:

[0031] Sub-step S100a: Based on the startup time of each initial distributed program, obtain third identification data, wherein the startup time of each initial distributed program is identified at the nanosecond level in the third identification data.

[0032] Sub-step S100b: Write the third identifier data into the second field corresponding to each initial distributed program in the first database.

[0033] The third identification data is used to uniquely identify each initial distributed program in the first database. Considering that multiple initial distributed programs cannot generate the same nanosecond-level timestamp data when they start, and that it is relatively easy to obtain the timestamp data corresponding to the start of multiple initial distributed programs, it is preferable to identify the start time of each initial distributed program in the third identification data according to the nanosecond level.

[0034] Step S102: Read the data stored in the first field corresponding to each initial distributed program in the first database to obtain the second identifier data.

[0035] In this embodiment, if an initial distributed program is in a failed state, new data cannot be written to the first field corresponding to the initial distributed program in step S101. Therefore, in order to determine whether the write operation in step S101 is successful, the second identifier data is obtained.

[0036] Step S103: Based on the second identifier data, determine at least one valid distributed program from all the initial distributed programs.

[0037] In this embodiment, the success of the write operation in step S101 can be determined based on whether the obtained second identifier data meets preset conditions, thereby confirming the validity of the distributed program. The setting method for the preset conditions is not limited and can be specified according to the actual application.

[0038] Optionally, to reduce the difficulty of data processing, step S103 may specifically include: determining at least one valid distributed program from all initial distributed programs based on the comparison result of whether the first identifier data and the second identifier data are the same. That is, when the data corresponding to each initial distributed program in the second identifier data is the same as the data corresponding to each initial distributed program in the first identifier data, it indicates that the write operation in step S101 was successful, and the initial distributed program is determined to be a valid distributed program; when the data corresponding to each initial distributed program in the second identifier data is different from the data corresponding to each initial distributed program in the first identifier data, it indicates that the write operation in step S101 failed, and the initial distributed program is determined to be a failed distributed program.

[0039] Step S104: Based on the sorting results of all valid distributed programs, determine the timed task data corresponding to each valid distributed program, so that when the time point for executing the timed task is reached, each valid distributed program processes the corresponding timed task data.

[0040] In this embodiment, the total number of effective distributed programs and the sorting order of each effective distributed program can be determined based on the sorting results. Therefore, each effective distributed program can be further determined to process the corresponding timed task data based on the total number of effective distributed programs and the sorting order of each effective distributed program.

[0041] Specifically, in order to allocate the scheduled task data to the effective distributed programs, the total scheduled task data to be processed can be divided into multiple parts based on the total amount of all effective distributed programs. Then, each effective distributed program determines its corresponding scheduled task data according to the corresponding sorting order. When the scheduled task is triggered, each effective distributed program processes the corresponding scheduled task data.

[0042] Optionally, to ensure the smooth and normal execution of scheduled tasks, a pre-defined allocation rule for scheduled task data can be established based on the total number and sequence number of effective distributed programs. The specific allocation method is not limited, and the amount of scheduled task data allocated to each effective distributed program can be the same or different. For example, if the total number of tasks corresponding to all scheduled task data is 100, it can be pre-set that effective distributed program with sequence number 1 handles tasks 1-40, effective distributed program with sequence number 2 handles tasks 41-80, and effective distributed program with sequence number 3 handles tasks 81-100.

[0043] Optionally, to facilitate and quickly obtain the sorting results of all valid distributed programs, the first database selected in this embodiment can automatically sort all valid distributed programs and generate fourth identifier data based on the sorting results. Correspondingly, the step between S103 and S104 may further include: obtaining the fourth identifier data from the first database. The fourth identifier data is used to identify the sorting results of all valid distributed programs, and the total number of valid distributed programs and the sorting order corresponding to each valid distributed program can be determined based on the fourth identifier data.

[0044] For example, if the initial number of distributed programs is 5, and the sequence numbers are "1, 2, 3, 4, 5", and if the initial distributed program with sequence number 3 is determined to be a failed distributed program in step S203, then the number of valid distributed programs is 4. The first database can automatically adjust the sequence numbers of these 4 valid distributed programs to "1, 2, 3, 4" instead of keeping them as "1, 2, 4, 5".

[0045] Optionally, for simplicity, Redis can be preferred as the primary database, as it stores data using an ordered set approach. Redis is a high-performance key-value database; each element in a Redis ordered set is unique and associated with a unique index, allowing for ordered arrangement.

[0046] As can be seen from the above embodiments of the present invention, the embodiments of the present invention first write the first identifier data into the first field corresponding to each initial distributed program in the first database, then read the data stored in the first field corresponding to each initial distributed program in the first data to obtain the second identifier data; then, based on the second identifier data, at least one valid distributed program is determined from all the initial distributed programs; then, based on the sorting result of all valid distributed programs, the timed task data corresponding to each valid distributed program is determined, so that when the time point for executing the timed task is reached, each valid distributed program processes the corresponding timed task data. Distributed processing can be realized, and invalid distributed programs can be dynamically cleaned up to balance the load.

[0047] Example 2

[0048] like Figure 2 As shown, Figure 2 This is a schematic flowchart illustrating a timed task execution method disclosed in Embodiment 2 of this application. The method includes:

[0049] Step S201: Based on the time point when the write operation is performed, determine the first identifier data to be written into the first field corresponding to each initial distributed program in the first database. The data written into the first field corresponding to each initial distributed program this time is different from the data written last time. The first identifier data is used to identify the time point.

[0050] In this embodiment, the first identifier data can be determined based on the timestamp data corresponding to the write operation. That is, the data written in the first field corresponding to each initial distributed program is used to identify the timestamp corresponding to the write operation. The data written in the first field corresponding to all initial distributed programs can be the same or different. For example, after determining a time point to start the write operation, the corresponding timestamp data can be written into the first field corresponding to all distributed programs, making the data written in the first field corresponding to all initial distributed programs the same; alternatively, the corresponding timestamp data can be written based on the data writing time point in the first field corresponding to each initial distributed program, making the data written in the first field corresponding to all initial distributed programs different.

[0051] Step S202: Read the data stored in the first field corresponding to each initial distributed program in the first database to obtain the second identifier data.

[0052] In this embodiment, since the first identification data is used to identify time points, the data stored in the first field corresponding to each initial distributed program in the first database is also used to identify time points. Therefore, the second identification data obtained in step S202 is also used to identify time points.

[0053] Step S203: Based on the second identification data, determine at least one valid distributed program from all the initial distributed programs.

[0054] In this embodiment, the method for determining the valid distributed program in step S203 can be the same as that described in step S103 of embodiment one, or it can be different.

[0055] Optionally, step S203 may include sub-step S203a or sub-step S203b:

[0056] Sub-step S203a: Based on the comparison result of whether all time points identified by the first identifier data and all time points identified by the second identifier data are the same, at least one valid distributed program is determined from all initial distributed programs.

[0057] Specifically, at least one valid distributed program can be determined from all the initial distributed programs by determining whether the time point identified in the second identifier data is the same as the time point identified in the first identifier data.

[0058] Sub-step S203b: Based on the time interval values ​​between all time points identified by the second identification data and the current time point, determine at least one valid distributed program from all initial distributed programs.

[0059] Specifically, considering that all time points identified by the second identifier data are determined based on the time point of the current write operation in step S201, if an initial distributed program is in a failed state, it is impossible to write new data to the first field corresponding to the initial distributed program in step S201. The data read in step S202 is not determined based on the time point of the current write operation in step S201, but based on the time point of the previous write operation. There is a certain time interval between the time point of the previous write operation and the time point of the current write operation, that is, the time interval between these two time points and the current time point will be significantly different. Therefore, step S203 may include: determining at least one valid distributed program from all initial distributed programs based on the time interval between all time points identified by the second identifier data and the current time point.

[0060] Here, the current time point is the time point at which step S203 begins execution. When the time interval between the time point identified by the data corresponding to each initial distributed program and the current time point is less than a preset time threshold, the initial distributed program is determined to be a valid distributed program. When the time interval between the time point identified by the data corresponding to each initial distributed program and the current time point is greater than or equal to the preset time interval threshold, the initial distributed program is determined to be a failed distributed program. The preset time interval threshold must be less than the execution cycle of the scheduled task; otherwise, it is impossible to determine which distributed programs are in a failed state.

[0061] For example, if the time point of the data identifier stored in the first field corresponding to an initial distributed program is 13:50:21, and the current time point is 13:50:23, and the preset time interval threshold is 10s, then the time interval between the time point of the data identifier stored in the first field corresponding to the initial distributed program and the current time point is 2s, which is less than the preset time interval threshold of 10s, and the initial distributed program can be determined as a valid distributed program.

[0062] For example, if the time point of the data identifier stored in the first field corresponding to an initial distributed program is 13:49:21, and the current time point is 13:50:23, and the preset time interval threshold is 10s, then the time interval between the time point of the data identifier stored in the first field corresponding to the initial distributed program and the current time point is 62s, which is greater than the preset time interval threshold of 10s. Therefore, the initial distributed program can be identified as a failed distributed program.

[0063] Step S204: Based on the sorting results of all valid distributed programs, determine the timed task data corresponding to each valid distributed program, so that when the time point for executing the timed task arrives, each valid distributed program processes the corresponding timed task data.

[0064] In this embodiment, step S204 is basically the same as or similar to step S104 in embodiment one, and will not be described again here.

[0065] As can be seen from the above embodiments of the present invention, the embodiments of the present invention first determine the first identifier data in the first field corresponding to each initial distributed program in the first database based on the time point when the write operation is performed, and then read the data stored in the first field corresponding to each initial distributed program in the first database to obtain the second identifier data; next, based on the second identifier data, at least one valid distributed program is determined from all initial distributed programs; then, based on the sorting result of all valid distributed programs, the timed task data corresponding to each valid distributed program is determined, so that when the time point for the execution of the timed task is reached, each valid distributed program processes the corresponding timed task data. Distributed processing can be realized, and invalid distributed programs can be dynamically cleaned up to balance the load.

[0066] Example 3

[0067] like Figure 3 As shown, Figure 3 This is a schematic flowchart illustrating a timed task execution method disclosed in Embodiment 3 of this application. The method includes:

[0068] Step S301: Write the first identifier data into the first field corresponding to each initial distributed program in the first database. The data written into the first field corresponding to each initial distributed program this time is different from the data written last time.

[0069] In this embodiment, step S301 is basically the same as or similar to step S101 in embodiment one or step S201 in embodiment two, and will not be described again here.

[0070] Step S302: Read the data stored in the first field corresponding to each initial distributed program in the first database to obtain the second identifier data.

[0071] In this embodiment, step S302 is basically the same as or similar to step S102 in embodiment one or step S202 in embodiment two, and will not be described again here.

[0072] Step S303: Based on the second identification data, determine at least one valid distributed program from all the initial distributed programs.

[0073] In this embodiment, step S303 is basically the same as or similar to step S103 in embodiment one or step S203 in embodiment two, and will not be described again here.

[0074] Step S304: Based on the total number of all valid distributed programs and the number of task entries in all timed task data, determine the timed task data corresponding to each valid distributed program, so that when the time point for timed task execution is reached, each valid distributed program processes the corresponding timed task data.

[0075] In this embodiment, the execution of sub-step S304a or sub-step S304b can be determined based on the total number of all valid distributed programs.

[0076] Sub-step S304a: When the total number of all valid distributed programs is greater than or equal to the number of tasks in all timed task data, all timed task data is allocated to one valid distributed program for processing, so that when the time point for timed task execution is reached, each valid distributed program processes the corresponding timed task data.

[0077] Sub-step S304b: When the total number of all valid distributed programs is less than the number of tasks corresponding to all timed task data, determine the timed task data corresponding to each valid distributed program based on the number of tasks in all timed task data and the sorting order of all valid distributed programs, so that when the time point for executing the timed task is reached, each valid distributed program processes the corresponding timed task data.

[0078] In cases where the total amount of data to be processed for all scheduled tasks is relatively small, in order to avoid errors when multiple effective distributed programs are executed in coordination, and to minimize the impact on the efficiency of scheduled task data processing, sub-step S304a can be executed. That is, when the total number of all effective distributed programs is greater than or equal to the number of tasks in all scheduled task data, all scheduled task data is allocated to one effective distributed program for processing.

[0079] When the total amount of data to be processed for all scheduled tasks is large, in order to improve the efficiency of scheduled task data processing, sub-step S304b can be executed. That is, when the total number of all effective distributed programs is less than the number of tasks corresponding to all scheduled task data, all scheduled task data is distributed to multiple effective distributed programs for processing.

[0080] Optionally, the total amount of timed task data to be processed can be divided into multiple parts based on the total amount of all valid distributed programs. Then, each valid distributed program determines its corresponding timed task data according to the corresponding sorting order. When the timed task is triggered, each valid distributed program processes its corresponding timed task data.

[0081] Optionally, in order to minimize the occurrence of errors when multiple effective distributed programs are executed in coordination and to shorten the overall data processing time, it is preferable that the number of task data corresponding to the timed task data of all effective distributed programs is the same; or, the number of task data corresponding to the timed task data of the last effective distributed program is greater than that of the other effective distributed programs, and the number of task data corresponding to the timed task data of the other effective distributed programs is the same.

[0082] If the number of tasks corresponding to all scheduled task data is divisible by the total number of all valid distributed programs, then the number of tasks corresponding to all valid distributed programs can be preset to be the same. If the number of tasks corresponding to all scheduled task data is not divisible by the total number of all valid distributed programs, then the remaining number of tasks can be preset to be assigned to the last valid distributed program in the sorting.

[0083] For example, if the total number of tasks corresponding to all scheduled task data is 100, and the total number of all valid distributed programs is 4, then the number of scheduled tasks corresponding to each valid distributed program can be preset to 25.

[0084] For example, if the total number of tasks corresponding to all scheduled task data is 105, and the total number of all valid distributed programs is 4, then it can be preset that the number of tasks corresponding to the scheduled tasks of the top 3 valid distributed programs is 25 each, and the number of tasks corresponding to the scheduled tasks of the 4th valid distributed program is 30.

[0085] As can be seen from the above embodiments of the present invention, after determining at least one valid distributed program based on the second identifier data, the embodiments of the present invention further determine the timed task data corresponding to each valid distributed program based on the total number of all valid distributed programs and the number of task items of all timed task data. When the time point for the execution of the timed task is reached, each valid distributed program processes the corresponding timed task data. This not only avoids the occurrence of errors when multiple valid distributed programs are executed in coordination as much as possible, but also ensures data processing efficiency.

[0086] Example 4

[0087] like Figure 4 As shown, Figure 4 This is a schematic diagram of a timed task execution device disclosed in Embodiment 4 of this application. The device includes:

[0088] The first writing module 401 is used to write the first identifier data into the first field corresponding to each initial distributed program in the first database, wherein the data written into the first field corresponding to each initial distributed program this time is different from the data written last time.

[0089] The reading module 402 is used to read the data stored in the first field corresponding to each initial distributed program in the first database to obtain the second identifier data;

[0090] The first determining module 403 is used to determine at least one valid distributed program from all the initial distributed programs based on the second identification data;

[0091] The second determining module 404 is used to determine the timed task data corresponding to each valid distributed program based on the sorting result of all valid distributed programs, so that when the time point for executing the timed task is reached, each valid distributed program processes the corresponding timed task data.

[0092] In this embodiment, both the first identification data and the second identification data are used to identify data points; correspondingly, the writing module 401 is also used to determine the first identification data based on the time point when the writing operation is performed.

[0093] In this embodiment, the first determining module 403 is further configured to determine at least one valid distributed program from all initial distributed programs based on the time interval between all time points identified by the second identifier data and the current time point; or it is further configured to determine at least one valid distributed program from all initial distributed programs based on the comparison result of whether all time points identified by the first identifier data and all time points identified by the second identifier data are the same.

[0094] In this embodiment, the timed task execution device further includes:

[0095] The module is used to obtain third identification data based on the startup time of each initial distributed program, wherein the third identification data identifies the startup time of each initial distributed program at the nanosecond level.

[0096] The second writing module is used to write the third identifier data into the second field corresponding to each initial distributed program in the first database.

[0097] In this embodiment, the first database can automatically sort all valid distributed programs and generate fourth identifier data based on the sorting results; correspondingly, the scheduled task execution device further includes:

[0098] The acquisition module is used to retrieve the fourth identifier data from the first database.

[0099] In this embodiment, the first database is a Redis database, which stores data using an ordered set approach.

[0100] In this embodiment, the first determining module 403 is further configured to allocate all timed task data to one valid distributed program for processing when the total number of all valid distributed programs is greater than or equal to the number of task items of all timed task data.

[0101] In this embodiment, the first determining module 403 is further configured to determine the timed task data corresponding to each valid distributed program based on the number of tasks in the total number of valid distributed programs and the sorting order of all valid distributed programs when the total number of valid distributed programs is less than the number of tasks corresponding to all timed task data.

[0102] In this embodiment, the number of task data corresponding to all valid distributed programs is the same; or, the number of task data corresponding to the last valid distributed program is greater than that of other valid distributed programs, and the number of task data corresponding to the other valid distributed programs is the same.

[0103] The timed task execution device of this embodiment can realize the corresponding timed task execution methods in the foregoing multiple method embodiments and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0104] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0105] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A method for executing a scheduled task, characterized in that, include: Write the first identifier data into the first field corresponding to each initial distributed program in the first database. The data written into the first field corresponding to each initial distributed program this time is different from the data written last time. Read the data stored in the first field corresponding to each initial distributed program in the first database to obtain the second identifier data; Based on the time interval between all time points identified by the second identification data and the current time point, at least one valid distributed program is determined from all the initial distributed programs; wherein, when the time interval between the time point identified by the data corresponding to the initial distributed program and the current time point is less than a preset time threshold, the initial distributed program is determined as the valid distributed program; Alternatively, based on the comparison results of whether all time points identified by the first identification data and all time points identified by the second identification data are the same, at least one valid distributed program is determined from all the initial distributed programs; wherein, when the data corresponding to the initial distributed program in the second identification data is the same as the data corresponding to the initial distributed program in the first identification data, the initial distributed program is determined to be the valid distributed program. Based on the sorting results of all the effective distributed programs, the timed task data corresponding to each effective distributed program is determined, so that when the time point for executing the timed task is reached, each effective distributed program processes the corresponding timed task data.

2. The method according to claim 1, characterized in that, Both the first and second identification data are used to identify time points; correspondingly, The step of writing the first identifier data into the first field corresponding to each initial distributed program in the first database includes: determining the first identifier data to be written into the first field corresponding to each initial distributed program in the first database based on the time point when the write operation is performed.

3. The method according to claim 1, characterized in that, The method further includes: A third identifier is obtained based on the startup time of each initial distributed program, wherein the third identifier identifies the startup time of each initial distributed program at the nanosecond level. The third identifier data is written into the second field corresponding to each initial distributed program in the first database.

4. The method according to claim 1, characterized in that, The method includes: the first database automatically sorts all the valid distributed programs, and generates fourth identifier data based on the sorting result; Correspondingly, after determining at least one valid distributed program from all the initial distributed programs based on the second identification data, the method further includes: obtaining the fourth identification data from the first database.

5. The method according to claim 4, characterized in that, The first database is a Redis database, which stores data using an ordered set approach.

6. The method according to claim 1, characterized in that, The step of determining the timed task data corresponding to each of the effective distributed programs based on the sorting results of all the effective distributed programs includes: When the total number of all effective distributed programs is greater than or equal to the number of tasks in all the scheduled task data, all the scheduled task data is allocated to one of the effective distributed programs for processing.

7. The method according to claim 1, characterized in that, The step of determining the timed task data corresponding to each of the effective distributed programs based on the sorting results of all the effective distributed programs includes: When the total number of all valid distributed programs is less than the number of tasks corresponding to all the timed task data, the timed task data corresponding to each valid distributed program is determined according to the number of tasks in all the timed task data and the sorting order of all the valid distributed programs.

8. The method according to claim 7, characterized in that, All of the effective distributed programs have the same number of task data corresponding to their scheduled task data; or, the number of task data corresponding to the last effective distributed program is greater than that of the other effective distributed programs, and the number of task data corresponding to the other effective distributed programs is the same.

9. A timed task execution device, characterized in that, include: The first writing module is used to write the first identifier data into the first field corresponding to each initial distributed program in the first database, wherein the data written into the first field corresponding to each initial distributed program this time is different from the data written last time. The reading module is used to read the data stored in the first field corresponding to each initial distributed program in the first database to obtain the second identifier data; The first determining module is configured to determine at least one valid distributed program from all the initial distributed programs based on the time interval between all time points identified by the second identifier data and the current time point; wherein, when the time interval between the time point identified by the data corresponding to the initial distributed program and the current time point is less than a preset time threshold, the initial distributed program is determined to be the valid distributed program; or, based on the comparison result of whether all time points identified by the first identifier data and all time points identified by the second identifier data are the same, at least one valid distributed program is determined from all the initial distributed programs; wherein, when the data corresponding to the initial distributed program in the second identifier data is the same as the data corresponding to the initial distributed program in the first identifier data, the initial distributed program is determined to be the valid distributed program; The second determining module is used to determine the timed task data corresponding to each of the effective distributed programs based on the sorting result of all the effective distributed programs, so that when the time point for executing the timed task is reached, each of the effective distributed programs processes the corresponding timed task data.

Citation Information

Patent Citations

  • Distributed scheduling method and system of task

    CN105975334A

  • Host node state determination method and device, host node and storage medium

    CN109302445A