Task execution method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202211477534.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-23
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2042-11-23
AI Technical Summary
[0003]然而,现有的定时任务一般按照固定频率的方式执行定时任务来实现数据同步,而定时任务的频率难以确定,频率太大使得数据更新延迟性较大;频率太小则会增加系统压力,且每次执行定时任务同步的数据量可能较少,效率低下
[0035] A processor, connected to the memory, is configured to implement the method provided in the first aspect of the technical solution by executing computer-executable instructions stored in the memory.
Smart Images

Figure CN116909693B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a task execution method, apparatus, electronic device, and storage medium. Background Technology
[0002] In existing technologies, data synchronization is generally performed through scheduled tasks to ensure data real-time performance.
[0003] However, existing scheduled tasks generally perform scheduled tasks at a fixed frequency to achieve data synchronization. The frequency of scheduled tasks is difficult to determine. If the frequency is too high, the data update delay will be large; if the frequency is too low, it will increase the system pressure, and the amount of data synchronized each time the scheduled task is executed may be small, resulting in low efficiency. Summary of the Invention
[0004] In view of this, embodiments of this application aim to provide a task execution method, apparatus, electronic device, and storage medium.
[0005] The technical solution of this application is implemented as follows:
[0006] In a first aspect, embodiments of this application provide a task execution method, the method comprising:
[0007] A first sleep probability group for a synchronization task is determined; wherein, a first sleep probability group includes: multiple first sleep probabilities of the synchronization task, and the nth first sleep probability is the first sleep probability of the synchronization task in the nth first time window; wherein, n is a positive integer less than or equal to N; and N is the total number of first time windows contained in one execution cycle of the synchronization task;
[0008] Based on the first sleep probability group and the historical execution status information of the synchronization task, select the second sleep probability group that has the highest matching degree with the historical execution status information from the first sleep probability group;
[0009] Based on the current execution status information of the synchronization task, determine the amount of data to be synchronized within the current second time window;
[0010] Based on the amount of data to be synchronized and the target sleep probability, determine whether to execute the synchronization task corresponding to the current second time window; wherein, the target sleep probability is the sleep probability in the second sleep probability group that corresponds to the current second time window.
[0011] Based on the above scheme, the step of selecting the second sleep probability group with the highest matching degree with the historical execution status information from the first sleep probability group, according to the first sleep probability group and the historical execution status information of the synchronization task, includes:
[0012] Based on the historical execution status information, a first function is determined; wherein the first function is a function with the expected execution time of the synchronous task as a variable; the expected execution time is determined based on the first sleep probability group;
[0013] Based on the first function, determine the degree of matching between the first sleep probability group and the historical execution status information;
[0014] When the matching degree meets the preset conditions, the second sleep probability group with the highest matching degree with the historical execution status information is selected from the first sleep probability group.
[0015] Based on the above scheme, the method further includes:
[0016] The first dormancy probability group is traversed until a second dormancy probability group that satisfies the matching degree and the preset condition is found.
[0017] Based on the above scheme, the preset conditions include at least:
[0018] The matching degree is greater than a first set threshold.
[0019] Based on the above scheme, determining whether to execute the synchronization task corresponding to the current second time window according to the amount of data to be synchronized and the target sleep probability includes:
[0020] The adjustment duration is determined based on the amount of data to be synchronized.
[0021] Based on the adjusted duration, update the execution time of the next synchronous task to be executed.
[0022] Based on the above scheme, determining whether to execute the synchronization task corresponding to the current second time window according to the amount of data to be synchronized and the target sleep probability includes:
[0023] The adjustment duration is determined based on the amount of data to be synchronized.
[0024] Based on the adjusted duration, update the execution time of the next synchronous task to be executed.
[0025] Based on the above scheme, determining the adjustment duration according to the amount of data to be synchronized includes:
[0026] When the amount of data to be synchronized is less than the second set threshold, the adjustment duration is determined based on the duration of the second time window and the target sleep probability;
[0027] When the amount of data to be synchronized is greater than or equal to the second set threshold, the adjustment duration is determined to be a preset duration.
[0028] Secondly, embodiments of this application provide a task execution apparatus, the apparatus comprising:
[0029] A first determining module is used to determine a first sleep probability group for a synchronization task; wherein, a first sleep probability group includes: multiple first sleep probabilities of the synchronization task, and the nth first sleep probability is the first sleep probability of the synchronization task in the nth first time window; wherein, n is a positive integer less than or equal to N; and N is the total number of first time windows contained in one execution cycle of the synchronization task.
[0030] The selection module is used to select, based on the first sleep probability group and the historical execution status information of the synchronization task, the second sleep probability group that has the highest matching degree with the historical execution status information from the first sleep probability group;
[0031] The second determining module is used to determine the amount of data to be synchronized within the current second time window based on the current execution status information of the synchronization task.
[0032] The third determining module is used to determine whether to execute the synchronization task corresponding to the current second time window based on the amount of data to be synchronized and the target sleep probability; wherein, the target sleep probability is the sleep probability in the second sleep probability group that corresponds to the current second time window.
[0033] Thirdly, embodiments of this application provide an electronic device, including:
[0034] Memory, which stores computer-readable instructions;
[0035] A processor, connected to the memory, is configured to implement the method provided in the first aspect of the technical solution by executing computer-executable instructions stored in the memory.
[0036] Fourthly, embodiments of this application provide a computer storage medium storing computer-executable instructions, which, when executed, can implement the method provided in the first aspect of the technical solution.
[0037] The task execution method, apparatus, electronic device, and storage medium provided in this application can determine a first sleep probability group for a synchronous task. Each first sleep probability group includes multiple first sleep probabilities of the synchronous task, where the nth first sleep probability is the first sleep probability of the synchronous task within the nth first time window. Here, n is a positive integer less than or equal to N, and N is the total number of first time windows included in one execution cycle of the synchronous task. This allows the execution cycle of a scheduled task to be divided into multiple time windows, facilitating the determination of the execution status of the scheduled task within each time window. Based on the first sleep probability group and the historical execution history of the synchronous task... The system first selects the second sleep probability group from the first sleep probability group, choosing the one with the highest matching degree to the historical execution status information. This improves the execution accuracy of the scheduled task by matching the sleep probability with the historical execution status information of the synchronization task and selecting the second sleep probability group with the highest matching degree. Based on the current execution status information of the synchronization task, the amount of data to be synchronized within the current second time window is determined. Based on the amount of data to be synchronized and the target sleep probability, it is determined whether to execute the synchronization task corresponding to the current second time window. The target sleep probability is the sleep probability in the second sleep probability group that corresponds to the current second time window. This allows for determining the corresponding sleep probability based on the time window of the current synchronization task, improving the execution accuracy of the scheduled task. Furthermore, by combining the real-time data update volume to determine whether to execute the synchronization task, unnecessary executions of scheduled tasks can be reduced based on the amount of updated data, thus reducing system operating pressure. Attached Figure Description
[0038] Figure 1 A flowchart illustrating a task execution method provided in this application embodiment. Figure 1 ;
[0039] Figure 2 A flowchart illustrating a task execution method provided in this application embodiment. Figure 2 ;
[0040] Figure 3 A flowchart illustrating a task execution method provided in this application embodiment. Figure 3 ;
[0041] Figure 4 A flowchart illustrating a method for dynamically adjusting a timed task based on a sliding time window, provided in an embodiment of this application;
[0042] Figure 5 This application provides a schematic diagram illustrating the execution process of a sliding time window in an embodiment of the present application.
[0043] Figure 6This is a schematic diagram of the structure of a task execution device provided in an embodiment of this application;
[0044] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0045] To gain a more detailed understanding of the features and technical content of this application, the implementation of this application will be described in detail below with reference to the accompanying drawings. The accompanying drawings are for reference and illustration only and are not intended to limit this application.
[0046] like Figure 1 As shown in the figure, this application provides a task execution method, the method including:
[0047] Step S110: Determine the first sleep probability group of the synchronization task; wherein, a first sleep probability group includes: multiple first sleep probabilities of the synchronization task, the nth first sleep probability is the first sleep probability of the synchronization task in the nth first time window; wherein, n is a positive integer less than or equal to N; N is the total number of first time windows contained in the synchronization task in one execution cycle;
[0048] Step S120: Based on the first sleep probability group and the historical execution status information of the synchronization task, select the second sleep probability group that has the highest matching degree with the historical execution status information from the first sleep probability group;
[0049] Step S130: Determine the amount of data to be synchronized within the current second time window based on the current execution status information of the synchronization task;
[0050] Step S140: Based on the amount of data to be synchronized and the target sleep probability, determine whether to execute the synchronization task corresponding to the current second time window; wherein, the target sleep probability is the sleep probability in the second sleep probability group that corresponds to the current second time window.
[0051] The synchronization tasks can be those required to perform data synchronization. Specifically, the synchronization tasks include, but are not limited to, tasks that update and synchronize data in real time, such as retrieving user order data from a third party, scanning the local database to correct fields, generating data reports, and / or periodically scanning inventory to issue inventory warnings.
[0052] The first sleep probability is negatively correlated with the execution probability of the synchronization task. That is, the higher the first sleep probability, the lower the probability of executing the synchronization task. Therefore, in this embodiment, the magnitude of the first sleep probability can be used to reflect the magnitude of the execution probability of the synchronization task, thereby determining whether to execute the synchronization task.
[0053] The execution cycle can be a complete time period from the start of execution to the completion of the synchronous task, such as 1 minute, 1 hour and / or 1 day.
[0054] The first time window can be each time period after the execution cycle is divided, such as 12 o'clock to 1 o'clock. The duration of the time window can be any length, such as 1 minute, 1 hour and / or 1 day.
[0055] The first sleep probability group consists of the first sleep probability within multiple time windows, used to indicate the execution probability of synchronous tasks within multiple time windows.
[0056] In this embodiment, the execution cycle can be divided into multiple first time windows, and a first sleep probability is set for each first time window. The multiple first sleep probabilities form a first sleep probability group. Specifically, one day can be used as the execution cycle of the synchronization task, and the execution cycle can be divided into 3 time windows, each with a duration of 8 hours. A corresponding first sleep probability is set within each time window, for example, w1 = 10%, w2 = 20%, and w3 = 30%. The first sleep probabilities within the multiple time windows form a first sleep probability group W: (10%, 20%, 30%).
[0057] The historical execution status information is used to indicate the historical execution status of the synchronization task. Specifically, the historical execution status information includes, but is not limited to, the execution time period, execution duration, number of executions, and / or the amount of data synchronized during the execution.
[0058] In this embodiment, the second sleep probability group can be selected based on the matching degree between the first sleep probability group and historical execution status information. Specifically, the execution time period, execution duration, number of executions, and / or the amount of data synchronized during the execution of the synchronization task according to the first sleep probability group can be matched with the historical execution status information. For example, if the number of executions of the task according to multiple first sleep probability groups is 4, 5, and 6, respectively, while the number of executions of the synchronization task in the historical execution status information is 7, it can be considered that the first sleep probability group with 6 executions has a relatively higher matching degree with the historical execution status information in terms of the number of executions. Through matching in multiple aspects, the first sleep probability group with the highest matching degree with the historical execution status information can be identified as the second sleep probability group.
[0059] In this embodiment, the historical execution status information can be updated, and then the highest matching degree can be selected as the second sleep probability group by re-matching with the first sleep probability group. In this way, the sleep probability corresponding to each time window can be adjusted in real time based on the most recent historical data, thereby improving task execution accuracy while ensuring real-time data synchronization.
[0060] In this embodiment, considering that user data changes vary across different time periods, the probability of dormancy for each time period is determined by matching it with historical execution status information. For example, user activity is low in the early morning, resulting in minimal, sometimes even zero, data changes. Therefore, synchronization tasks executed during this period may not have achieved new data synchronization, rendering them ineffective. Thus, matching based on historical execution status information reduces the number of ineffective tasks in synchronization, lowers system load, and improves system performance.
[0061] In the embodiments of this application, the methods for determining the first sleep probability group include, but are not limited to, random initialization.
[0062] In this embodiment, multiple first dormant probability groups can be encoded, and a computational model based on a genetic algorithm can be established to determine multiple optimal first dormant probability groups. Specifically, multiple first dormant probability groups are used as multiple individuals to form an initial population, which serves as the first generation population for the genetic algorithm. Multiple individuals are selected from the first generation population in a manner proportional to their matching degree, and crossover and mutation operations are performed to obtain a new generation population. The selection, crossover, and mutation processes are then repeated to continue optimizing the population. When the number of repetitions reaches a predetermined number, the final optimization result can be obtained. In this way, multiple optimal first dormant probability groups can be quickly optimized using a genetic algorithm, thereby improving the matching degree between the first dormant probability groups and historical execution status information, and thus enabling the selection of first dormant probability groups with higher matching degrees as second dormant probability groups.
[0063] The current execution status information is used to indicate the current execution status of the synchronization task. Specifically, the current execution status information includes, but is not limited to, the pending execution time period, the pending execution duration, the pending execution count, and / or the amount of data to be synchronized.
[0064] The second time window can be the current time period, such as from 12 o'clock to 1 o'clock, and the length of the time window can be any length such as 1 minute, 1 hour and / or 1 day.
[0065] In this embodiment, the synchronization task can be executed at any point within the second time window. Furthermore, the length of the second time window can be determined based on the business requirements corresponding to the synchronization task. For example, if the business requirement delay cannot exceed 5 minutes, then the length of the second time window cannot exceed 5 minutes.
[0066] The target sleep probability is the sleep probability in the second sleep probability group that corresponds to the current second time window. For example, if the current second time window is from 12:00 to 1:00, then the target sleep probability is the sleep probability of the time period from 12:00 to 1:00 in the second sleep probability group.
[0067] In this embodiment, the decision to perform a synchronization task within a time window can be determined by the amount of data to be synchronized and the target sleep probability. Specifically, when the amount of data to be synchronized is small and / or the target sleep probability is high, it is possible to choose not to perform the synchronization task within the time window, thereby improving the accuracy of the task execution, reducing system pressure, and improving system performance.
[0068] In this embodiment, the execution cycle of the synchronization task can be divided into multiple time windows, and multiple first sleep probability groups can be set. Then, the first sleep probability group with the highest matching degree can be selected as the second sleep probability group. In this way, the second sleep probability group can be dynamically determined based on historical execution status information, thereby adjusting the expected execution time of the synchronization task to be executed in real time. While ensuring the real-time performance of data synchronization as much as possible, the number of unnecessary synchronization tasks can be reduced, the system operating pressure can be reduced, and the system performance can be improved.
[0069] In the embodiments of this application, such as Figure 2 As shown, the step of selecting the second sleep probability group with the highest matching degree with the historical execution status information from the first sleep probability group based on the first sleep probability group and the historical execution status information of the synchronization task includes:
[0070] Step S121: Determine a first function based on the historical execution status information; wherein the first function is a function with the expected execution time of the synchronous task as a variable; the expected execution time is determined based on the first sleep probability group;
[0071] Step S122: Determine the matching degree between the first sleep probability group and the historical execution status information according to the first function;
[0072] Step S123: When the matching degree meets the preset conditions, select the second sleep probability group with the highest matching degree with the historical execution status information from the first sleep probability group.
[0073] In this embodiment, the first function may include the historical execution time of the synchronization task, which is determined based on historical execution status information. Thus, by inputting the expected execution time of the synchronization task into the first function and comparing it with the historical execution time, the degree of matching between the first sleep probability group and the historical execution status information is determined. Specifically, the smaller the error between the expected execution time of the synchronization task and the historical execution time, the higher the degree of matching between the first sleep probability group and the historical execution status information.
[0074] The preset condition can be that the matching degree between the current first sleep probability group and the historical execution status information is greater than a set threshold.
[0075] In this embodiment, the matching degree between the first sleep probability group and the historical execution status information is determined by setting a function. The matching degree between each first sleep probability group and the historical execution status information is expressed intuitively by numerical means, which facilitates comparison and selection of the first sleep probability group with the highest matching degree.
[0076] In this embodiment of the application, the method further includes:
[0077] The first dormancy probability group is traversed until a second dormancy probability group that satisfies the matching degree and the preset condition is found.
[0078] In the embodiments of this application, the traversal method includes, but is not limited to, sequential traversal and / or random traversal.
[0079] In this embodiment of the application, the preset conditions include at least:
[0080] The matching degree is greater than a first set threshold.
[0081] In this embodiment, by reasonably setting a threshold, the first sleep probability group with a matching degree exceeding the threshold can be directly used as the second sleep probability group. This reduces the number of calculations and improves computational efficiency while ensuring the matching degree between the second sleep probability group and the execution status information.
[0082] In the embodiments of this application, such as Figure 3 As shown, determining whether to execute the synchronization task corresponding to the current second time window based on the amount of data to be synchronized and the target sleep probability includes:
[0083] Step S141: Determine the adjustment duration based on the amount of data to be synchronized;
[0084] Step S142: Update the execution time of the next synchronization task to be executed according to the adjusted duration.
[0085] The adjustment duration can be the length of time to be adjusted, such as 1 second, 1 minute, and / or 1 hour. In this embodiment, the adjustment duration is used to adjust the second time window. For example, if the second time window is from 12:00 to 1:00, and the adjustment duration is 1 hour, then the adjusted second time window is from 1:00 to 2:00. The maximum value of the adjustment duration is the length of the current time window.
[0086] In this embodiment, the adjustment duration can be determined based on the amount of data to be synchronized. When the amount of data to be synchronized is small, it can be assumed that a synchronization task is not currently required, thus allowing for a longer adjustment duration. Conversely, when the amount of data to be synchronized is large, it can be assumed that a synchronization task is currently required, thus allowing for a shorter adjustment duration to facilitate the execution of the synchronization task.
[0087] In this embodiment of the application, after determining the adjustment duration, the execution time of the currently pending synchronous task can be updated, that is, the synchronous task is executed after the time window slides to the next time period according to the adjustment duration.
[0088] In this embodiment of the application, determining the adjustment duration based on the amount of data to be synchronized includes:
[0089] When the amount of data to be synchronized is less than the second set threshold, the adjustment duration is determined based on the duration of the second time window and the target sleep probability;
[0090] When the amount of data to be synchronized is greater than or equal to the second set threshold, the adjustment duration is determined to be a preset duration.
[0091] In this embodiment, the second set threshold can be determined based on historical execution status information. For example, the amount of data synchronized by synchronization tasks executed within the same time window in the historical execution status information can be used as the second set threshold. In this way, the execution status of synchronization tasks can be adjusted in real time based on the most recent historical execution status information, improving the execution accuracy of synchronization tasks while ensuring the real-time nature of data synchronization.
[0092] In this embodiment of the application, a second set threshold can also be determined based on the specific needs of the business corresponding to the synchronous task executed within the current time window.
[0093] In this embodiment, determining the adjustment duration based on the length of the second time window and the target sleep probability can be achieved by multiplying the target sleep probability by the length of the time window as the adjustment duration. This allows for determination based on the sleep probability.
[0094] The preset duration can be a preset adjustment duration, determined based on the minimum execution granularity of the synchronous task, i.e., the execution frequency. In this embodiment, to ensure task execution accuracy, the preset duration is generally set to 1 minute.
[0095] In this embodiment of the application, the method further includes:
[0096] After the synchronization task is completed according to the execution time, the amount of data to be synchronized is re-determined.
[0097] In this embodiment, the amount of data to be synchronized is redefined after each synchronization task is completed based on the execution time. Specifically, the amount of data to be synchronized can be determined based on the most recent historical execution status information. For example, if the current time window length is 5 minutes, the amount of synchronized data in the previous 5 minutes of the current time window can be used as a reference to determine the amount of data to be synchronized. In this way, the duration can be dynamically determined and adjusted in real time based on historical execution status information, providing high flexibility.
[0098] In related technologies, as project workloads increase, the demand for data synchronization also grows. Currently, most systems can achieve data synchronization by configuring scheduled tasks, such as periodically retrieving user order data from third parties, periodically scanning the local database for field corrections, periodically generating data reports, and periodically scanning inventory to generate inventory alerts. However, as the number of scheduled tasks increases, the resource consumption on the server running these tasks also increases, significantly increasing the server's workload.
[0099] Scheduled tasks generally fall into two categories: those that execute at fixed times and those that execute at fixed frequencies, such as every 10 seconds, every minute, or every hour, to synchronize data. Currently, optimizations for scheduled tasks include unified scheduling and management, real-time monitoring of task execution and manual adjustment of frequency, and sorting of tasks and executing them according to priority. However, these solutions typically achieve data synchronization through a fixed frequency or manually adjusted frequency.
[0100] The existing scheduled tasks that execute at a fixed frequency have the following drawbacks:
[0101] 1. The frequency of scheduled tasks is difficult to determine. Too high a frequency will result in greater data update latency; too low a frequency will result in faster execution speed, which can reduce data update latency, but will increase server pressure, especially for large-scale scheduled task systems, where system performance will be drastically reduced.
[0102] 2. The amount of data change (hereinafter referred to as the amount of data synchronization) generated by each execution of a scheduled task varies. Generally speaking, for user data, user activity levels differ throughout the day, with significantly lower activity levels in the early morning compared to other times. This results in minimal or even zero data changes generated by scheduled tasks during these periods, and these scheduled tasks that produce no data changes can be considered invalid.
[0103] Therefore, based on this, this application proposes a method for dynamically adjusting timed tasks based on a sliding time window. The basic idea is as follows: First, the optimal weights (hereinafter referred to as dormancy probabilities) for each hourly time period within a day are trained offline using the speed, randomness, and global convergence characteristics of a genetic algorithm for solving optimization problems. Then, the sliding time window is used to track the synchronization status of the most recent historical data in real time, and the dormancy probabilities trained by the genetic algorithm guide the calculation of the sliding step size, thereby achieving dynamic adjustment of the timed task. The optimal weights are one type of the aforementioned dormancy probabilities, each hourly time period is one type of the aforementioned first time window, the time window is one type of the aforementioned second time window, and the most recent historical data synchronization status is one type of the aforementioned historical execution status information.
[0104] This scheme first uses a genetic algorithm to train an array of sleep probabilities for different time periods throughout the day offline, and then uses a sliding time window to control the execution step size of the scheduled task in real time. Figure 4 The diagram shown is a flowchart illustrating a method for dynamically adjusting a timed task based on a sliding time window, as provided in an embodiment of this application.
[0105] Depend on Figure 4 It can be seen that the method has the following steps:
[0106] Step 1: Establish the error model for the genetic algorithm;
[0107] A genetic algorithm is used to train the dormancy probability for each time period. This dormancy probability enables dynamic adjustment of the sliding step size for subsequent sliding time windows. The higher the dormancy probability, the larger the sliding step size, and vice versa. Therefore, the dormancy probability for each hourly time period within a 24-hour day can be encoded using real-number encoding. Each encoded probability is represented as an individual w in a population of size N. i (i = 1, 2... N), also called chromosomes, w i It is expressed as follows:
[0108] w i =(w i1 ,w i2 ...w ik ,...,w i24 (1)
[0109] In equation (1), w ik Represents individual w i The probability of dormancy during the time interval [k-1,k] hours is 0 ≤ w ik The value is ≤1. The larger the value, the lower the probability of the scheduled task being executed during that time period.
[0110] In genetic algorithms, the fitness of an individual is used to evaluate its quality; the better the individual, the higher its fitness, and the greater its chance of inheritance. Considering that the objective of this application's embodiments is to minimize the error between the actual execution time and the expected execution time, a fitness function f can be established. i as follows:
[0111]
[0112] In equation (2), f i Indicates that the i-th individual follows w i The fitness of executing tasks with a dormant probability; m represents the total number of task executions in a day; at it and et it This represents the actual execution timestamp and expected execution timestamp (in seconds) of a task performed by the i-th individual during a given day. it with et it The closer the values are, the greater the fitness. The fitness is one of the aforementioned matching degrees.
[0113] Step 2: Use a genetic algorithm to train the optimal sleep probability array for each time period of the day;
[0114] Step 2.1 Initialize the population
[0115] Randomly initialize multiple individuals w of size N i (i = 1, 2... N), each individual represents the probability of sleeping at different times of the 24 hours of the day. These multiple individuals form the initial population, which serves as the first generation population for the genetic algorithm.
[0116] Step 2.2 Select
[0117] Genetic algorithms select a batch of individuals from the population as the next generation according to the survival of the fittest selection rule. Individuals with higher fitness have a greater probability of being inherited by the next generation. This application's embodiment uses a roulette wheel selection operator to determine the probability of each individual in the current population being selected, based on a method proportional to the individual's fitness. i The selection probability p of (i = 1, 2, ..., N) i and cumulative selection probability Q i for:
[0118]
[0119] In equation (3): f i Represents individual w i fitness
[0120] Take a random number r∈(0,1), if Q i-1 <r<Qi Under the condition, then individual w i It will be selected as the parent individual to participate in the crossover operation.
[0121] Step 2.3 Cross
[0122] After selection, the resulting population undergoes crossover operations between pairs of individuals according to a certain crossover probability, resulting in two new individuals. To accelerate the population update speed, this application proposes a multi-point crossover method, that is, randomly selecting multiple crossover points between two individuals and exchanging their values.
[0123] Step 2.4 Mutation
[0124] The individual's encoded string is mutated at one or more positions according to a certain mutation probability to generate a new individual.
[0125] Step 2.5 Determine if the termination condition is met.
[0126] Determine if the algorithm meets the convergence condition or reaches the maximum number of iterations. If it does, output the optimal individual and its corresponding attribute weights w = (w1, w2, ... w...). k ,...,w 24 Otherwise, proceed to step 2.2.
[0127] Each generation of the population evolves through selection, crossover, and mutation, producing a new generation of population. This new generation of population continues to evolve, and after several generations of evolution, the algorithm will converge to a certain best individual. This individual is the dormancy probability value for each time period that is required to be solved in the embodiments of this application.
[0128] Step 3: Use a sliding time window to slide the time grid to execute the scheduled task;
[0129] During the execution of a scheduled task, due to the uncertainty of data synchronization, the task is not effective every time it is executed. Generally speaking, the task occurrence maintains a certain continuity within a relatively short time interval. Therefore, a sliding time window can be used to divide the task execution process into time cells. Multiple consecutive time cells form a time window. During the execution of the scheduled task, the window can slide forward along the time cells according to the data synchronization status of the current time window, with a certain step size.
[0130] The specific steps are as follows:
[0131] Step 3.1 Determine the sliding time window parameters: The sliding time window parameters include the window length k, the threshold δ, and the sliding step size step. The window length k and the threshold δ can be determined according to specific business requirements. For example, if the project requires that the delay not exceed 5 minutes and the minimum time execution granularity is 1 minute, then the window length k can be defined as 5, the threshold δ as 1, and the sliding step size must be between the minimum step size 1 (i.e., one time interval) and the maximum step size step. max Between, i.e., 1 ≤ step ≤ step max The sliding step size is one of the aforementioned adjustment durations.
[0132] Step 3.2 Calculate the number of data synchronizations in the current time window, v[tk,t]. v[tk,t] represents the total number of data synchronizations during the execution of the scheduled task from the historical time tk to the current time t.
[0133] Step 3.3 Determine if v[tk,t] is less than the threshold δ. If v[tk,t] < δ, take the product of the window length and the sleep probability of the current hour segment (obtained by the genetic algorithm in step 2) and round it up. Otherwise, to ensure execution accuracy, take the minimum step size of 1. The calculation formula is as follows:
[0134]
[0135] Step 3.4 The sliding time window slides to the next time according to the step size calculated in Step 3.3 and executes the timed task. After each timed task is executed, it returns to Step 3.2 so that the timed task can dynamically adjust the sliding step size in real time based on the historical task execution results.
[0136] like Figure 5 The diagram shown is a schematic representation of a sliding time window execution process provided in an embodiment of this application. Figure 5 As can be seen from this, the data synchronization quantity v[tk,t] in the previous time window is updated based on the total data synchronization quantity during the period from historical time tk to the current time t. When v[tk,t]≥δ, the sliding step size is 1 unit (minimum sliding step size), and when v[tk,t]<δ, the sliding step size is 1 step. max *w.
[0137] Therefore, the method for dynamically adjusting timed tasks based on a sliding time window provided in this application has the following advantages over related technologies:
[0138] 1. To address the difficulty in determining the frequency of scheduled tasks, this application embodiment comprehensively considers the task execution trends and recent historical behavior data for different time periods within a day, dynamically adjusts the execution frequency of scheduled tasks, and ensures the real-time synchronization of data as much as possible, effectively improving the execution accuracy of scheduled tasks;
[0139] 2. To address the issue of invalid execution of scheduled tasks, this application's embodiments utilize a sliding time window combined with a genetic algorithm to predict the next task execution time, thereby reducing the number of invalid task executions, reducing server load, and ultimately improving system performance;
[0140] 3. The timed task optimization system constructed using sliding time windows and genetic algorithms in this application embodiment can realize automatic adjustment of timed tasks without human intervention or the need for expert experience.
[0141] like Figure 6 As shown, this application provides a task execution device, which includes:
[0142] The first determining module 110 is used to determine a first sleep probability group for a synchronization task; wherein, a first sleep probability group includes: multiple first sleep probabilities of the synchronization task, and the nth first sleep probability is the first sleep probability of the synchronization task in the nth first time window; wherein, n is a positive integer less than or equal to N; and N is the total number of first time windows contained in one execution cycle of the synchronization task.
[0143] The selection module 120 is used to select, based on the first sleep probability group and the historical execution status information of the synchronization task, the second sleep probability group that has the highest matching degree with the historical execution status information from the first sleep probability group.
[0144] The second determining module 130 is used to determine the amount of data to be synchronized in the current second time window based on the current execution status information of the synchronization task.
[0145] The third determining module 140 is used to determine whether to execute the synchronization task corresponding to the current second time window based on the amount of data to be synchronized and the target sleep probability; wherein, the target sleep probability is the sleep probability in the second sleep probability group that corresponds to the current second time window.
[0146] In some embodiments, the first determining module 110, the selecting module 120, the second determining module 130, and the third determining module 140 may all be program modules. After being executed by the processor, the program module can realize the functions of the above-mentioned modules.
[0147] In other embodiments, the first determining module 110, the selecting module 120, the second determining module 130, and the third determining module 140 may all be hardware-software hybrid modules; the hardware-software hybrid modules include, but are not limited to, various programmable arrays; the field-programmable arrays include, but are not limited to, field-programmable arrays and / or complex programmable arrays.
[0148] In some embodiments, the first determining module 110, the selecting module 120, the second determining module 130, and the third determining module 140 may all be pure hardware modules; the pure hardware modules include, but are not limited to, application-specific integrated circuits.
[0149] In some embodiments, the selection module 120 is specifically used for:
[0150] Based on the historical execution status information, a first function is determined; wherein the first function is a function with the expected execution time of the synchronous task as a variable; the expected execution time is determined based on the first sleep probability group;
[0151] Based on the first function, determine the degree of matching between the first sleep probability group and the historical execution status information;
[0152] When the matching degree meets the preset conditions, the second sleep probability group with the highest matching degree with the historical execution status information is selected from the first sleep probability group.
[0153] In some embodiments, the apparatus further includes:
[0154] The traversal module is used to traverse the first sleep probability group until a second sleep probability group that satisfies the matching degree and the preset condition is found.
[0155] In some embodiments, the preset conditions include at least:
[0156] The matching degree is greater than a first set threshold.
[0157] In some embodiments, the third determining module 140 is further configured to:
[0158] The adjustment duration is determined based on the amount of data to be synchronized.
[0159] Based on the adjusted duration, update the execution time of the next synchronous task to be executed.
[0160] In some embodiments, the third determining module 140 is further configured to:
[0161] When the amount of data to be synchronized is less than the second set threshold, the adjustment duration is determined based on the duration of the second time window and the target sleep probability;
[0162] When the amount of data to be synchronized is greater than or equal to the second set threshold, the adjustment duration is determined to be a preset duration.
[0163] In some embodiments, the apparatus further includes:
[0164] The fourth determining module is used to redetermine the amount of data to be synchronized after the synchronization task has been completed according to the execution time.
[0165] like Figure 7 As shown in the figure, this application provides an electronic device, which includes:
[0166] Memory, used to store computer-readable instructions;
[0167] A processor, connected to the memory, is configured to implement the methods provided in any of the foregoing embodiments by executing computer-readable instructions, for example, an executable... Figure 1 , Figure 2 , Figure 3 and / or Figure 4 The method shown in the figure.
[0168] The memory can be of various types, such as random access memory, read-only memory, flash memory, etc. The memory can be used for information storage, for example, storing computer-executable instructions. These computer-executable instructions can be various program instructions, such as object program instructions and / or source program instructions.
[0169] The processor can be of various types, such as a central processing unit, microprocessor, digital signal processor, programmable array, application-specific integrated circuit, or image processor. The processor can be connected to the memory via a bus, which can be an integrated circuit bus, etc.
[0170] like Figure 7 As shown, the electronic device may also include a network interface that can be used to interact with peer devices via a network.
[0171] This application also provides a computer storage medium storing computer-executable instructions. When executed, these instructions can implement the methods provided in any of the foregoing embodiments. For example, they can execute... Figure 1 , Figure 2 , Figure 3 and / or Figure 4 The method shown in the figure.
[0172] The computer storage media provided in this embodiment include various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0173] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.
[0174] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.
[0175] In addition, each functional unit in the various embodiments of this application can be integrated into one processing module, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.
[0176] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0177] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A task execution method, characterized in that, The method includes: A first sleep probability group for a synchronization task is determined; wherein, a first sleep probability group includes: multiple first sleep probabilities of the synchronization task, and the nth first sleep probability is the first sleep probability of the synchronization task in the nth first time window; wherein, n is a positive integer less than or equal to N; and N is the total number of first time windows contained in one execution cycle of the synchronization task; Based on the historical execution status information of the synchronization task, a first function is determined; wherein, the first function is a function with the expected execution time of the synchronization task as a variable; the expected execution time is determined based on the first sleep probability group; Based on the first function, determine the degree of matching between the first sleep probability group and the historical execution status information; When the matching degree meets the preset conditions, the second sleep probability group with the highest matching degree with the historical execution status information is selected from the first sleep probability group; Based on the current execution status information of the synchronization task, determine the amount of data to be synchronized within the current second time window; When the amount of data to be synchronized is less than the second set threshold, the adjustment duration is determined based on the duration of the second time window and the target sleep probability. When the amount of data to be synchronized is greater than or equal to the second set threshold, the adjustment duration is determined to be a preset duration; Based on the adjusted duration, the execution time of the next synchronous task to be executed is updated; wherein, the target sleep probability is the sleep probability in the second sleep probability group corresponding to the current second time window.
2. The method according to claim 1, characterized in that, The method further includes: The first dormancy probability group is traversed until a second dormancy probability group whose matching degree satisfies the preset condition is found.
3. The method according to claim 2, characterized in that, The preset conditions include at least the following: The matching degree is greater than a first set threshold.
4. The method according to claim 1, characterized in that, The method further includes: After the synchronization task is completed according to the execution time, the amount of data to be synchronized is re-determined.
5. A task execution device, characterized in that, The device includes: A first determining module is used to determine a first sleep probability group for a synchronization task; wherein, a first sleep probability group includes: multiple first sleep probabilities of the synchronization task, and the nth first sleep probability is the first sleep probability of the synchronization task in the nth first time window; wherein, n is a positive integer less than or equal to N; and N is the total number of first time windows contained in one execution cycle of the synchronization task. The selection module is used to determine a first function based on the historical execution status information of the synchronization task; wherein the first function is a function with the expected execution time of the synchronization task as a variable; the expected execution time is determined based on the first sleep probability group; the matching degree between the first sleep probability group and the historical execution status information is determined according to the first function; when the matching degree meets a preset condition, the second sleep probability group with the highest matching degree with the historical execution status information is selected from the first sleep probability group; The second determining module is used to determine the amount of data to be synchronized within the current second time window based on the current execution status information of the synchronization task. The third determining module is used to determine the adjustment duration based on the duration of the second time window and the target sleep probability when the amount of data to be synchronized is less than the second set threshold; to determine the adjustment duration as a preset duration when the amount of data to be synchronized is greater than or equal to the second set threshold; and to update the execution time of the next synchronization task to be executed based on the adjustment duration; wherein the target sleep probability is the sleep probability in the second sleep probability group that corresponds to the current second time window.
6. An electronic device, characterized in that, include: Memory, which stores computer-readable instructions; A processor, connected to the memory, is configured to implement the method of any one of claims 1 to 4 by executing the computer-readable instructions.
7. A computer storage medium, characterized in that, The computer storage medium stores computer-executable instructions; when the computer-executable instructions are executed by a processor, they can implement the method described in any one of claims 1 to 4.
Citation Information
Patent Citations
Cloud computing optimization method and system fusing and limiting periodic quasi-dormancy, and medium
CN113342462A
SOC sleep control method and device
CN113590205A