CN114281504A - Task scheduling method and device, electronic equipment and computer readable medium - Google Patents

Task scheduling method and device, electronic equipment and computer readable medium Download PDF

Info

Publication number
CN114281504A
CN114281504A CN202111593458.9A CN202111593458A CN114281504A CN 114281504 A CN114281504 A CN 114281504A CN 202111593458 A CN202111593458 A CN 202111593458A CN 114281504 A CN114281504 A CN 114281504A
Authority
CN
China
Prior art keywords
task
time
timing
timing task
scheduling
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111593458.9A
Other languages
Chinese (zh)
Inventor
易淑文
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CCB Finetech Co Ltd
Original Assignee
CCB Finetech Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by CCB Finetech Co Ltd filed Critical CCB Finetech Co Ltd
Priority to CN202111593458.9A priority Critical patent/CN114281504A/en
Publication of CN114281504A publication Critical patent/CN114281504A/en
Pending legal-status Critical Current

Links

Images

Abstract

The application discloses a task scheduling method, a task scheduling device, electronic equipment and a computer readable medium, which relate to the technical field of computers, and the method comprises the following steps: receiving a task scheduling request, acquiring a timed task storage array, and determining task cycle time and task execution time corresponding to each timed task in the timed task storage array; acquiring current time, and further calculating the time difference between the execution time of each task and the current time; generating a triple corresponding to each timing task based on each task cycle time and each time difference; and scheduling the corresponding timing tasks in the timing task storage array based on the triples. By abstracting the timing task into a triple, the timing task is not influenced by system time during scheduling, and the time precision and task scheduling performance of task scheduling are improved.

Description

Task scheduling method and device, electronic equipment and computer readable medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a task scheduling method and apparatus, an electronic device, and a computer-readable medium.
Background
The conventional timed task scheduling is realized based on system time, adopts a complex scheduling algorithm, is easily influenced by the system time, and can influence the normal execution of tasks by changing the system time; and the realization is complex, and the time precision and the performance of task scheduling are influenced.
In the process of implementing the present application, the inventor finds that at least the following problems exist in the prior art:
the existing timing task scheduling is complex to realize and influences the time precision and the performance of task scheduling.
Disclosure of Invention
In view of this, embodiments of the present application provide a task scheduling method, a task scheduling device, an electronic device, and a computer readable medium, which can solve the problems that the existing timing task scheduling is complex to implement and affects the time precision and performance of task scheduling.
To achieve the above object, according to an aspect of the embodiments of the present application, there is provided a task scheduling method, including:
receiving a task scheduling request, acquiring a timed task storage array, and determining task cycle time and task execution time corresponding to each timed task in the timed task storage array;
acquiring current time, and further calculating the time difference between the execution time of each task and the current time;
generating a triple corresponding to each timing task based on each task cycle time and each time difference;
and scheduling the corresponding timing tasks in the timing task storage array based on the triples.
Optionally, calculating a time difference between each task execution time and the current time includes:
calculating the difference between the current time and the execution time of each task;
and determining the number of seconds corresponding to each difference value, and further determining each number of seconds as the time difference between the execution time of each task and the current time.
Optionally, generating a triple corresponding to each timing task includes:
acquiring a task function corresponding to each timing task;
determining a one-time task and a periodic task based on a task cycle time;
and setting the corresponding task cycle time of the disposable task as 0, converting the task cycle time corresponding to the periodic task into seconds, and further generating a triple corresponding to each timing task according to each task function and each time difference.
Optionally, based on each triplet, scheduling a corresponding timing task in the timing task storage array includes:
acquiring the time difference of each corresponding timing task based on each triple;
acquiring the value of a time accumulator, and updating the time difference of each timing task based on the value of the time accumulator;
traversing each timing task in the timing task array, determining the corresponding timing task when the updated time difference is less than or equal to 0 as a target timing task and executing the target timing task;
and resetting the time difference in the triple corresponding to the target timing task as the task cycle time in the triple corresponding to the target timing task in response to the completion of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is not 0.
Optionally, based on each triplet, scheduling a corresponding timing task in the timing task storage array, further includes:
and in response to the completion of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is 0, deleting the target timing task.
Optionally, deleting the target timed task comprises:
acquiring the last timing task in a timing task storage array;
and moving the last timing task to the position of the target timing task in the timing task storage array, and deleting the target timing task.
Optionally, after resetting the time difference in the triplet corresponding to the target timing task to the task cycle time in the triplet corresponding to the target timing task, the method further includes:
after traversing each timing task in the timing task storage array, acquiring a timer value and a numerical value of a time accumulator;
the timer value is accumulated to the value of the time accumulator, and the value of the time accumulator is updated.
In addition, the present application also provides a task scheduling device, including:
the receiving unit is configured to receive the task scheduling request, acquire a timed task storage array and determine task cycle time and task execution time corresponding to each timed task in the timed task storage array;
the time difference calculation unit is configured to acquire the current time and further calculate the time difference between the execution time of each task and the current time;
a triple generating unit configured to generate a triple corresponding to each timing task based on each task cycle time and each time difference;
and the scheduling unit is configured to schedule the corresponding timing task in the timing task storage array based on each triplet.
Optionally, the time difference calculation unit is further configured to:
calculating the difference between the current time and the execution time of each task;
and determining the number of seconds corresponding to each difference value, and further determining each number of seconds as the time difference between the execution time of each task and the current time.
Optionally, the triplet generation unit is further configured to:
acquiring a task function corresponding to each timing task;
determining a one-time task and a periodic task based on a task cycle time;
and setting the corresponding task cycle time of the disposable task as 0, converting the task cycle time corresponding to the periodic task into seconds, and further generating a triple corresponding to each timing task according to each task function and each time difference.
Optionally, the scheduling unit is further configured to:
acquiring the time difference of each corresponding timing task based on each triple;
acquiring the value of a time accumulator, and updating the time difference of each timing task based on the value of the time accumulator;
traversing each timing task in the timing task array, determining the corresponding timing task when the updated time difference is less than or equal to 0 as a target timing task and executing the target timing task;
and resetting the time difference in the triple corresponding to the target timing task as the task cycle time in the triple corresponding to the target timing task in response to the completion of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is not 0.
Optionally, the scheduling unit is further configured to:
and in response to the completion of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is 0, deleting the target timing task.
Optionally, the scheduling unit is further configured to:
acquiring the last timing task in a timing task storage array;
and moving the last timing task to the position of the target timing task in the timing task storage array, and deleting the target timing task.
Optionally, the task scheduling apparatus further includes an updating unit configured to:
after traversing each timing task in the timing task storage array, acquiring a timer value and a numerical value of a time accumulator;
the timer value is accumulated to the value of the time accumulator, and the value of the time accumulator is updated.
In addition, the present application further provides a task scheduling electronic device, including: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by one or more processors, the one or more processors realize the task scheduling method.
In addition, the present application also provides a computer readable medium, on which a computer program is stored, which when executed by a processor implements the task scheduling method as described above.
To achieve the above object, according to still another aspect of embodiments of the present application, there is provided a computer program product.
A computer program product according to an embodiment of the present application includes a computer program, and when the computer program is executed by a processor, the computer program implements the task scheduling method according to the embodiment of the present application.
One embodiment of the above invention has the following advantages or benefits: the method comprises the steps of receiving a task scheduling request, obtaining a timed task storage array, and determining task cycle time and task execution time corresponding to each timed task in the timed task storage array; acquiring current time, and further calculating the time difference between the execution time of each task and the current time; generating a triple corresponding to each timing task based on each task cycle time and each time difference; and scheduling the corresponding timing tasks in the timing task storage array based on the triples. By abstracting the timing task into a triple, the timing task is not influenced by system time during scheduling, and the time precision and task scheduling performance of task scheduling are improved.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a further understanding of the application and are not to be construed as limiting the application. Wherein:
fig. 1 is a schematic diagram of a main flow of a task scheduling method according to a first embodiment of the present application;
FIG. 2 is a schematic diagram of a main flow of a task scheduling method according to a second embodiment of the present application;
fig. 3 is a schematic diagram of an application scenario of a task scheduling method according to a third embodiment of the present application;
FIG. 4 is a task scheduling thread diagram of a task scheduling method according to a third embodiment of the present application;
FIG. 5 is a task deletion diagram illustrating a task scheduling method according to a fourth embodiment of the present application;
FIG. 6 is a schematic diagram of the main elements of a task scheduler according to an embodiment of the application;
FIG. 7 is an exemplary system architecture diagram to which embodiments of the present application may be applied;
fig. 8 is a schematic structural diagram of a computer system suitable for implementing the terminal device or the server according to the embodiment of the present application.
Detailed Description
The following description of the exemplary embodiments of the present application, taken in conjunction with the accompanying drawings, includes various details of the embodiments of the application for the understanding of the same, which are to be considered exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present application. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness. According to the technical scheme, the data acquisition, storage, use, processing and the like meet relevant regulations of national laws and regulations.
Fig. 1 is a schematic diagram of a main flow of a task scheduling method according to a first embodiment of the present application, and as shown in fig. 1, the task scheduling method includes:
step S101, receiving a task scheduling request, acquiring a timed task storage array, and determining task cycle time and task execution time corresponding to each timed task in the timed task storage array.
In this embodiment, an execution main body (for example, a server) of the task scheduling method may receive the task scheduling request through a wired connection or a wireless connection. In an example, the execution main body detects the start of a task scheduling thread, responds to a task scheduling request corresponding to the task scheduling thread, and obtains a timing task storage array corresponding to the task scheduling request. In the task storage array, the existence form of each stored task may be a word, for example: once after 5 seconds, once at 16:00:00, once every 15 seconds, once every 16:00:00 days, etc. Of course, the existence form of each stored task may also be a keyword obtained by extracting the key information from the text of the task, and for example, the keyword may be once every 5 seconds, once every 16:00:00, once every 15 seconds, once every 16:00:00, and the like, and specifically, the execution main body may also convert the keyword into a corresponding binary number or a corresponding vector that can be identified by the computer, and further store the binary number or the vector in the timing task array for the task scheduling thread to call. The embodiment of the present application does not specifically limit the existence form of the timing task in the timing task array. The timed task may be, for example, some low-priority and low-frequency task, such as checking system updates, cleaning junk files at a specified time every day, or changing a screen saver at regular intervals.
The timing task storage array may store information related to execution of each task, such as execution frequency, execution time point of each task, and a function to be called when each task is executed, which may be mixed together, and the execution main body needs to analyze the timing task storage array to accurately execute each corresponding timing task.
Step S102, obtaining the current time, and further calculating the time difference between the execution time of each task and the current time.
Specifically, for each task, the time difference is used to characterize how many seconds the current time is from the next time the task is performed.
Step S103, generating a triplet corresponding to each timing task based on each task cycle time and each time difference.
In the timing task storage array, the cycle time period of each task can be obtained according to the execution frequency information of each task, and the time difference count between the time for executing the task next time and the current time can be determined according to the execution time point of each task, wherein the time difference is a non-negative value. And the execution main body can acquire the execution function f corresponding to each timing task from the timing task storage array. Specifically, the execution function f is a function (or a closure, an executable object that packages a function and its parameters), and executing a task is equivalent to executing the function), and each task corresponds to an execution function. Furthermore, after obtaining the execution function f of each timing task, the period time period and the time difference count of the task, the execution main body may generate a triple (f, period, count) corresponding to each timing task to represent a specific configuration parameter for executing the timing task.
Specifically, generating a triple corresponding to each timing task includes:
acquiring a task function corresponding to each timing task; the one-time task and the periodic task are determined based on the task cycle time. The execution main body may determine whether the task is a one-time task or a periodic task according to whether the task cycle time extracted from the timed task storage array is 0, and if the task cycle time is 0, the execution main body is the one-time task, and if the task cycle time is not 0, the execution main body is the periodic task. When the value is not 0, the unit of the task cycle time may be month, day, hour, minute, second, and the like, and the unit of the task cycle time is not specifically limited in the embodiment of the present application. The execution main body may set the corresponding task cycle time of the one-time task to 0, convert the task cycle time corresponding to the periodic task into seconds (if the unit of the task cycle time is second, conversion is not needed, and the call is directly performed), and generate triples corresponding to each timed task according to each task function and each time difference.
Illustratively, the timing task (task) is abstracted as a triplet (f, period, count), which may represent various forms of timing tasks. Where f is a function (or closure, an executable object that packages functions and their parameters), and executing a task is equivalent to executing the function; period is the periodic time of the task in seconds, a value of 0 indicates that the task is aperiodic, and a value of 86400 indicates that the task will be executed once a day; the count is used to count how many seconds it takes for the task to be performed next.
Assuming that the current time is 15:00:00, the executing agent may now add the following tasks to the task scheduler:
f is executed once after 5 seconds; f is performed once at 16:00: 00; f is executed every 15 seconds; f was performed once per day at 16:00: 00.
The task can be represented by the triplets: (f, 0, 5); (f, 0, 3600); (f, 15, 15); (f, 86400, 3600).
The first two tasks are one-time tasks, so the period time period value of the tasks is 0; the latter two are periodic tasks, with period values other than 0. Wherein the 4 th task indicates that f is executed once after 1 hour (3600 seconds), and then f is executed once every other day. f is an execution function corresponding to the timing task, and an executable object of the function and parameters thereof is packaged.
And step S104, scheduling the corresponding timing tasks in the timing task storage array based on the triples.
Specifically, based on each triplet, scheduling the corresponding timing task in the timing task storage array includes:
and acquiring the time difference of each corresponding timing task based on each triplet.
For example, for each timing task, the execution subject may determine a count number, i.e., a time difference, in a triplet (f, period, count) corresponding to the timing task. The count number is used to count how many seconds remain since the timed task is next executed.
The value of the time accumulator is acquired, and the time difference of each timing task is updated based on the value of the time accumulator.
And traversing each timing task in the timing task array, determining the corresponding timing task when the updated time difference is less than or equal to 0 as a target timing task, and executing.
By way of example, the core idea of task scheduling is: every 1 second, the number of task counts is reduced by 1, and after n seconds, the number of task counts is reduced by n, and the task is executed when the number of count is reduced to be less than or equal to 0. As shown in FIG. 4, the task scheduler uses two dynamically growing arrays to hold timed tasks, which are referred to as M and N for descriptive convenience. The added task is firstly put into M, a plurality of threads can add the task into M concurrently, and the process needs to solve the concurrent conflict through a conventional mutual exclusion lock and other mechanisms. In particular, the task scheduler employs single-threaded scheduling, i.e., each task scheduler creates a thread (referred to as a task scheduling thread).
The thread scheduling process is as shown in steps (1) to (4):
step (1) of the thread scheduling process: the timer T is reset, the seconds T of the time accumulator dt (milliseconds) are calculated, dt is subtracted from the seconds (e.g., 1200 milliseconds minus 1 second to 200 milliseconds), and then the time difference of each timing task (i.e., the count in the corresponding triplet) is updated. The specific updating method may be that every time 1 second is subtracted from the time accumulator dt (millisecond) (provided that 1 second is subtracted from the time accumulator dt (millisecond) when the time accumulator dt (millisecond) is accumulated for 1 second, and when the time accumulator dt (millisecond) is not accumulated for 1 second, the time difference of each timing task is subtracted from 1 second correspondingly, and if the dt is accumulated for n seconds, the time difference (i.e. the count number in the corresponding triplet) is subtracted from n;
step (2) of the thread scheduling process: the tasks in the array M are switched out and added into the array N, then the tasks in the array N are traversed, the number of counts of each task is subtracted by the number of seconds t (the number of seconds t is determined by the number of whole seconds reached by the time accumulator, namely, the number of seconds is determined according to the time accumulator reaching several 1 seconds, wherein the whole seconds are counted when the number of seconds reaches 1 second), when the number of counts is less than or equal to 0, the task is executed, otherwise, the task is skipped. The target timing task is a timing task corresponding to a triple corresponding to which the count number is less than or equal to 0, and is specifically a task to be executed immediately.
In response to the end of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is not 0, that is, the target timing task may be determined to be a periodic task, and the execution main body may reset the time difference in the triplet corresponding to the target timing task to the task cycle time in the triplet corresponding to the target timing task.
After the target timing task is executed, if the task cycle time period of the target timing task is not 0, the target timing task may be determined to be a periodic task, and the execution main body may reset the count number in the triple (f, period, count) corresponding to the task cycle time period, otherwise, delete the task.
Specifically, based on each triplet, scheduling the corresponding timing task in the timing task storage array, further includes:
and responding to the completion of the execution of the target timing task and determining that the task cycle time corresponding to the target timing task is 0, namely determining that the target timing task is a disposable task, and executing the main body to delete the target timing task.
Specifically, after the value of the time accumulator corresponding to the target timing task is reset to the preset time accumulated value corresponding to the triplet corresponding to the target timing task, the method further includes:
after traversing each timing task in the timing task storage array, acquiring a timer value and a numerical value of a time accumulator; the timer value is accumulated to the value of the time accumulator, and the value of the time accumulator is updated.
Specifically, step (3) of the thread scheduling process: after traversing N, waiting for 1 second; step (4) of the thread scheduling process: the elapsed time (unit millisecond) is counted by the timer T, added to the time accumulator dt, and then returned to step (1) of the thread scheduling process in the example corresponding to step S104, and the processes of steps (1) to (4) are repeated.
In particular, the timer T acts differently from the time accumulator dt. T is used only to measure the time (milliseconds) taken by steps (1) to (4) of the thread scheduling process described above, including the time waiting in (3). The time of the T measurement is added to dt, the second number of dt is the number of task counts needing to be subtracted, and the time (millisecond) which is less than 1 second and remains after the second number of dt is subtracted continues to participate in the subsequent accumulation operation, so that the time precision of task scheduling is improved.
In addition, the time measured by the timer T includes the time waiting in (3), because the waiting for 1 second in the computer program is also error, and the actual waiting time may be slightly longer than 1 second, so that the timer T is used to measure the time of the whole process from (1) to (4), rather than measuring the time of (1), (2) and (4) plus 1 second (the application does not specifically limit the added 1 second, and may also be 2 seconds, 3 seconds or n seconds), which can improve the time accuracy of task scheduling.
Fig. 5 is a schematic task deletion flow chart of a task scheduling method according to a fourth embodiment of the present application, and as shown in fig. 5, deleting a target timing task includes:
acquiring the last timing task in a timing task storage array; and moving the last timing task to the position of the target timing task in the timing task storage array, and deleting the target timing task.
As shown in fig. 5, when a target timing task, for example, task 2, is deleted, the last task k in the timing task storage array is directly moved to the position of task 2, and this method only needs to move one task in the timing task storage array, and the performance is much higher than that of the conventional task deletion method (if the conventional deletion method is adopted, after task 2 is deleted, all tasks behind task 2 need to be moved, the performance is very poor). The task scheduling algorithm of the embodiment of the application is independent of the sequence of the tasks in the array N, so that the optimization operation can be performed.
The timing task is abstracted into the triple (f, period, count), and after the task is added, the influence of system time is avoided. The number of seconds for executing the task next time is represented by the number of counts, and the number of counts is reduced by 1 per second, so that the design of a task scheduler is simplified; the time is measured by using a timer T which is not influenced by the system time, and the time is calibrated by using a time accumulator dt (the time which is less than 1 second and is accumulated with the subsequent time), so that the time precision of task scheduling is improved.
The embodiment obtains a timed task storage array by receiving a task scheduling request, and determines task cycle time and task execution time corresponding to each timed task in the timed task storage array; acquiring current time, and further calculating the time difference between the execution time of each task and the current time; generating a triple corresponding to each timing task based on each task cycle time and each time difference; and scheduling the corresponding timing tasks in the timing task storage array based on the triples. By abstracting the timing task into a triple, the timing task is not influenced by system time during scheduling, and the time precision and task scheduling performance of task scheduling are improved.
Fig. 2 is a schematic main flow diagram of a task scheduling method according to a second embodiment of the present application, and as shown in fig. 2, the task scheduling method includes:
step S201, receiving a task scheduling request, obtaining a timed task storage array, and determining a task cycle time and a task execution time corresponding to each timed task in the timed task storage array.
It is understood that the timing tasks in the timing task storage array can be timing tasks in various data forms, such as timing tasks in text form, binary digit form, and vector form.
Step S202, obtaining the current time, and further calculating the difference value between the execution time of each task and the current time.
Step S203 determines the number of seconds corresponding to each difference, and further determines each number of seconds as the time difference between each task execution time and the current time.
The time difference is a difference value between the task execution time of each task in the timed task storage array and the current time, and the difference value can be a non-negative value in a month unit, a day unit, an hour unit, a minute unit, a second unit and the like. Finally, the execution body may convert the difference value into a time difference in seconds. For example, the current time is 15:00:00, the task execution time of one task in the timed task storage array is 16:00:00, the difference between the current time and each task execution time is 1 hour, the conversion time is 3600 seconds, and the time difference of the task (i.e., the count number in the initial triplet (f, period, count)) is 3600 seconds.
The embodiment of the application schedules the timing tasks through the time difference between the execution time of each timing task and the current time, so that the task scheduling is not influenced by the system time, and the accuracy of the timing task scheduling is improved.
Step S204, generating a triple corresponding to each timing task based on each task cycle time and each time difference.
And for each timing task, forming an execution function f, a task period time period and a time difference count corresponding to the timing task into a triple (f, period and count) of the corresponding task.
Step S205, based on each triplet, schedules the corresponding timed task in the timed task storage array.
Of course, as another implementation manner of the embodiment of the present application, the execution main body may also directly place the task converted into the triple form into the array M shown in fig. 4, and then the execution main body may swap out the task added in the array M, add the task to N, and then traverse the tasks in N to perform task scheduling. The time for converting the task into the triple is not particularly limited in the embodiment of the application.
The timing task is abstracted into the triple (f, period, count), and after the task is added, the influence of system time is avoided. The number of seconds for executing the task next time is represented by the number of counts, and the number of counts is reduced by 1 per second, so that the design of a task scheduler is simplified; the time is measured by using a timer T which is not influenced by the system time, and the time is calibrated by using a time accumulator dt (the time which is less than 1 second and is accumulated with the subsequent time), so that the time precision of task scheduling is improved.
Fig. 3 is a schematic view of an application scenario of a task scheduling method according to a third embodiment of the present application. The task scheduling method of the embodiment of the application can be applied to a scene of scheduling the timing task. As shown in fig. 3, the operation flow of the timed task scheduling includes the following steps:
step 1), starting a task scheduling thread, and setting dt of a time accumulator to be 0;
step 2), resetting a timer T, calculating the second number T of dt, and subtracting the second number part of dt (the unit of dt is millisecond, and the result of subtracting 2 seconds from 2300 millisecond is 300 millisecond);
step 3), exchanging the tasks in the array M and putting the tasks in the array N;
step 4), traversing the tasks in the array N (i.e., the part in the dashed box in fig. 3), for each task, subtracting t from the count number of the task, and if the count number is less than or equal to 0, executing the task; after the task is executed, if the period is not 0 (periodic task), the count number of the task is reset to be period, otherwise, the task is deleted from N.
Step 5), waiting for 1 second.
Step 6), the time (milliseconds) consumed in steps 1) to 5) is counted by a timer T (milliseconds), and added to dt, and then the process returns to step 2), and the process is repeated.
As shown above, the foregoing steps 1) to 6) are execution processes of task scheduling threads, while the process of adding the timed task is independent of the task scheduling process and is completed by other threads, which is relatively simple, and only the process of adding the timed task to the array M is indicated by a dotted line in fig. 3. Step 4) is the process of scheduling the thread to traverse the tasks in the array N, which is indicated by the dashed box in fig. 3.
In the embodiment of the application, by abstracting various timing tasks into triples (f, period, count), the count number is reduced by 1 per second, and the task is executed when the count number is reduced to be less than or equal to 0. Period represents the cycle time of the task in the triple, and count represents the time from the next execution of the task, and once the task is added, the system time is not influenced. The tasks added by the users are converted into the triples (f, period, count), the timer T which is not influenced by the system time is used, the timer T is matched with the time accumulator dt, the time is calibrated, and the time precision of task scheduling is improved.
Fig. 6 is a schematic diagram of main units of a task scheduling device according to an embodiment of the present application. As shown in fig. 6, the task scheduling apparatus includes a receiving unit 601, a time difference calculating unit 602, a triplet generating unit 603, and a scheduling unit 604.
The receiving unit 601 is configured to receive a task scheduling request, obtain a timed task storage array, and determine a task cycle time and a task execution time corresponding to each timed task in the timed task storage array.
The time difference calculating unit 602 is configured to obtain the current time, and further calculate a time difference between each task execution time and the current time.
The triple generating unit 603 is configured to generate a triple corresponding to each timing task based on each task cycle time and each time difference.
The scheduling unit 604 is configured to schedule the corresponding timed task in the timed task storage array based on each triplet.
In some embodiments, the time difference calculation unit 602 is further configured to: calculating the difference between the current time and the execution time of each task; and determining the number of seconds corresponding to each difference value, and further determining each number of seconds as the time difference between the execution time of each task and the current time.
In some embodiments, the triplet generation unit 603 is further configured to: acquiring a task function corresponding to each timing task; determining a one-time task and a periodic task based on a task cycle time; and setting the corresponding task cycle time of the disposable task as 0, converting the task cycle time corresponding to the periodic task into seconds, and further generating a triple corresponding to each timing task according to each task function and each time difference.
In some embodiments, the scheduling unit 604 is further configured to: acquiring the time difference of each corresponding timing task based on each triple; acquiring the value of a time accumulator, and updating the time difference of each timing task based on the value of the time accumulator; traversing each timing task in the timing task array, determining the corresponding timing task when the updated time difference is less than or equal to 0 as a target timing task and executing the target timing task; and resetting the time difference in the triple corresponding to the target timing task as the task cycle time in the triple corresponding to the target timing task in response to the completion of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is not 0.
In some embodiments, the scheduling unit 604 is further configured to: and in response to the completion of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is 0, deleting the target timing task.
In some embodiments, the scheduling unit 604 is further configured to: acquiring the last timing task in a timing task storage array; and moving the last timing task to the position of the target timing task in the timing task storage array, and deleting the target timing task.
In some embodiments, the task scheduler further comprises an updating unit, not shown in fig. 6, configured to: after traversing each timing task in the timing task storage array, acquiring a timer value and a numerical value of the time accumulator, accumulating the timer value to the numerical value of the time accumulator, and updating the numerical value of the time accumulator.
It should be noted that, in the present application, the task scheduling method and the task scheduling apparatus have a corresponding relationship in the specific implementation content, so the repeated content is not described again.
Fig. 7 shows an exemplary system architecture 700 to which the task scheduling method or the task scheduling apparatus according to the embodiment of the present application may be applied.
As shown in fig. 7, the system architecture 700 may include terminal devices 701, 702, 703, a network 704, and a server 705. The network 704 serves to provide a medium for communication links between the terminal devices 701, 702, 703 and the server 705. Network 704 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 701, 702, 703 to interact with a server 705 over a network 704, to receive or send messages or the like. The terminal devices 701, 702, 703 may have installed thereon various communication client applications, such as a shopping-like application, a web browser application, a search-like application, an instant messaging tool, a mailbox client, social platform software, etc. (by way of example only).
The terminal devices 701, 702, 703 may be various electronic devices having a task scheduling processing screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 705 may be a server providing various services, such as a background management server (for example only) providing support for task scheduling requests submitted by users using the terminal devices 701, 702, 703. The background management server can receive the task scheduling request, acquire the timed task storage array and determine the task cycle time and the task execution time corresponding to each timed task in the timed task storage array; acquiring current time, and further calculating the time difference between the execution time of each task and the current time; generating a triple corresponding to each timing task based on each task cycle time and each time difference; and scheduling the corresponding timing tasks in the timing task storage array based on the triples. By abstracting the timing task into a triple, the timing task is not influenced by system time during scheduling, and the time precision and task scheduling performance of task scheduling are improved.
It should be noted that the task scheduling method provided in the embodiment of the present application is generally executed by the server 705, and accordingly, the task scheduling device is generally disposed in the server 705.
It should be understood that the number of terminal devices, networks, and servers in fig. 7 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 8, shown is a block diagram of a computer system 800 suitable for use in implementing a terminal device of an embodiment of the present application. The terminal device shown in fig. 8 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 8, the computer system 800 includes a Central Processing Unit (CPU)801 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage section 808 into a Random Access Memory (RAM) 803. In the RAM803, various programs and data necessary for the operation of the computer system 800 are also stored. The CPU801, ROM802, and RAM803 are connected to each other via a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
The following components are connected to the I/O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output section 807 including a signal such as a Cathode Ray Tube (CRT), a liquid crystal credit authorization query processor (LCD), and the like, and a speaker; a storage portion 808 including a hard disk and the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. The communication section 809 performs communication processing via a network such as the internet. A drive 810 is also connected to the I/O interface 805 as necessary. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as necessary, so that a computer program read out therefrom is mounted on the storage section 808 as necessary.
In particular, according to embodiments disclosed herein, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, embodiments disclosed herein include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 809 and/or installed from the removable medium 811. The computer program executes the above-described functions defined in the system of the present application when executed by the Central Processing Unit (CPU) 801.
It should be noted that the computer readable medium shown in the present application may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may include, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In this application, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present application may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes a receiving unit, a time difference calculating unit, a triplet generating unit, and a scheduling unit. Wherein the names of the elements do not in some way constitute a limitation on the elements themselves.
As another aspect, the present application also provides a computer-readable medium, which may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs, and when the one or more programs are executed by one device, the device receives a task scheduling request, acquires a timed task storage array, and determines task cycle time and task execution time corresponding to each timed task in the timed task storage array; acquiring current time, and further calculating the time difference between the execution time of each task and the current time; generating a triple corresponding to each timing task based on each task cycle time and each time difference; and scheduling the corresponding timing tasks in the timing task storage array based on the triples. By abstracting the timing task into a triple, the timing task is not influenced by system time during scheduling, and the time precision and task scheduling performance of task scheduling are improved.
The computer program product of the present application includes a computer program, and the computer program realizes the task scheduling method in the embodiment of the present application when being executed by a processor.
According to the technical scheme of the embodiment of the application, the timing task is abstracted into the triple, so that the timing task is not influenced by system time during scheduling, and the time precision and the task scheduling performance of task scheduling are improved.
The above-described embodiments should not be construed as limiting the scope of the present application. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims (16)

1. A method for task scheduling, comprising:
receiving a task scheduling request, acquiring a timed task storage array, and determining task cycle time and task execution time corresponding to each timed task in the timed task storage array;
acquiring current time, and further calculating the time difference between the task execution time and the current time;
generating a triple corresponding to each timing task based on each task cycle time and each time difference;
and scheduling the corresponding timing task in the timing task storage array based on each triplet.
2. The method of claim 1, wherein said calculating a time difference between each of said task execution times and said current time comprises:
calculating the difference value between the current time and each task execution time;
and determining the number of seconds corresponding to each difference value, and further determining each number of seconds as the time difference between each task execution time and the current time.
3. The method of claim 1, wherein generating the triplets for each timing task comprises:
acquiring a task function corresponding to each timing task;
determining a one-time task and a periodic task based on the task cycle time;
and setting the corresponding task cycle time of the one-time task as 0, converting the task cycle time corresponding to the periodic task into seconds, and generating a triple corresponding to each timing task according to each task function and each time difference.
4. The method of claim 1, wherein scheduling a corresponding timed task in the stored array of timed tasks based on each of the triples comprises:
acquiring the time difference of each corresponding timing task based on each triplet;
acquiring the value of a time accumulator, and updating the time difference of each timing task based on the value of the time accumulator;
traversing each timing task in the timing task array, determining the corresponding timing task when the updated time difference is less than or equal to 0 as a target timing task and executing the target timing task;
and in response to the completion of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is not 0, resetting the time difference in the triple corresponding to the target timing task to the task cycle time in the triple corresponding to the target timing task.
5. The method of claim 4, wherein scheduling a corresponding timed task in the stored array of timed tasks based on each of the triples further comprises:
and in response to the completion of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is 0, deleting the target timing task.
6. The method of claim 5, wherein the deleting the target timed task comprises:
acquiring the last timing task in the timing task storage array;
and moving the last timing task to the position of the target timing task in the timing task storage array, and deleting the target timing task.
7. The method of claim 4, wherein after resetting the time difference in the triplet corresponding to the target timed task to the task period time in the triplet corresponding to the target timed task, the method further comprises:
after traversing and finishing each timing task in the timing task storage array, acquiring a timer value and a numerical value of a time accumulator;
and accumulating the timer value to the value of the time accumulator, and further updating the value of the time accumulator.
8. A task scheduling apparatus, comprising:
the system comprises a receiving unit, a task scheduling unit and a task scheduling unit, wherein the receiving unit is configured to receive a task scheduling request, acquire a timing task storage array and determine task cycle time and task execution time corresponding to each timing task in the timing task storage array;
a time difference calculation unit configured to acquire a current time, and further calculate a time difference between each of the task execution times and the current time;
a triplet generating unit configured to generate triples corresponding to the respective timing tasks based on the respective task cycle times and the respective time differences;
and the scheduling unit is configured to schedule the corresponding timing task in the timing task storage array based on each triplet.
9. The apparatus of claim 8, wherein the time difference calculation unit is further configured to:
calculating the difference value between the current time and each task execution time;
and determining the number of seconds corresponding to each difference value, and further determining each number of seconds as the time difference between each task execution time and the current time.
10. The apparatus of claim 8, wherein the triplet generation unit is further configured to:
acquiring a task function corresponding to each timing task;
determining a one-time task and a periodic task based on the task cycle time;
and setting the corresponding task cycle time of the one-time task as 0, converting the task cycle time corresponding to the periodic task into seconds, and generating a triple corresponding to each timing task according to each task function and each time difference.
11. The apparatus of claim 8, wherein the scheduling unit is further configured to:
acquiring the time difference of each corresponding timing task based on each triplet;
acquiring the value of a time accumulator, and updating the time difference of each timing task based on the value of the time accumulator;
traversing each timing task in the timing task array, determining the corresponding timing task when the updated time difference is less than or equal to 0 as a target timing task and executing the target timing task;
and in response to the completion of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is not 0, resetting the time difference in the triple corresponding to the target timing task to the task cycle time in the triple corresponding to the target timing task.
12. The apparatus of claim 11, wherein the scheduling unit is further configured to:
and in response to the completion of the execution of the target timing task and the determination that the task cycle time corresponding to the target timing task is 0, deleting the target timing task.
13. The apparatus of claim 12, wherein the scheduling unit is further configured to:
acquiring the last timing task in the timing task storage array;
and moving the last timing task to the position of the target timing task in the timing task storage array, and deleting the target timing task.
14. A task scheduling electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
15. A computer-readable medium, on which a computer program is stored, which program, when being executed by a processor, is adapted to carry out the method of any one of claims 1-7.
16. A computer program product comprising a computer program, characterized in that the computer program realizes the method according to any of claims 1-7 when executed by a processor.
CN202111593458.9A 2021-12-23 2021-12-23 Task scheduling method and device, electronic equipment and computer readable medium Pending CN114281504A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111593458.9A CN114281504A (en) 2021-12-23 2021-12-23 Task scheduling method and device, electronic equipment and computer readable medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111593458.9A CN114281504A (en) 2021-12-23 2021-12-23 Task scheduling method and device, electronic equipment and computer readable medium

Publications (1)

Publication Number Publication Date
CN114281504A true CN114281504A (en) 2022-04-05

Family

ID=80875112

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111593458.9A Pending CN114281504A (en) 2021-12-23 2021-12-23 Task scheduling method and device, electronic equipment and computer readable medium

Country Status (1)

Country Link
CN (1) CN114281504A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117421106A (en) * 2023-12-11 2024-01-19 湖南行必达网联科技有限公司 Task scheduling method, system and equipment for embedded software

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117421106A (en) * 2023-12-11 2024-01-19 湖南行必达网联科技有限公司 Task scheduling method, system and equipment for embedded software
CN117421106B (en) * 2023-12-11 2024-03-08 湖南行必达网联科技有限公司 Task scheduling method, system and equipment for embedded software

Similar Documents

Publication Publication Date Title
CN110928905B (en) Data processing method and device
CN109949064B (en) Open interface call charging method and device
CN113722055A (en) Data processing method and device, electronic equipment and computer readable medium
CN114281504A (en) Task scheduling method and device, electronic equipment and computer readable medium
CN113127564B (en) Parameter synchronization method and device
US9513660B2 (en) Calibrated timeout interval on a configuration value, shared timer value, and shared calibration factor
CN114048931A (en) Replenishment information generation method and device, electronic equipment and computer readable medium
CN113742057A (en) Task execution method and device
CN112884181A (en) Quota information processing method and device
CN113760982A (en) Data processing method and device
CN113127225A (en) Method, device and system for scheduling data processing tasks
CN113220705A (en) Slow query identification method and device
CN113254191A (en) Method, electronic device and computer program product for running applications
CN116737370A (en) Multi-resource scheduling method, system, storage medium and terminal
CN114327918B (en) Method and device for adjusting resource amount, electronic equipment and storage medium
CN114064403A (en) Task delay analysis processing method and device
CN113722113A (en) Traffic statistic method and device
CN114924937A (en) Batch task processing method and device, electronic equipment and computer readable medium
CN104462116A (en) Data selecting method and device
CN114257521A (en) Flow prediction method, device, electronic equipment and storage medium
CN112784139A (en) Query method, query device, electronic equipment and computer readable medium
CN112507676A (en) Energy report generation method and device, electronic equipment and computer readable medium
CN111782351A (en) Distributed task scheduling method and device
CN110750424A (en) Resource inspection method and device
CN112799933B (en) Automatic test method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination