CN108021439B - Task polling method, task arrangement method and related device - Google Patents

Task polling method, task arrangement method and related device Download PDF

Info

Publication number
CN108021439B
CN108021439B CN201610942962.8A CN201610942962A CN108021439B CN 108021439 B CN108021439 B CN 108021439B CN 201610942962 A CN201610942962 A CN 201610942962A CN 108021439 B CN108021439 B CN 108021439B
Authority
CN
China
Prior art keywords
queue
task
time
polling
tasks
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.)
Active
Application number
CN201610942962.8A
Other languages
Chinese (zh)
Other versions
CN108021439A (en
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.)
Alibaba Cloud Computing Ltd
Original Assignee
Alibaba Group Holding 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 Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN201610942962.8A priority Critical patent/CN108021439B/en
Publication of CN108021439A publication Critical patent/CN108021439A/en
Application granted granted Critical
Publication of CN108021439B publication Critical patent/CN108021439B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Telephonic Communication Services (AREA)

Abstract

The embodiment of the invention discloses a task polling method, a task arrangement method and a related device, wherein a plurality of queues for arranging tasks are arranged in a computer system, the time delay time of the tasks arranged in the queues accords with the time interval corresponding to the queues, and only the tasks in one queue are polled, so that the quantity of the tasks needing to be polled at one time is obviously less than that of the tasks needing to be polled in the traditional mode. And polling the tasks in the first queue according to the polling period of the first queue, calculating the time delay from polling to the tasks, taking the first task out of the first queue and arranging the first task in a second queue with a smaller polling period if the time delay from polling to the first task is in a time interval corresponding to the second queue, and arranging the first task in the second queue with a shorter polling period when the time delay of the first task is shorter.

Description

Task polling method, task arrangement method and related device
Technical Field
The present invention relates to the field of data processing, and in particular, to a task polling method, a task arranging method, and a related apparatus.
Background
In computer systems, some services need to be implemented at some predetermined time in the future, such as pushing information at fixed periods of time each day, posting certain active content at specific points in time or dates, etc. If such services are implemented by a computer system simply by manually waiting for a predetermined time to arrive, high costs and uncertainty are incurred.
It is conventional to use a pre-created task with a time delay characteristic, which can set a time delay time, for example, 10 seconds, 10 minutes, 10 days, etc. The delay time may be shortened as time elapses in a countdown manner, for example, the delay time for creating a task at time 0 is 10 seconds, and after 8 seconds of time 0, the delay time for the task becomes 10-8 to 2 seconds. Because of the latency time, such tasks are not executed immediately upon creation by the computer system, but rather are executed while waiting for the latency time to return to zero. Specifically, the computer system monitors the delay time of such tasks, automatically calls and executes one task when the delay time of the task returns to zero, and accordingly realizes the corresponding service by executing the task.
The computer system generally saves tasks with time delay characteristics in a storage area, periodically polls the tasks in the storage area, calculates whether the time delay time of the polled tasks is already reset to zero in the polling process, and executes the tasks with the time delay time reset to zero.
However, the task polling method has a problem that, in order to ensure that all tasks with a delay characteristic can be monitored when the delay time is zero, the computer system needs to poll all the tasks stored in the storage area in each polling cycle, and in view of the short delay time of some tasks, the polling cycle of the computer system needs to be set to be shorter accordingly, so that the computer system needs to poll a large number of tasks repeatedly at short time intervals, and the polling task consumes a large amount of system resources, which affects the performance of the computer system.
Disclosure of Invention
In order to solve the technical problems, the invention provides a task polling method, a task arrangement method and a related device, which reduce the number of one-time polling tasks, avoid the tasks with long time delay of frequent polling and improve the utilization rate of system resources.
The embodiment of the invention discloses the following technical scheme:
in a first aspect, the present invention provides a task polling method, applied to a computer system, where a plurality of queues having corresponding time intervals are set in the computer system, each of the plurality of queues is used to arrange tasks whose delay times meet the corresponding time intervals, the plurality of queues at least include a first queue and a second queue, a polling period of the first queue is greater than a polling period of the second queue, and the method includes:
polling the tasks arranged in the first queue according to the polling period of the first queue;
calculating a time delay time from polling to the task;
judging a time interval of the time delay time of the polled task; when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue;
and if the delay time of the first task is in the time interval corresponding to the second queue, taking the first task out of the first queue and distributing the first task into the second queue.
Optionally, the determining a time interval in which the delay time of the first task is located further includes:
and if the time delay time of the first task is less than or equal to 0, taking the first task out of the first queue, and executing the first task.
Optionally, a time interval corresponding to the first queue is not overlapped with a time interval corresponding to the second queue.
Optionally, the polling the tasks arranged in the first queue according to the polling period of the first queue includes:
setting a mark for a second task, wherein the second task is a first task polled in a polling period of the first queue;
after the second task is polled, the second task is arranged at the tail of the first queue;
sequentially polling the tasks in the first queue according to the queue arrangement sequence, and arranging one task to the tail of the first queue after the task is polled;
when the second task with the mark is polled, canceling the mark of the second task and finishing polling.
Optionally, the setting a flag for the second task further includes:
storing a second time into the second task, wherein the second time is determined by a first time and a polling cycle of the first queue, and the first time is a time for marking the second task;
said when polling said second task with said tag, further comprising:
acquiring the second moment from the second task;
and determining the next time for polling the first queue according to a third time and the second time, wherein the third time is the time from polling to the second task with the mark.
Optionally, before the polling the tasks arranged in the first queue according to the polling period of the first queue, the method further includes:
judging whether tasks are distributed in the first queue or not;
and if the tasks are not arranged, waiting for a polling period of the first queue and then executing the judgment again to judge whether the tasks are arranged in the first queue.
Optionally, the queue types of the multiple queues include any one or a combination of multiple queues in a memory queue arranged in a memory, a file queue arranged in a disk, and a queue in a table structure form arranged in a database.
Optionally, the queue with the shortest polling period among the queues is a memory queue set in the memory.
Optionally, the method further includes:
acquiring a third task, wherein the third task is a task with time delay time;
and arranging the third task into a third queue of the plurality of queues, wherein the delay time of the third task is in a time interval corresponding to the third queue.
In a second aspect, the present invention provides a task polling device, applied to a computer system, where the computer system is provided with a plurality of queues having corresponding time intervals, each of the plurality of queues is used to arrange tasks whose delay times meet the corresponding time intervals, the plurality of queues at least include a first queue and a second queue, a polling cycle of the first queue is greater than a polling cycle of the second queue, and the device includes a polling unit, a calculating unit, a determining unit, and an arranging unit:
the polling unit is used for polling the tasks arranged in the first queue according to the polling period of the first queue;
the computing unit is used for computing the time delay time of the polled task;
the judging unit is used for judging a time interval in which the time delay time of the polled task is located; when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue; if the delay time of the first task is in the time interval corresponding to the second queue, triggering the arrangement unit;
the arranging unit is used for taking the first task out of the first queue and arranging the first task into the second queue.
Optionally, the polling unit is further configured to set a flag for a second task, where the second task is a first task polled in a polling period of the first queue; after the second task is polled, the second task is arranged at the tail of the first queue; sequentially polling the tasks in the first queue according to the queue arrangement sequence, and arranging one task to the tail of the first queue after the task is polled; when the second task with the mark is polled, canceling the mark of the second task and finishing polling.
Optionally, the polling unit is further configured to store a second time into the second task, where the second time is determined according to a first time and a polling cycle of the first queue, and the first time is a time for marking the second task; acquiring the second moment from the second task; and determining the next time for polling the first queue according to a third time and the second time, wherein the third time is the time from polling to the second task with the mark.
In a third aspect, the present invention provides a task arranging method, applied to a computer system, where the computer system is provided with a plurality of queues having corresponding time intervals, and each queue in the plurality of queues is used to arrange tasks whose delay times meet the time interval corresponding to the queue, where the method includes:
acquiring a task, wherein the task is a task with time delay time;
and if the delay time of the task is in a time interval corresponding to a target queue, the task is arranged in the target queue, and the target queue is one of the queues.
Optionally, the plurality of queues at least include a first queue and a second queue, and a polling period of the first queue is greater than a polling period of the second queue, the method includes:
polling the tasks arranged in the first queue according to the polling period of the first queue;
calculating the time delay from polling to the task;
judging a time interval of the time delay time of the polled task; when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue;
and if the delay time of the first task is in the time interval corresponding to the second queue, taking the first task out of the first queue and distributing the first task into the second queue.
Optionally, the queue types of the multiple queues include any one or a combination of multiple queues in a memory queue arranged in a memory, a file queue arranged in a disk, and a queue in a table structure form arranged in a database.
Optionally, the queue with the shortest polling period among the queues is a memory queue set in the memory.
In a fourth aspect, the present invention provides a task arranging apparatus, applied to a computer system, where the computer system is provided with a plurality of queues having corresponding time intervals, and each queue in the plurality of queues is used to arrange a task whose delay time meets the time interval corresponding to the queue, and the apparatus includes an obtaining unit and an arranging unit:
the acquisition unit is used for acquiring a task, wherein the task is a task with time delay time;
the arranging unit is configured to arrange the task into a target queue if the delay time of the task is in a time interval corresponding to the target queue, where the target queue is one of the queues.
According to the technical scheme, a plurality of queues for arranging tasks are arranged in the computer system, the delay time of the tasks arranged in the queues accords with the time interval corresponding to the queues, and the tasks with the delay time in different time intervals are distributed in different queues, so that only the tasks in one queue are polled, and the number of the tasks needing to be polled at one time is obviously less than that of all the tasks needing to be polled in the computer system at one time in a traditional mode. For a first queue in the plurality of queues, polling tasks in the first queue according to the polling period of the first queue, calculating the time delay from polling to the task, and if the time delay from polling to the first task is in the time interval corresponding to a second queue in the plurality of queues, taking the first task out of the first queue and arranging the first task in the second queue with a smaller polling period. When the delay time of the first task is short, the first task can be arranged in a second queue with a short polling period, and the possibility that the delay time of the first task can be timely executed when the delay time of the first task is zero is improved through frequent polling.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
FIG. 1 is a diagram illustrating a plurality of queues in a computer system according to an embodiment of the present invention;
FIG. 2 is a flow chart of a polling method according to an embodiment of the present invention;
FIG. 3 is a flowchart of a method for polling tasks in a queue according to an embodiment of the present invention;
fig. 4 is a flowchart of a method for determining a next polling time according to an embodiment of the present invention;
FIG. 5 is a flowchart of a method for queuing tasks according to an embodiment of the present invention;
FIG. 6 is a diagram of an apparatus structure of a task polling apparatus according to an embodiment of the present invention;
fig. 7 is a flowchart of a method of a task arranging method according to an embodiment of the present invention;
fig. 8 is a device structure diagram of a task arranging device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some embodiments of the present invention, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In a computer system, for some services that need to be implemented at a predetermined time in the future, a general solution is to create tasks with delay times in advance, and when the delay time of a task is reset to zero by means of countdown, the task will be executed, and the corresponding service can be implemented by executing the task.
In order to ensure that such tasks can be executed in time when the delay time is reset to zero, the delay time of such tasks needs to be monitored in a polling manner. However, in the conventional method, uniform saving and uniform polling are generally adopted for the tasks. Moreover, since the delay time of some tasks may be relatively short, the period of unified polling must also be set to be very short, and when the number of tasks stored in a unified manner is relatively large, a computer system needs to repeatedly poll a large number of tasks at short time intervals, so that a large number of system resources are consumed by polling tasks, and the performance of the computer system is affected. Moreover, due to the large number of tasks, it may also be possible that all polling operations cannot be completed in one polling period, for example, 1000 ten thousand tasks are uniformly stored in a database, the set polling period is 10 seconds, that is, all stored tasks need to be polled every 10 seconds, due to a performance bottleneck of the processing speed of the processor, assuming that a maximum of 50 ten thousand data can be queried in 1 second, and only a maximum of 500 ten thousand tasks can be polled in 10 seconds, a new round of polling operation must be started, which may cause that a part of tasks may not be polled for a long time, so that some delay time has been reduced to zero, tasks that should be executed are delayed, which causes accumulation of tasks, and delay of service release time.
To this end, embodiments of the present invention provide a task polling method, a task arranging method, and a related apparatus, where multiple queues for arranging tasks are set in a computer system, and each of the multiple queues has a corresponding time interval, where a delay time of a task arranged in each queue corresponds to the time interval corresponding to the queue, for example, the multiple queues include a queue a and a queue b, where the time interval corresponding to the queue a is 10 to 20 seconds, and the time interval corresponding to the queue b is 30 to 40 seconds, then a task with a delay time of 10 to 20 seconds may be arranged in the queue a, and a task with a delay time of 30 to 40 seconds may be arranged in the queue b. It should be noted that, in addition to the above-mentioned queue with the corresponding time interval, other queues in the conventional manner may also be set in the computer system.
Since tasks with different time delay intervals are distributed in different queues, only the tasks in one queue are polled, so that the number of tasks needing to be polled at one time is obviously less than that of the tasks needing to be polled in the computer system at one time in the traditional mode. For example, in the scenario of the 1000 ten thousand tasks, when a plurality of queues are set, the 1000 ten thousand tasks are respectively arranged in the respective queues according to a rule, wherein the number of tasks in one queue is generally less than 1000 ten thousand, and then when task polling is performed on the queue, the tasks requiring polling are less than the tasks requiring polling in the conventional manner, so that the problem that some delay time is already zero and the tasks that should be executed are delayed due to non-timely polling can be effectively reduced or even eliminated.
And polling the tasks in the first queue according to the polling period of the first queue, and calculating the time delay from polling to the tasks, if the time delay from polling to the first task is in the time interval corresponding to the second queue in the queues, taking the first task out of the first queue and arranging the first task in the second queue with a smaller polling period, so that the first task can be placed in the first queue with a longer polling period when the time delay of the first task is longer, thereby avoiding frequent polling of the first task and saving system resources. When the delay time of the first task is short, the first task can be arranged in a second queue with a short polling period, and the possibility that the delay time of the first task can be timely executed when the delay time of the first task is zero is improved through frequent polling.
Before specifically describing the technical scheme of the invention, a plurality of queues arranged in a computer system are described. The computer system provided with a plurality of queues can be a local computer or a server on the network side. These queues may be placed in any one or a combination of databases, disks and memory of the computer system, depending on the needs of the scenario. The queue set in the database may be a queue in a table structure form, the queue set in the disk may be a file queue, and the queue set in the memory may be a memory queue. The plurality of queues need not be arranged in the same storage space, and may be arranged in a memory in a part of queues, in a disk in a part of queues, or in other possible combinations. For example: when three queues, queue 1, queue 2, and queue 3, are included in the computer system, queue 1 may be set in memory, queue 2 may be set in disk, and queue 3 may be set in a database. In addition to the more common storage media mentioned above: the queues may be provided in other storage media besides memory, disks, and databases.
The execution main body for polling the tasks in the plurality of queues can be a processing module of the computer system, and the processing module is responsible for polling the tasks in the queues according to the polling periods of the queues. Each queue can also be respectively allocated with a corresponding processing module to be responsible for polling the tasks in the queue, or a plurality of queues can be polled by the same processing module.
After the tasks with short time delay are placed in the second queue, because the polling period of the first queue is greater than that of the second queue, the polling of the tasks in the second queue is relatively frequent, and because the read-write efficiency of the memory is higher than that of storage media such as a disk and a database, the queues with short polling periods, such as the second queue, can be arranged in the memory, so as to improve the read-write efficiency of the tasks in the queues.
The plurality of queues can be as shown in fig. 1, and through the N queues, tasks with delay time can be respectively arranged in the N queues, and for one queue, tasks needing to be polled are smaller than tasks needing to be polled in a traditional mode, so that the problem that some delay time is already zero and the executed tasks are delayed because of not polling in time can be effectively reduced or even avoided.
The role of tasks with a delay time has been made clear above, and some services that need to be provided at a fixed time can be implemented by creating such tasks. For example, a new online service is required at point 15, point 18, and point 23 of point 20, which are service a, service b, and service c, respectively, and a worker can create task a with a delay time of 3 hours, task b with a delay time of 6 hours, and task c with a delay time of 11 hours at point 12 of point 20, which correspond to the three online services, respectively. The delay time of the task decreases with time, for example, the delay time of the task a at the time of creation (at the time of 0 second) is 180 minutes, and after one hour after creation, that is, at the time of 60 minutes, the delay time of the task a becomes 180-60 to 120 minutes. After three hours after creation, namely 180 minutes, the delay time of the task a will return to zero, and the executed condition is reached.
The plurality of queues are respectively provided with corresponding time intervals, and for one queue in the plurality of queues, the queue can be used for arranging tasks with the delay time meeting the time interval corresponding to the queue. The mode of arranging the tasks in one queue can be various, for example, the tasks can be arranged in a queue mode, and the tasks which are queued later are arranged at the tail of the queue; tasks may also be arranged in a circular queue end to end. It should be noted that when there are no tasks in a queue, the queue does not exist and the queue may be an empty queue.
It is understood that the time intervals corresponding to the queues may partially overlap or may not overlap. If there is an overlapping portion between the time intervals corresponding to the two queues, when the delay time from polling to a task is in the overlapping portion, it needs to further determine in which queue of the two queues the task is arranged. For example, when 6 queues are included in the computer system, the time intervals corresponding to the 6 queues do not overlap. The time interval of the queue 1 is greater than 3200 seconds, the time interval of the queue 2 is greater than or equal to 800 and less than 3200 seconds, namely, the time node of 3200 seconds is not included; the time interval of the queue 3 is greater than or equal to 200 seconds and less than 800 seconds, namely, the time node of 800 seconds is not included; the time interval of the queue 4 is greater than or equal to 40 seconds and less than 200 seconds, namely, the time node of 200 seconds is not included; the time interval of the queue 5 is greater than or equal to 10 seconds and less than 40 seconds, namely, the time node of 40 seconds is not included. If the time delay time of a polled task is 200 seconds in the process of polling the task in the queue 1 and is in the time interval corresponding to the queue 3, the task can be taken out of the queue 1 and arranged in the queue 3.
Therefore, by setting non-overlapping time intervals for different queues, after a user submits a task, a corresponding queue can be determined according to the time delay time of the task, and the queue corresponding to the task does not need to be determined through judgment or other mechanisms, so that the task arrangement process is simplified, and the processing time is shortened.
The time interval corresponding to one queue can be used as a basis for judging whether the queue can be assigned with tasks. In order to avoid as far as possible the occurrence that the delay time of a task has been set to zero for a long time when the task is polled in one polling period of a queue, the time interval corresponding to the queue may be set according to the polling period of the queue. For example, if a polling cycle corresponding to one queue is 40 seconds, and a task with a delay time of 30 seconds is arranged in the queue, it is likely that when the task is polled, the delay time of the task is already set to zero before 10 seconds, thereby causing a delay of the task. Therefore, the time interval corresponding to the queue with the polling period of 40 seconds can be set to be greater than 40 seconds, for example, 40 seconds to 100 seconds, so that the delay time of the task arranged in the queue is generally greater than the polling period of the queue.
The polling period of a queue refers to the period between two adjacent polling periods, and in a polling period, all tasks in the queue can be polled once. For example, if the polling period corresponding to one queue is 40 seconds, the polling of the task in the queue is performed every 40 seconds, for example, when the time is 0 second, the first polling of the task in the queue is started, when the time is 40 seconds, the second polling of the task in the queue is started, and so on.
The plurality of queues may include at least a first queue and a second queue, and a polling period of the first queue may be greater than a polling period of the second queue.
The polling periods of the queues may be different from each other, and the polling periods of the queues may be specifically set according to specific situations. For example: when 5 queues are set in the computer system, the polling periods of the 5 queues may be set to 3200 seconds, 800 seconds, 200 seconds, 40 seconds, and 10 seconds, respectively. Wherein the first queue may be one of the other four queues except for the queue having the polling period of 10 seconds, and the second queue may be one queue smaller than the polling period of the first queue.
Next, referring to fig. 2, a task polling method provided in an embodiment of the present invention is described in detail.
S101: and polling the tasks arranged in the first queue according to the polling period of the first queue.
For example, the present invention is not limited to the polling manner for the tasks in the first queue, as long as the effect of polling each task in the first queue once in the polling period can be achieved. The polling method may be, for example, a method of sequentially extracting tasks from a queue to perform polling, or a method of randomly extracting tasks to perform polling.
And judging whether the queue has the arranging task before polling, and if not, waiting for the time of a polling period. And in the time of the polling period, the resource consumption of the computer system is reduced because the polling operation is not required. That is, optionally, before polling the tasks in the first queue, it may be determined whether there are arranged tasks in the first queue, and if there are arranged tasks, step S101 may be executed to start task polling. If no task is arranged in the first queue, S101 may be executed again after waiting for a polling cycle of the first queue.
S102: the latency time to be polled to the task is calculated.
The delay time refers to the remaining time of each task in each queue when the distance between the tasks is executed, and the delay time calculated in the step is the polling time when the task is polled to a moment when the task is at the moment. For example, when the polling period corresponding to the queue a is 20 seconds, if the first task polling is performed on the queue a, the polling is performed to the task T, and the delay time of the task T is 38 seconds, the queue a may be continuously arranged. When the task T is polled again when the task is polled for the second time according to the polling period of the queue a, because the polling period corresponding to the queue a is 20 seconds, the time of the polling period corresponding to the queue a is already passed when the task is polled to the task T, namely 20 seconds, and the time delay time corresponding to the task T is 38 seconds-20 seconds, namely 18 seconds. It can be seen that the delay time of task T is a decreasing value over time, rather than a constant value.
S103: and judging a time interval of the time delay time of the polled task, wherein when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue.
For example, the first task is any one of the tasks arranged in the first queue, and the present invention does not limit the specific arrangement position of the first task in the first queue, and may be a task at the head of the queue in the first queue, a task at the tail of the queue in the first queue, or a task arranged at another position in the first queue.
It should be noted that, during the process of sequentially polling the tasks in the first queue, when the first task is polled, the delay time of the first task may already be zero or even less than 0, and in this case, the first task may be taken out from the first queue and executed.
It is easy to understand that, in the process of polling a task, it may happen that when a task is polled, it is just time for the task to be executed, and at this time, the delay time of the task is equal to 0, the task is taken out from the queue and executed; it may also happen that when a task is polled, the time for the task to be executed has elapsed, and when the task has a latency less than 0 (also in the case of a zero), the task is taken out of the queue and executed.
This part is further illustrated below by way of example.
First, the case where the delay time of the task is equal to 0 is exemplified. For example, the time interval of a certain queue m is 800 seconds to 3200 seconds, the polling cycle of the queue m is 800 seconds, the delay time of a certain task N is 1600 seconds and is arranged at the head of the queue, when the task N is polled for the first time, the delay time of the task N is 1600 seconds, the task N is still arranged in the queue m within the time interval of the queue m, when the time of the polling cycle of one queue m is passed, the task N is polled for the second time in the queue m, the delay time of the task N is 1600 seconds to 800 seconds and is still within the time interval of the queue m, when the task N is polled for the next time, the time of the polling cycle of one queue m is passed, namely the time of 800 seconds, when the task N is polled for the second time, the delay time of the task N is 800 seconds to 800 seconds, then the task N is taken from the queue m and executed.
Next, a case where the delay time of the task is less than 0 is described as an example. For example, the time interval of a certain queue p is less than 10 seconds, the polling cycle of the queue p is 1 second, the delay time of a certain task Q is 0.4 second, and the task Q is arranged at the middle position, the tail position or the last position of the queue p, in a polling process, the time from polling the task Q at the head of the forefront of the queue p to polling the task Q is 0.5 second, when the task Q is polled, the delay time of the task Q is 0.4-0.5-0.1 second, namely the task Q is already out of date, at this time, the task Q is taken out, and the task Q is executed.
S104: and if the delay time of the first task is in the time interval corresponding to the second queue, taking the first task out of the first queue and distributing the first task into the second queue.
As the time delay time of the first task is gradually reduced along with the time, in the polling process, when the time interval corresponding to the time delay time of the first task is judged to be the second queue, the first task is arranged in the second queue.
For example, the time interval of the queue b is 200 seconds to 400 seconds, the polling period is 200 seconds, the time interval of the queue c is 100 seconds to 199 seconds, the polling period is 100 seconds, and the delay time of the task M is 350 seconds, and the queue b is arranged in the queue c. When the task M is polled for the first time, because the delay time of the task M is 350 seconds, the task M is still arranged in the queue b when the delay time of the task M is judged to be in the time interval of the queue b, after the polling period of one queue b, the delay time of the task M is 350 seconds-200 seconds which is 150 seconds, at the moment, the time interval in which the delay time of the task M is judged to be the time interval corresponding to the queue c, and therefore, the task M is taken out of the queue b and is arranged in the second queue.
It should be noted that, after the first task is taken out from the first queue, the first task is arranged in the second queue, and the specific arrangement position of the first task in the second queue is not limited, and the first task may be arranged at the head of the second queue, the first task may be arranged at the tail of the second queue, or the first task may be arranged at any other position of the second queue.
The present invention does not limit the relationship of the first queue and the second queue among the plurality of queues that are set. The second queue and the first queue may be two queues adjacent to each other in a time interval, or may be two queues not adjacent to each other in the time interval, and it is necessary to determine the corresponding queue according to the delay time of the task, so as to take out the task and arrange the task in the corresponding queue. This is further illustrated below with reference to specific examples.
When 6 queues are set in the computer system, the 6 queues respectively correspond to respective time intervals: the time interval of the queue d is more than 3200 seconds, the time interval of the queue e is 800 seconds to 3200 seconds, the time interval of the queue f is 200 seconds to 800 seconds, the time interval of the queue g is 40 seconds to 200 seconds, the time interval of the queue h is 10 seconds to 40 seconds, and the time interval of the queue i is less than 10 seconds. Assuming that when the tasks of 3205 seconds, 3230 seconds, 3250 seconds, 3430 seconds and 4030 seconds are stored in the queue d in sequence, the task of 3205 seconds is polled first in the first polling, and since 3205 seconds is greater than 3200 seconds of the queue d, the task is still arranged in the queue d, and accordingly, the tasks of 3230 seconds, 3250 seconds, 3430 seconds and 4030 seconds are still arranged in the queue d since the time delay time is greater than 3200 seconds. When the task of 3205 seconds is polled for the second time in the queue d, the time of the polling period of one queue d has already passed, at this time, the delay time of the task of 3205 seconds is 3205 seconds-3200 seconds, which is 5 seconds, so that the time interval corresponding to the task at this time is the delay time of the queue i, the task is put in queue i for execution, and accordingly, the delay times for the 3230, 3250, 3430 and 4030 second tasks are 30, 50, 230 and 830 seconds (ignoring the polling time for polling all tasks in a queue because there are fewer tasks in the queue), according to the time delay time corresponding to each queue, the 3230-second task is executed for 30 seconds, therefore, the task of 3250 seconds is arranged in the queue h, the task of 3430 seconds is arranged in the queue f, and the task of 4030 seconds is arranged in the queue e.
It can be seen from the above embodiments that, multiple queues for arranging tasks are set in the computer system, the delay time of the tasks arranged in the queues corresponds to the time interval corresponding to the queue, and since the tasks with delay times in different time intervals are arranged in different queues in a distributed manner, only the task in one queue is polled, so that the number of tasks that need to be polled at one time is obviously less than the number of tasks that need to be polled at one time in the conventional manner. And polling the tasks in the first queue according to the polling period of the first queue, and calculating the time delay from polling to the tasks, if the time delay from polling to the first task is in the time interval corresponding to the second queue in the queues, taking the first task out of the first queue and arranging the first task in the second queue with a smaller polling period, so that the first task can be placed in the first queue with a longer polling period when the time delay of the first task is longer, thereby avoiding frequent polling of the first task and saving system resources. When the delay time of the first task is short, the first task can be arranged in a second queue with a short polling period, and the possibility that the delay time of the first task can be timely executed when the delay time of the first task is zero is improved through frequent polling.
In order to accurately and effectively poll the tasks in the queue, the embodiment of the invention also provides a specific mode for polling the tasks in the queue, which is used for sequentially polling the tasks in the queue according to the arrangement sequence of the tasks in the queue and ensuring that the situation that one task is polled for multiple times does not occur as much as possible.
Optionally, on the basis of the embodiment corresponding to fig. 2, fig. 3 is a flowchart of a method for polling tasks in a queue according to an embodiment of the present invention, where the method includes:
s201: and setting a mark for a second task, wherein the second task is the first task polled in the polling period of the first queue.
For example, the second task may be any one of the tasks in the first queue, e.g., the second task may be the first task. However, since the second task is the first task polled in one polling cycle, the second task is typically the task at the head of the queue in the first queue.
The role of setting the flag for the second task is mainly to determine when to complete task polling, and the specific contents are described in S204.
S202: and after the second task is polled, the second task is arranged at the tail of the first queue.
S203: and sequentially polling the tasks in the first queue according to the queue arrangement sequence, and arranging the tasks to the tail of the first queue after one task is polled.
For example, in a polling period, since a task in the first queue is polled, the task is arranged at the tail of the first queue. Thus, other tasks polled after the second task are still arranged after the second task in the arrangement sequence of the queues after polling. It should be noted, however, that in the task polling process, in some cases, not every task in the first queue is implemented according to the method defined in S203, and if the delay time of a polled task (including the second task) is in the time interval corresponding to the other queues, the task is taken out from the first queue and arranged in the other queues, and is not arranged at the tail position of the first queue.
S204: when the second task with the mark is polled, canceling the mark of the second task and finishing polling.
Because the flag is already set for the second task in step S201, and among the tasks that have been polled, the tasks whose delay time is still in the time interval of the first queue are all rearranged at the tail of the first queue in the manner of S202 and S203. Then in this polling period, if a second task with the flag is polled, which indicates that all tasks in the first queue have been polled at the beginning of the polling task in this polling period, the polling of the tasks in this polling period can be considered to be completed. Therefore, the flag of the second task may be cancelled and the polling may be ended.
The mark arranged on the second task ensures that the situation that one task is polled for multiple times in one polling period does not occur as much as possible, and the polling efficiency is improved.
Typically, the time it takes to complete polling of a task in a queue during polling is less than the polling period for that queue. I.e., after polling the tasks in the queue one time, the next polling cycle has not yet started, and therefore, the time for the next polling needs to be determined. The conventional implementation manner is that a corresponding timer is set for one queue, for example, the timer may be started when starting one task polling, and whether to start the next task polling is determined by the value of the timer. However, this method needs to set a corresponding timer for each queue, which results in waste of system resources. Therefore, an embodiment of the present invention further provides a method for determining a task start polling time, where on the basis of the embodiment corresponding to fig. 3, referring to fig. 4, the method includes:
s301: and setting a mark for a second task, wherein the second task is the first task polled in the polling period of the first queue.
S302: and storing a second time into the second task, wherein the second time is determined by a first time and a polling cycle of the first queue, and the first time is a time for marking the second task.
For example, the present invention does not limit the sequence of executing S301 and S302, S302 may be executed before S301, or these two steps may be executed simultaneously.
The first time may be the time from the first polling to the second task in a polling cycle, for example: the specific time from the first polling to the second polling in one polling cycle is 12 points, and the first time may be 12 points. The second time is determined by the first time and the polling period of the first queue, for example, the polling period of the first queue is 10 seconds, and when the first time is 12 o 'clock, the second time may be 12 o' clock and 10 seconds.
By storing the second time in the second task, when the second task is polled again in the same polling period, the time for next task polling can be determined through the second time.
S303: and after the second task is polled, the second task is arranged at the tail of the first queue.
S304: and sequentially polling the tasks in the first queue according to the queue arrangement sequence, and arranging one task to the tail of the first queue after the task is polled.
S305: and when the second task with the mark is polled, acquiring the second time from the second task.
S306: and determining the next time for polling the first queue according to a third time and the second time, wherein the third time is the time from polling to the second task with the mark.
S307: canceling the marking of the second task and ending the polling.
In this embodiment, the execution sequence between S306 and S307 is not limited, S307 may be executed before S306, S306 may be executed before S307, and S306 and S307 may be executed simultaneously.
For example, when the second task with the flag is polled in the same polling cycle after the second time is saved in the second task with the flag, the second time saved in S302 may be obtained from the second task, and the second time is, for example, 12 o' clock and 10 seconds. The third time is the time of polling to the second task with the identification, for example: the third time may be 12 o' clock 8 seconds to poll to the second task with the identification. Since the first time and the third time are the time from polling to the second task twice in a polling cycle, the time from the first time to the third time is the time consumed by polling the task in the first queue. The time remaining for this polling period can be determined by the second time and the third time.
For example, according to the third time 12, point 8 seconds and the second time 12, point 10 seconds, the next time to poll the queue is determined: the 12 o 'clock 10 s-12 o' clock 8 s is 2 s, that is, the polling period is still finished in 2 s, and the next task polling can be performed on the first queue after 2 s.
Therefore, a timer is not required to be additionally arranged, when the second task is polled for the second time in the same polling period through the second time saved in the second task of the first queue, the time for starting task polling next time can be automatically determined according to the time for polling the second task for the second time and the second time saved in the second task, and therefore the processing module in charge of the first queue can be dormant in the time without task polling and can start working in time when task polling is needed, resources are saved, and efficiency is improved.
Next, how a task with a delay time is added to a queue when it is created will be described. Optionally, referring to fig. 5, a specific method for arranging tasks into a plurality of set queues includes:
s501: and acquiring a third task, wherein the third task is a task with time delay.
For example, the third task may be a task that has just been created with a latency time.
S502: and arranging the third task into a third queue of the plurality of queues, wherein the delay time of the third task is in a time interval corresponding to the third queue.
That is to say, the time interval corresponding to the queue may be used as a basis for arranging the newly created task, and the queue capable of arranging the task may be selected according to the delay time of the newly created task. It should be noted that the third queue may be the first queue or the second queue mentioned in the above embodiment of the present invention, or may be another queue of the plurality of queues. The present invention also does not limit the specific location of the third task in the third queue.
For example, when a processing module is used as an execution subject for polling tasks in a plurality of queues, after a user submits a task, the processing module first obtains the task, then calculates the time remaining from the task being executed, i.e. the instant delay time, and puts the task into the corresponding queue according to the delay time, for example: assuming that the computer system includes 6 queues, the 6 queues correspond to respective time intervals: the time interval of queue d is more than 3200 seconds, the time interval of queue e is 800-3200 seconds, the time interval of queue f is 200-800 seconds, the time interval of queue g is 40-200 seconds, the time interval of queue h is 10-40 seconds, and the time interval of queue i is less than 10 seconds. When the time remaining until a certain task is executed is calculated to be 3405 seconds, since 3405 seconds is more than 3200 seconds, the task is arranged in the queue d. Similarly, when the processing module calculates that the time required for the distance to the task submitted by the user to be executed is 520 seconds, the task is arranged in the queue f because the 520 seconds are in the time interval of 200 seconds to 800 seconds.
Fig. 6 is a device structure diagram of a task polling device according to an embodiment of the present invention, which is applied to a computer system, where the computer system is provided with a plurality of queues having corresponding time intervals, each of the plurality of queues is used to arrange tasks whose delay times meet the corresponding time intervals, the plurality of queues at least include a first queue and a second queue, a polling cycle of the first queue is greater than a polling cycle of the second queue, and the device includes a polling unit 601, a calculating unit 602, a determining unit 603, and an arranging unit 604:
the polling unit 601 is configured to poll the tasks arranged in the first queue according to a polling period of the first queue.
The calculating unit 602 is configured to calculate a time delay time of being polled to a task.
The judging unit 603 is configured to judge a time interval where the delay time of the polled task is located; when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue; if the delay time of the first task is in the time interval corresponding to the second queue, the arranging unit 604 is triggered.
The arranging unit 604 is configured to take the first task out of the first queue and arrange the first task in the second queue.
For the description of each unit, please refer to the related description in the embodiment corresponding to fig. 2, which is not repeated here.
Optionally, the determining unit is further configured to, when the delay time of the first task is less than or equal to 0, take the first task out of the first queue, and execute the first task.
Optionally, a time interval corresponding to the first queue is not overlapped with a time interval corresponding to the second queue.
Optionally, the polling unit is further configured to set a flag for a second task, where the second task is a first task polled in a polling period of the first queue; after the second task is polled, the second task is arranged at the tail of the first queue; sequentially polling the tasks in the first queue according to the queue arrangement sequence, and arranging one task to the tail of the first queue after the task is polled; when the second task with the mark is polled, canceling the mark of the second task and finishing polling.
Optionally, the polling unit is further configured to store a second time into the second task, where the second time is determined according to a first time and a polling cycle of the first queue, and the first time is a time for marking the second task; acquiring the second moment from the second task; and determining the next time for polling the first queue according to a third time and the second time, wherein the third time is the time from polling to the second task with the mark.
Optionally, the determining unit is further configured to determine whether a task is arranged in the first queue; and if the tasks are not distributed, the task is judged whether to be distributed in the first queue or not after waiting for the polling period of the first queue.
Optionally, the queue types of the multiple queues include any one or a combination of multiple queues in a memory queue arranged in a memory, a file queue arranged in a disk, and a queue in a table structure form arranged in a database.
Optionally, the queue with the shortest polling period in the plurality of queues is a memory queue arranged in a memory.
Optionally, the apparatus further includes an obtaining unit:
the acquiring unit is used for acquiring a third task, wherein the third task is a task with time delay time;
the arranging unit is further configured to arrange the third task into a third queue of the plurality of queues, where a delay time of the third task is in a time interval corresponding to the third queue.
It can be seen that, a plurality of queues for arranging tasks are arranged in the computer system, the delay time of the tasks arranged in the queues conforms to the time interval corresponding to the queues, and since the tasks with the delay time in different time intervals are distributed in different queues, the number of tasks to be polled at one time is obviously less than the number of tasks to be polled at one time in the conventional manner. And polling the tasks in the first queue according to the polling period of the first queue, and calculating the time delay from polling to the tasks, if the time delay from polling to the first task is in the time interval corresponding to the second queue in the queues, taking the first task out of the first queue and arranging the first task in the second queue with a smaller polling period, so that the first task can be placed in the first queue with a longer polling period when the time delay of the first task is longer, thereby avoiding frequent polling of the first task and saving system resources. When the delay time of the first task is short, the first task can be arranged in a second queue with a short polling period, and the possibility that the delay time of the first task can be timely executed when the delay time of the first task is zero is improved through frequent polling.
Fig. 7 is a flowchart of a method for arranging tasks according to an embodiment of the present invention, where the method is applied to a computer system, where the computer system is provided with a plurality of queues having corresponding time intervals, and each queue in the plurality of queues is used to arrange tasks whose delay times meet the time interval corresponding to the queue, and the method includes:
s701: and acquiring a task, wherein the task is a task with time delay time.
S702: and if the delay time of the task is in a time interval corresponding to a target queue, the task is arranged in the target queue, and the target queue is one of the queues.
That is, the time interval corresponding to the queue may be used as a basis for arranging the newly created task, and the newly created task may be the task acquired in S701.
Because each queue has a corresponding time interval, a queue meeting the task arrangement requirement can be selected according to the delay time of the newly created task, or in other words, if the delay time of the task falls into the time interval corresponding to one queue of the plurality of queues, the queue can be the target queue in S702, and the task can be arranged in the queue.
It should be noted that, the present invention does not limit the specific position of the task in the target queue.
Optionally, the plurality of queues at least include a first queue and a second queue, and a polling period of the first queue is greater than a polling period of the second queue, the method includes:
polling the tasks arranged in the first queue according to the polling period of the first queue;
calculating the time delay from polling to the task;
judging a time interval of the time delay time of the polled task; when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue;
and if the delay time of the first task is in the time interval corresponding to the second queue, taking the first task out of the first queue and distributing the first task into the second queue.
Optionally, the queue types of the multiple queues include any one or a combination of multiple queues in the form of a memory queue set in a memory, a file queue set in a disk, and a list structure set in a database.
Optionally, the queue with the shortest polling period in the plurality of queues is a memory queue arranged in a memory.
It can be seen that, since tasks with different time delays in different time intervals are distributed in different queues, only the tasks in one queue are polled, so that the number of tasks that need to be polled at one time is obviously less than that of the tasks that need to be polled at one time in the conventional manner in the computer system. The problem that the executed task is delayed because some delay time is already zero due to the fact that the time is not polled in time can be effectively reduced or even avoided.
Fig. 8 is a device structure diagram of a task arranging device according to an embodiment of the present invention, which is applied to a computer system, where the computer system is provided with a plurality of queues having corresponding time intervals, and each queue in the plurality of queues is used to arrange a task whose delay time meets the time interval corresponding to the queue, where the device includes an obtaining unit 801 and an arranging unit 802:
the acquiring unit 801 is configured to acquire a task, where the task is a task with a delay time;
the arranging unit 802 is configured to arrange the task into a target queue if the delay time of the task is in a time interval corresponding to the target queue, where the target queue is one of the multiple queues.
Optionally, the plurality of queues at least include a first queue and a second queue, where a polling cycle of the first queue is greater than a polling cycle of the second queue, the apparatus further includes a polling unit, a calculating unit, a determining unit, and an arranging unit:
the polling unit is used for polling the tasks arranged in the first queue according to the polling period of the first queue;
the computing unit is used for computing the time delay time from polling to the task;
the judging unit is used for judging a time interval in which the time delay time of the polled task is located; when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue; if the delay time of the first task is in the time interval corresponding to the second queue, triggering the arrangement unit;
the arranging unit is used for taking the first task out of the first queue and arranging the first task into the second queue.
Optionally, the queue types of the multiple queues include any one or a combination of multiple queues in a memory queue arranged in a memory, a file queue arranged in a disk, and a queue in a table structure form arranged in a database.
Optionally, the queue with the shortest polling period among the queues is a memory queue set in the memory.
It can be seen that, since tasks with different time delays are distributed in different queues, only the tasks in one queue are polled, and the number of tasks required to be polled at one time is obviously less than that of the tasks required to be polled in the computer system at one time in the conventional manner. The problem that the executed task is delayed because some delay time is already zero due to the fact that the time is not polled in time can be effectively reduced or even avoided.
Those of ordinary skill in the art will understand that: all or part of the steps for realizing the method embodiments can be completed by hardware related to program instructions, the program can be stored in a computer readable storage medium, and the program executes the steps comprising the method embodiments when executed; and the aforementioned storage medium may be at least one of the following media: various media that can store program codes, such as read-only memory (ROM), RAM, magnetic disk, or optical disk.
It should be noted that, in the present specification, all the embodiments are described in a progressive manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, the apparatus and system embodiments, because they are substantially similar to the method embodiments, are described in a relatively simple manner, and reference may be made to some of the descriptions of the method embodiments for related points. The above-described embodiments of the apparatus and system are merely illustrative, and the units described as separate parts may or may not be physically separate, and the parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
While the invention has been described with reference to specific preferred embodiments, it will be understood by those skilled in the art that various changes and modifications may be made without departing from the spirit and scope of the invention as defined in the following claims. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (16)

1. A task polling method is applied to a computer system, wherein a plurality of queues with corresponding time intervals are arranged in the computer system, each queue in the plurality of queues is used for arranging tasks with delay time meeting the corresponding time interval, the plurality of queues at least comprise a first queue and a second queue, a polling period of the first queue is greater than a polling period of the second queue, and the method comprises the following steps:
polling the tasks arranged in the first queue according to the polling period of the first queue;
calculating the time delay from polling to the task;
judging a time interval of the time delay time of the polled task; when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue;
and if the delay time of the first task is in the time interval corresponding to the second queue, taking the first task out of the first queue and distributing the first task into the second queue.
2. The method of claim 1, wherein determining a time interval in which the delay time of the first task is located further comprises:
and if the time delay time of the first task is less than or equal to 0, taking the first task out of the first queue, and executing the first task.
3. The method of claim 1, wherein the time interval corresponding to the first queue is non-overlapping with the time interval corresponding to the second queue.
4. The method of claim 1, wherein polling the queued tasks in the first queue according to the polling period of the first queue comprises:
setting a flag for a second task, wherein the second task is a first task polled in a polling period of the first queue;
after the second task is polled, the second task is arranged at the tail of the first queue;
sequentially polling the tasks in the first queue according to the queue arrangement sequence, and arranging one task to the tail of the first queue after the task is polled;
when the second task with the mark is polled, canceling the mark of the second task and finishing polling.
5. The method of claim 4, wherein setting a flag for the second task further comprises:
saving a second time into the second task, wherein the second time is determined by a first time and a polling cycle of the first queue, and the first time is a time for marking the second task;
when polling to the second task with the mark, the method further comprises:
acquiring the second moment from the second task;
and determining the next time for polling the first queue according to a third time and the second time, wherein the third time is the time from polling to the second task with the mark.
6. The method according to any one of claims 1 to 5, further comprising, before said polling the queued tasks in the first queue according to the polling period of the first queue:
judging whether tasks are arranged in the first queue or not;
and if the tasks are not arranged, waiting for a polling period of the first queue and then executing the judgment again to judge whether the tasks are arranged in the first queue.
7. The method according to any one of claims 1 to 5, wherein the queue types of the plurality of queues include any one or more of a memory queue provided in a memory, a file queue provided in a disk, and a queue provided in a table structure form in a database.
8. The method according to any one of claims 1 to 5, wherein the queue with the shortest polling period among the plurality of queues is a memory queue disposed in a memory.
9. The method according to any one of claims 1 to 5, further comprising:
acquiring a third task, wherein the third task is a task with time delay time;
and arranging the third task into a third queue of the plurality of queues, wherein the delay time of the third task is in a time interval corresponding to the third queue.
10. The task polling device is applied to a computer system, wherein a plurality of queues with corresponding time intervals are arranged in the computer system, each queue in the plurality of queues is used for arranging tasks with delay time meeting the corresponding time interval, the plurality of queues at least comprise a first queue and a second queue, the polling period of the first queue is greater than that of the second queue, and the device comprises a polling unit, a calculating unit, a judging unit and an arranging unit:
the polling unit is used for polling the tasks arranged in the first queue according to the polling period of the first queue;
the computing unit is used for computing the time delay time of the polled task;
the judging unit is used for judging the time interval of the time delay time of the polled task; when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue; if the delay time of the first task is in the time interval corresponding to the second queue, triggering the arrangement unit;
the arranging unit is used for taking the first task out of the first queue and arranging the first task into the second queue.
11. The apparatus according to claim 10, wherein the polling unit is further configured to set a flag for a second task, the second task being a first task polled in a polling period of the first queue; after the second task is polled, the second task is arranged at the tail of the first queue; sequentially polling the tasks in the first queue according to the queue arrangement sequence, and arranging one task to the tail of the first queue after the task is polled; when the second task with the mark is polled, canceling the mark of the second task and finishing polling.
12. The apparatus according to claim 11, wherein the polling unit is further configured to save a second time into the second task, the second time being determined by a first time and a polling period of the first queue, the first time being a time when the second task is marked; acquiring the second moment from the second task; and determining the next time for polling the first queue according to a third time and the second time, wherein the third time is the time from polling to the second task with the mark.
13. A task arranging method, applied to a computer system, where multiple queues having corresponding time intervals are set in the computer system, each queue in the multiple queues is used to arrange tasks whose delay times meet the time interval corresponding to the queue, the multiple queues include at least a first queue and a second queue, a polling cycle of the first queue is greater than a polling cycle of the second queue, and the method includes:
acquiring a task, wherein the task is a task with time delay time;
if the delay time of the task is in a time interval corresponding to a target queue, the task is arranged in the target queue, and the target queue is one of the queues;
polling the tasks arranged in the first queue according to the polling period of the first queue;
calculating a time delay time from polling to the task;
judging a time interval of the time delay time of the polled task; when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue;
and if the delay time of the first task is in the time interval corresponding to the second queue, taking the first task out of the first queue and distributing the first task into the second queue.
14. The method of claim 13, wherein the queue types of the plurality of queues include any one or more of a memory queue disposed in a memory, a file queue disposed in a disk, and a queue disposed in a table structure in a database.
15. The method according to claim 13, wherein the queue with the shortest polling period among the plurality of queues is a memory queue disposed in a memory.
16. A task arranging device is applied to a computer system, wherein a plurality of queues with corresponding time intervals are arranged in the computer system, each queue in the plurality of queues is used for arranging tasks with delay time meeting the time interval corresponding to the queue, the plurality of queues at least comprise a first queue and a second queue, the polling period of the first queue is greater than that of the second queue, and the device comprises an obtaining unit and an arranging unit:
the acquisition unit is used for acquiring a task, wherein the task is a task with time delay time;
the arranging unit is used for arranging the task into a target queue if the time delay of the task is in a time interval corresponding to the target queue, wherein the target queue is one of the queues;
the device further comprises: polling the tasks arranged in the first queue according to the polling period of the first queue;
calculating the time delay from polling to the task;
judging a time interval of the time delay time of the polled task; when the time interval of the time delay time of the first task is judged, the first task is one of the tasks arranged in the first queue;
and if the delay time of the first task is in the time interval corresponding to the second queue, taking the first task out of the first queue and distributing the first task into the second queue.
CN201610942962.8A 2016-10-31 2016-10-31 Task polling method, task arrangement method and related device Active CN108021439B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610942962.8A CN108021439B (en) 2016-10-31 2016-10-31 Task polling method, task arrangement method and related device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610942962.8A CN108021439B (en) 2016-10-31 2016-10-31 Task polling method, task arrangement method and related device

Publications (2)

Publication Number Publication Date
CN108021439A CN108021439A (en) 2018-05-11
CN108021439B true CN108021439B (en) 2022-07-15

Family

ID=62070712

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610942962.8A Active CN108021439B (en) 2016-10-31 2016-10-31 Task polling method, task arrangement method and related device

Country Status (1)

Country Link
CN (1) CN108021439B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110139229B (en) * 2019-04-15 2022-03-29 平安科技(深圳)有限公司 Method and device for sending short message in delayed mode, computer equipment and storage medium
CN111343152B (en) * 2020-02-07 2023-01-24 北京达佳互联信息技术有限公司 Data processing method and device, electronic equipment and storage medium
CN112966876B (en) * 2021-03-19 2024-04-12 北京京东振世信息技术有限公司 Order production scheduling method and device, electronic equipment and readable medium
CN116647530A (en) * 2023-06-06 2023-08-25 深圳花儿绽放网络科技股份有限公司 Automatic execution system for instant messaging task

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1794855A (en) * 2005-06-27 2006-06-28 华为技术有限公司 Method and device synchronous operating time in equipment management
CN1870767A (en) * 2005-12-14 2006-11-29 华为技术有限公司 Method for managing timer task
CN101178713A (en) * 2006-11-29 2008-05-14 腾讯科技(深圳)有限公司 Method and system for collecting web page
CN101183316A (en) * 2007-11-28 2008-05-21 北京中星微电子有限公司 Tasks delayed time processing method and system in real-time operating system
CN101561767A (en) * 2008-04-16 2009-10-21 上海聚力传媒技术有限公司 Method and device for executing tasks based on operating system
CN103744730A (en) * 2014-01-27 2014-04-23 北京京东尚科信息技术有限公司 Task scheduling method and device
CN105808329A (en) * 2016-02-25 2016-07-27 北京京东尚科信息技术有限公司 Distributed overtime task scheduling method and device

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8244943B2 (en) * 2009-09-30 2012-08-14 International Business Machines Corporation Administering the polling of a number of devices for device status
CN104951282A (en) * 2015-05-21 2015-09-30 中国人民解放军理工大学 Timer management system and method
CN105915468B (en) * 2016-06-17 2019-03-29 北京邮电大学 A kind of dispatching method and device of business

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1794855A (en) * 2005-06-27 2006-06-28 华为技术有限公司 Method and device synchronous operating time in equipment management
CN1870767A (en) * 2005-12-14 2006-11-29 华为技术有限公司 Method for managing timer task
CN101178713A (en) * 2006-11-29 2008-05-14 腾讯科技(深圳)有限公司 Method and system for collecting web page
CN101183316A (en) * 2007-11-28 2008-05-21 北京中星微电子有限公司 Tasks delayed time processing method and system in real-time operating system
CN101561767A (en) * 2008-04-16 2009-10-21 上海聚力传媒技术有限公司 Method and device for executing tasks based on operating system
CN103744730A (en) * 2014-01-27 2014-04-23 北京京东尚科信息技术有限公司 Task scheduling method and device
CN105808329A (en) * 2016-02-25 2016-07-27 北京京东尚科信息技术有限公司 Distributed overtime task scheduling method and device

Also Published As

Publication number Publication date
CN108021439A (en) 2018-05-11

Similar Documents

Publication Publication Date Title
CN108021439B (en) Task polling method, task arrangement method and related device
US10459915B2 (en) Managing queries
CN106407190A (en) Event record querying method and device
US9430283B2 (en) Information processing apparatus and job scheduling method
US8984527B2 (en) System and method for execution time donation in a time-partitioning scheduler
CN101366012A (en) Methods and system for interrupt distribution in a multiprocessor system
JP2020531967A (en) Distributed system Resource allocation methods, equipment, and systems
CN107391279B (en) Message queue container creation method and device and message queue container
WO2021104178A1 (en) Dynamic message pushing method and system and vehicle diagnosis server
CN113138860B (en) Message queue management method and device
CN107818012B (en) Data processing method and device and electronic equipment
CN110138662B (en) Session table item processing method and device in multi-core system and multi-core system
US20150378782A1 (en) Scheduling of tasks on idle processors without context switching
CN103473071B (en) The implementation method of software timer and system
CN112860387A (en) Distributed task scheduling method and device, computer equipment and storage medium
CN111143053A (en) Scheduling method of timing task, server and storage device
CN113703929B (en) Task scheduling method, system, computing device and storage medium
CN111736961B (en) Virtual machine release method and device, storage medium and electronic equipment
JP2009230581A (en) Batch job control system, management node, and batch job control method
CN111679895A (en) Execution method, device and equipment of distributed timing task and readable storage medium
CN108769244B (en) Storage task information acquisition method and related device
CN110912949B (en) Method and device for submitting sites
CN111026527A (en) Distribution execution system for processing mass timing tasks
CN113242149B (en) Long connection configuration method, apparatus, device, storage medium, and program product
CN109460193A (en) I O process method, apparatus and terminal in a kind of storage system

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
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20230608

Address after: Room 1-2-A06, Yungu Park, No. 1008 Dengcai Street, Sandun Town, Xihu District, Hangzhou City, Zhejiang Province

Patentee after: Aliyun Computing Co.,Ltd.

Address before: Box 847, four, Grand Cayman capital, Cayman Islands, UK

Patentee before: ALIBABA GROUP HOLDING Ltd.