Task scheduling method, system, device and medium
By sorting and optimizing the service time of tasks in the task scheduling queue, the problem of excessive waiting time in the existing technology is solved, and the system throughput is improved.
Patent Information
- Application Number
- CN202011416121.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-04
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2040-12-04
AI Technical Summary
In the prior art, the method of task scheduling may cause the average waiting time of the task to be too long, thereby reducing the throughput of the system.
By receiving task execution requests, obtain the service time of the task and the service time of the task to be executed in the queue, sort the tasks according to the size of the service time, form a new task scheduling queue, and execute the tasks in the queue in sequence.
This method can ensure that tasks with the shortest service time are executed first, reduce the average waiting time of all tasks, and improve the system throughput.
Smart Images

Figure CN112395067B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of financial technology (Fintech), and in particular to a task scheduling method, system, device and computer storage medium. Background Art
[0002] With the development of computer technology, more and more technologies (big data, distributed, artificial intelligence, etc.) are applied in the financial field. The traditional financial industry is gradually transforming to financial technology (Fintech). However, due to the security and versatility requirements of the financial industry, higher requirements are also placed on task scheduling technology.
[0003] In applications, in order to improve the throughput of the system, queue technology is often used for data transmission. The queue has a first-in-first-out or first-in-last-out mechanism. In the first-in-first-out mechanism of the queue, the first element that enters the queue will inevitably be the first to be dequeued, and subsequent data processing will be given priority. After the processing is completed, the next element will be dequeued, and the subsequent elements will be dequeued in the same way.
[0004] In the prior art, the idea of task scheduling is to select the first task that enters the ready queue from the ready queue each time scheduling, and put it into operation. The task will not give up its priority until it is completed or blocked by an event, and then select another first task that enters the queue from the remaining ready queues to put it into operation. However, since each task (except the first one) may have a waiting time, this solution of executing each task request one by one in the order of the arrival time of the task request may cause the average waiting time of the task to be too long, thereby reducing the system throughput. Summary of the invention
[0005] The main purpose of the present invention is to provide a task scheduling method, system, device and computer storage medium, aiming to reduce the average waiting time of tasks.
[0006] To achieve the above object, the present invention provides a task scheduling method, which comprises the following steps:
[0007] Receiving an execution request for a first task, obtaining a service time of the first task and a service time of each task to be executed in a task scheduling queue;
[0008] Based on the service time of the first task and the service time of each of the tasks to be executed, the first task and each of the tasks to be executed are sorted according to the size of the service time to obtain a new task scheduling queue, and the tasks in the new task scheduling queue are executed in sequence according to the size of the service time, wherein the tasks with smaller service time are closer to the head of the queue in the new task scheduling queue.
[0009] Optionally, the step of sorting the first task and each of the tasks to be executed according to the size of the service time to obtain a new task scheduling queue includes:
[0010] Determine whether there is a second task with the same service time between the first task and the to-be-performed task;
[0011] If it exists, the second task and other tasks are sorted according to the service time, and the second task is sorted according to the order of the task request time of the second task to obtain a new task scheduling queue.
[0012] Optionally, after the step of receiving the execution request for the first task, the method further includes:
[0013] Determine whether there are undequeued tasks in the task scheduling queue and whether there are tasks being executed;
[0014] If there is no unqueued task in the task scheduling queue and no task being executed, execute the first task;
[0015] If there are undequeued tasks in the task scheduling queue and / or there are tasks being executed, the following steps are performed: obtaining the service time of the first task and the service time of each task to be executed in the task scheduling queue.
[0016] Optionally, after the step of sorting the first task and each of the tasks to be executed according to the service time to obtain a new task scheduling queue, the step further includes:
[0017] Monitoring the waiting time of each task in the new task scheduling queue;
[0018] The task whose waiting time is greater than or equal to the preset time threshold is adjusted to the head of the new task scheduling queue.
[0019] Optionally, after the step of sorting the first task and each of the tasks to be executed according to the service time to obtain a new task scheduling queue, the step further includes:
[0020] Monitoring the waiting time of each task in the new task scheduling queue;
[0021] Determine the response ratio of each task according to the waiting time and service time of each task;
[0022] The task whose response ratio is greater than or equal to a preset response ratio threshold is adjusted to the head of the new task scheduling queue.
[0023] Optionally, after the step of receiving the execution request for the first task, the method further includes:
[0024] Obtaining the service time of the first task and the remaining service time of the currently executed task;
[0025] Determining whether the service time of the first task is greater than or equal to the remaining service time of the currently executed task;
[0026] If yes, then execute the steps: obtaining the service time of the first task and the service time of each task to be executed in the task scheduling queue;
[0027] If not, suspend the execution of the currently executed task, execute the first task, sort the currently executed task and each of the tasks to be executed in the task scheduling queue according to the remaining service time of the currently executed task and the service time of each task to be executed, and obtain a new task scheduling queue.
[0028] Optionally, after the step of executing tasks in sequence according to the new task scheduling queue, the method further includes:
[0029] Obtaining the actual execution time of each task in the new task scheduling queue, and calculating the absolute value of the difference between the actual execution time and the service time of each task;
[0030] Adding the requester corresponding to the task whose absolute value is greater than or equal to the preset threshold into the task scheduling blacklist;
[0031] When the execution request for the second task from the requesting party is received again, the second task is inserted into and maintained at the end of the current task scheduling queue.
[0032] In addition, to achieve the above object, the present invention also provides a task scheduling system, the task scheduling system comprising:
[0033] A service time acquisition module, used to receive an execution request for a first task, and obtain the service time of the first task and the service time of each task to be executed in the task scheduling queue;
[0034] A task sorting module is used to sort the first task and each of the tasks to be executed according to the service time based on the service time of the first task and the service time of each of the tasks to be executed, so as to obtain a new task scheduling queue, and to execute the tasks in the new task scheduling queue in sequence according to the service time, wherein the tasks with smaller service time are closer to the head of the queue in the new task scheduling queue.
[0035] In addition, to achieve the above-mentioned purpose, the present invention also provides a task scheduling device, which includes: a memory, a processor, and a task scheduling program stored in the memory and executable on the processor, and the task scheduling program implements the steps of the task scheduling method described above when executed by the processor.
[0036] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer storage medium, on which a task scheduling program is stored, and when the task scheduling program is executed by a processor, the steps of the task scheduling method described above are implemented.
[0037] The present invention receives an execution request for a first task, obtains the service time of the first task and the service time of each task to be executed in a task scheduling queue; based on the service time of the first task and the service time of each task to be executed, the first task and each task to be executed are sorted according to the size of the service time to obtain a new task scheduling queue, and the tasks in the new task scheduling queue are executed in sequence according to the size of the service time, wherein the smaller the service time, the closer the task is to the head of the queue in the new task scheduling queue.
[0038] When a new task arrives, the order of each task in the task scheduling queue is rearranged according to the service time of all tasks. The reordering is carried out in the order of service time from the head to the tail of the task scheduling queue. This ensures that the task with the shortest service time is executed first, thereby reducing the average waiting time of all tasks and improving the system throughput. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 It is a schematic diagram of the structure of a task scheduling device in a hardware operating environment involved in an embodiment of the present invention;
[0040] Figure 2 It is a flowchart of the first embodiment of the task scheduling method of the present invention;
[0041] Figure 3 A schematic diagram of an existing task scheduling scheme;
[0042] Figure 4 A schematic diagram of the task scheduling method of the present invention;
[0043] Figure 5 It is a schematic diagram of the system modules of the task scheduling system of the present invention.
[0044] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0045] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0046] like Figure 1 As shown, Figure 1 It is a schematic diagram of the structure of a task scheduling device in a hardware operating environment involved in an embodiment of the present invention.
[0047] The task scheduling device in the embodiment of the present invention may be a PC or a server device, on which a virtual machine runs.
[0048] like Figure 1 As shown, the task scheduling device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0049] Those skilled in the art will understand that Figure 1 The task scheduling device structure shown in the figure does not constitute a limitation on the device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0050] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a task scheduling program.
[0051] exist Figure 1 In the task scheduling device shown, the network interface 1004 is mainly used to connect to the background server and communicate data with the background server; the user interface 1003 is mainly used to connect to the client (user end) and communicate data with the client; and the processor 1001 can be used to call the task scheduling program stored in the memory 1005 and perform the operations in the following task scheduling method.
[0052] Based on the above hardware structure, an embodiment of the task scheduling method of the present invention is proposed.
[0053] Reference Figure 2 , Figure 2This is a flow chart of a first embodiment of a task scheduling method of the present invention, wherein the method comprises:
[0054] Step S10, receiving an execution request for a first task, and obtaining a service time of the first task and a service time of each task to be executed in a task scheduling queue;
[0055] The task scheduling method of this embodiment is applied to a task scheduling device, which may be a terminal, a robot or a PC device.
[0056] In the prior art, the idea of task scheduling is to select the first task that enters the ready queue from the ready queue each time scheduling, and put it into operation. The task will not give up its priority until it is completed or blocked by an event, and then select another first task that enters the queue from the remaining ready queues to put it into operation. However, since each task (except the first one) may have a waiting time, this solution of executing each task request one by one in the order of the arrival time of the task request may cause the average waiting time of the task to be too long, thereby reducing the system throughput.
[0057] In this context, this embodiment pursues a shorter average waiting time by rearranging the order of each task in the task scheduling queue according to the service time of all tasks when a new task arrives. When rearranging, the task scheduling queue is arranged in order from the head to the tail according to the service time from the smallest to the largest. This ensures that the task with the shortest service time is executed first, thereby reducing the average waiting time of all tasks.
[0058] In this embodiment, when receiving the execution request of the first task from the task requester, that is, when a new task arrives, the task scheduling device will obtain the service time of the first task and the service time of each task to be executed in the current task scheduling queue. The service time refers to the time required from the start of the task execution to the completion of the task execution, and the service time of each task may be the same or different.
[0059] There are many ways to obtain service time. One is that the task requester provides service time and sends the service time to the task scheduling device together with the execution request. The task scheduling device can obtain the service time of the task when receiving the execution request for each task. Another way is that the task scheduling device counts the historical execution time of each task according to the historical execution of each task, and then calculates the average value of the historical execution time corresponding to each task, receives the execution request for the first task, and then obtains the average value of the historical execution time of the first task as the service time of the first task. Of course, the service time can also be obtained according to the task type, that is, the task scheduling device counts the historical execution time of each task according to the historical execution of each task, and then calculates the average value of the historical execution time of the task type corresponding to each task, receives the execution request for the first task, and then obtains the average value of the historical execution time of the task type corresponding to the first task as the service time of the first task. This embodiment does not limit the specific method of obtaining service time.
[0060] Among them, the task scheduling queue is mainly used to execute a series of asynchronous tasks in sequence. The tasks in the task scheduling queue can be executed in sequence from the head of the queue to the end of the queue.
[0061] Further, after the step of receiving the execution request for the first task, the method further includes:
[0062] Step a1, determining whether there are any undequeued tasks in the task scheduling queue and whether there are any tasks being executed;
[0063] Step a2: if there is no unqueued task in the task scheduling queue and no task being executed, then execute the first task;
[0064] If there are undequeued tasks in the task scheduling queue and / or there are tasks being executed, the following steps are performed: obtaining the service time of the first task and the service time of each task to be executed in the task scheduling queue.
[0065] In this embodiment, after receiving the execution request for the first task, the task scheduling device first needs to determine whether the first task can be directly executed without participating in the queue. Specifically, determine whether there are unqueued tasks and whether there are tasks being executed in the task scheduling queue. If there are unqueued tasks in the task scheduling queue, it means that when the first task arrives, there are other tasks waiting to be executed. At this time, it is necessary to rearrange the order of the first task and each task to be executed in the task scheduling queue according to the service time; if there are tasks being executed, it means that when the first task arrives, there are other tasks being executed. At this time, it is necessary to rearrange the order of the first task and each task to be executed in the task scheduling queue according to the service time. It should be noted that when a task in the task scheduling queue is executed, the task will be deleted from the task scheduling queue, that is, dequeued; only when it is determined that there are no unqueued tasks and no tasks being executed in the task scheduling queue, the first task will be directly executed.
[0066] This embodiment can directly execute the first task when it is determined that there are no other tasks being executed or waiting to be executed, thereby ensuring the timeliness of the execution of the newly arrived task.
[0067] Step S20, based on the service time of the first task and the service time of each of the tasks to be executed, sort the first task and each of the tasks to be executed according to the size of the service time to obtain a new task scheduling queue, and execute the tasks in the new task scheduling queue in sequence according to the size of the service time, wherein the smaller the service time, the closer the task is to the head of the queue in the new task scheduling queue.
[0068] In this embodiment, after obtaining the service time of the newly arrived task, i.e., the first task, and the service time of each task to be executed, all tasks are sorted in ascending order of service time, and a new task scheduling queue is determined based on the sorting result. The task with a smaller service time is closer to the head of the new task scheduling queue, and the task with a larger service time is closer to the tail of the new task scheduling queue. Since the tasks in the task scheduling queue are executed sequentially from the head to the tail, this embodiment can ensure that tasks with smaller service times are executed first through the above-mentioned method of re-arranging the task scheduling queue, thereby reducing the average waiting time of all tasks compared to the existing task scheduling method.
[0069] To help understand, an example is given. There are three tasks P1, P2, and P3. The task request time of P1 is 0, and the service time is 7; the task request time of P2 is 2, and the service time is 4; the task request time of P3 is 4, and the service time is 1. According to the scheme in the prior art that each task is executed one by one in the order of the arrival time of the task request, the task execution order is P1, P2, and P3. P1 arrives first and is executed first. Then the waiting time of P1 is 0, the waiting time of P2 is 7-2=5, and the waiting time of P3 is (7+4)-4=7. Then the average waiting time is (0+5+7) / 3=4. According to the scheme of executing tasks according to the size of the service time in this embodiment, the task execution order is P1, P3, and P2. The specific reason is that P1 arrives first and is still executed first. Therefore, P1 P1's waiting time is 0; although P2's request time is 2, P1 is not completed at this time. The time point after P1 is completed is 7, and P2 and P3 have arrived at this time. They are sorted according to the size of the service time. P3's service time is less than P1's service time. P3 will be executed first after P1 is completed, so the waiting time of P3 is 7-4=3; P2's waiting time is: (7+1)-2=6, and the average waiting time is (0+3+6) / 3=3. It can be seen that the task scheduling scheme of this embodiment can reduce the average waiting time of tasks.
[0070] Furthermore, the step of sorting the first task and each of the tasks to be executed according to the service time to obtain a new task scheduling queue includes:
[0071] Step b1, determining whether there is a second task with the same service time between the first task and the task to be executed;
[0072] Step b2: if it exists, sort the second task and other tasks according to the service time, and sort the second task according to the order of the task request time of the second task to obtain a new task scheduling queue.
[0073] In this embodiment, when the task scheduling queue is re-arranged, it is first determined whether there is a task with the same service time among the first task and the tasks to be executed, that is, the second task. If not, these tasks are directly sorted according to the size of the service time; if so, the second task and other tasks are still sorted according to the size of the service time, but for the second tasks with the same service time, they are sorted in the order of task request time. The earlier the task request time, the closer to the head of the queue in the new task scheduling queue.
[0074] To help understand, here is an example. There are four tasks P1, P2, P3, and P4. The task request time of P1 is 0 and the service time is 7; the task request time of P2 is 2 and the service time is 4; the task request time of P3 is 4 and the service time is 1; the task request time of P4 is 5 and the service time is 4. According to the scheme of executing each task one by one in the order of the arrival time of the task request in the prior art, see Figure 3 , the task execution order is P1, P2, P3, P4, P1 arrives first and is executed first, then the waiting time of P1 is 0, the waiting time of P2 is 7-2=5, the waiting time of P3 is (7+4)-4=7, the waiting time of P4 is (7+4+1)-5=7, then the average waiting time is (0+5+7+7) / 4=4.75; and according to the scheme of executing tasks according to the size of service time in this embodiment, see Figure 4 , the task execution order is P1, P3, P2, P4. The specific reason is that P1 arrives first and is still executed first. Therefore, the waiting time of P1 is 0; although the request time of P2 is 2, P1 is not completed at this time. The time point after P1 is completed is 7. At this time, P2, P3 and P4 have all arrived. Then they are sorted according to the size of the service time. The service time of P3 is less than the service time of P2 and P4. Then P3 is executed first after P1 is completed. Therefore, the waiting time of P3 is 7-4=3; the service time of P2 and P4 is the same. For P2 and P4, the task with the earlier request time is executed first. Therefore, P2 is executed first, and then P4, so the waiting time of P2 is (7+1)-2=6; the waiting time of P4 is (7+1+4)-5=7, so the average waiting time is (0+3+6+7) / 4=4. It can be seen that the task scheduling scheme of this embodiment can reduce the average waiting time of tasks.
[0075] In the above manner, this embodiment prioritizes sorting tasks according to service time, and sorting tasks with the same service time according to task request time, thereby ensuring the orderly execution of tasks with the same service time. For tasks with the same service time, tasks with longer waiting time, that is, tasks with earlier task request time, are executed first, thereby avoiding long waiting times for the requester.
[0076] In this embodiment, by receiving an execution request for a first task, the service time of the first task and the service time of each task to be executed in the task scheduling queue are obtained; based on the service time of the first task and the service time of each task to be executed, the first task and each task to be executed are sorted according to the size of the service time to obtain a new task scheduling queue, and the tasks in the new task scheduling queue are executed in sequence according to the size of the service time, wherein the task with a smaller service time is closer to the head of the queue in the new task scheduling queue.
[0077] When a new task arrives, the order of each task in the task scheduling queue is rearranged according to the service time of all tasks. The reordering is carried out in the order of service time from the head to the tail of the task scheduling queue. This ensures that the task with the shortest service time is executed first, thereby reducing the average waiting time of all tasks and improving the system throughput.
[0078] Further, based on the first embodiment of the task scheduling method of the present invention, a second embodiment of the task scheduling method of the present invention is proposed. After the above step of sorting the first task and each of the tasks to be executed according to the size of the service time to obtain a new task scheduling queue, it also includes:
[0079] Step c1, monitoring the waiting time of each task in the new task scheduling queue;
[0080] Step c2: Adjust the task whose waiting time is greater than or equal to the preset time threshold to the head of the new task scheduling queue.
[0081] For the above embodiment, if there are tasks with shorter service time than the task in the task scheduling queue before the task with longer service time is executed, the task may be queued for a long time and cannot be executed, resulting in a long waiting time for the task and reduced user satisfaction. The so-called waiting time is the difference between the start time of the task execution and the task request time.
[0082] To address this situation, this embodiment will monitor the waiting time of each task in the task scheduling queue after rearranging the task execution order according to the service time, and compare the waiting time with the preset time threshold. Tasks with a waiting time greater than or equal to the preset time threshold will be adjusted to the head of the task scheduling queue, so that tasks with too long waiting time can be executed first, avoiding indefinite waiting, and improving the satisfaction of the requester of such tasks with long service time.
[0083] It is understandable that if there are multiple tasks whose waiting time is greater than or equal to the preset time threshold, the task with the longer waiting time, that is, the task with an earlier task request time, will be executed first.
[0084] Furthermore, after the step of sorting the first task and each of the tasks to be executed according to the size of the service time to obtain a new task scheduling queue, the method further includes:
[0085] Step d1, monitoring the waiting time of each task in the new task scheduling queue;
[0086] Step d2, determining the response ratio of each task according to the waiting time and service time of each task;
[0087] Step d3: Adjust the task whose response ratio is greater than or equal to a preset response ratio threshold to the head of the new task scheduling queue.
[0088] In view of the possible indefinite waiting situation of the above-mentioned tasks with long service times, in this embodiment, the waiting time of each task in the task scheduling queue is monitored, and the response ratio of each task is determined based on the waiting time, service time and a preset response ratio formula, wherein the preset response ratio formula is R=(Tw+Ts) / Ts, wherein R is the response ratio of the task; Tw is the waiting time; and Ts is the service time.
[0089] Then compare the response ratio with the preset response ratio threshold, and adjust the tasks with a response ratio greater than or equal to the preset response ratio threshold to the head of the task scheduling queue. The response ratio comprehensively considers the waiting time and service time of the task. When the waiting time is the same, the shorter the service time, the greater the response ratio, and the more priority it will be executed; when the service time is the same, the longer the waiting time, the greater the response ratio, and the more priority it will be executed, so that tasks with too long waiting time and short service time can be executed first.
[0090] Furthermore, in the above step S10, after receiving the execution request for the first task, the following step is further included:
[0091] Step e1, obtaining the service time of the first task and the remaining service time of the currently executed task;
[0092] Step e2, determining whether the service time of the first task is greater than or equal to the remaining service time of the currently executed task;
[0093] Step e3, if not, suspend the execution of the currently executed task, execute the first task, sort the currently executed task and each of the tasks to be executed in the task scheduling queue according to the remaining service time of the currently executed task and the service time of each of the tasks to be executed in the task scheduling queue, and obtain a new task scheduling queue;
[0094] If so, execute the step: obtaining the service time of the first task and the service time of each task to be executed in the task scheduling queue.
[0095] In this embodiment, when receiving the execution request for the first task, the service time of the first task and the remaining service time of the currently executed task are obtained, and it is determined whether the service time of the first task is greater than or equal to the remaining service time of the currently executed task. If the service time of the first task is greater than or equal to the remaining service time of the currently executed task, the step of obtaining the service time of the first task and the service time of each task to be executed in the task scheduling queue is performed, that is, the task scheduling queue is rearranged according to the first embodiment. Among them, the remaining service time refers to how long it will take from the current time to complete the execution of the currently executed task.
[0096] When the service time of the first task is less than the remaining service time of the currently executing task, the execution of the currently executing task is suspended, and the first task is executed. According to the remaining service time of the currently executing task and the service time of each task to be executed in the task scheduling queue, the currently executing task and each task to be executed are sorted to obtain a new task scheduling queue. The new task scheduling queue is arranged from the head to the tail in the order of service time from small to large, and then the tasks are executed in sequence according to the order of the new task scheduling queue.
[0097] In this embodiment, when a task with a longer service time is being executed, if a task with a shorter service time arrives, and the service time of the task with a shorter service time is less than the remaining service time of the currently executing task, the task with a shorter service time will be executed immediately to avoid the short task waiting for a long time, and also to avoid the same task occupying the CPU for a long time.
[0098] Furthermore, after the step of executing tasks in sequence according to the new task scheduling queue, the method further includes:
[0099] Step f1, obtaining the actual execution time of each task in the new task scheduling queue, and calculating the absolute value of the difference between the actual execution time and the service time of each task;
[0100] Step f2, adding the requester corresponding to the task whose absolute value is greater than or equal to the preset threshold to the task scheduling blacklist;
[0101] Step f3: when receiving the execution request of the second task from the requesting party again, inserting the second task into the tail of the current task scheduling queue and keeping it there.
[0102] In this embodiment, for the case where the service time is provided by the requester itself, in the process of executing tasks in sequence according to the new task scheduling queue, the task scheduling device will record the actual execution time of each task, and calculate the absolute value of the difference between the actual execution time and the service time of the task. If the absolute value is greater than the preset threshold, it means that the accuracy of the service time provided by the task requester is too low, and then the credibility of the requester is low. In order to avoid the subsequent impact of the low-accuracy service time provided by the requester on the normal scheduling of tasks of other requesters, the requester corresponding to the task whose absolute value is greater than or equal to the preset threshold can be included in the task scheduling blacklist, so that when the execution request for the second task from the requester who hits the task scheduling blacklist is received again, the second task will be inserted and maintained at the end of the current task scheduling queue, that is, the second task maintains the lowest priority, regardless of the service time of the second task.
[0103] Of course, when the requester corresponding to the task whose absolute value is greater than or equal to the preset threshold is included in the task scheduling blacklist, a low credit warning prompt may be sent to the corresponding requester.
[0104] In this embodiment, by setting a scheduling blacklist, it is possible to prevent the requesting party from arbitrarily setting the service time, thereby affecting the normal scheduling of tasks according to the service time.
[0105] The present invention also provides a task scheduling system, referring to Figure 5 , the task scheduling system comprises:
[0106] A service time acquisition module 10 is used to receive an execution request for a first task, and obtain the service time of the first task and the service time of each task to be executed in the task scheduling queue;
[0107] The task sorting module 20 is used to sort the first task and each of the tasks to be executed according to the service time based on the service time of the first task and the service time of each of the tasks to be executed, so as to obtain a new task scheduling queue, and to execute the tasks in the new task scheduling queue in sequence according to the service time, wherein the tasks with smaller service time are closer to the head of the queue in the new task scheduling queue.
[0108] Optionally, the task sorting module is further used to:
[0109] Determine whether there is a second task with the same service time between the first task and the to-be-performed task;
[0110] If it exists, the second task and other tasks are sorted according to the service time, and the second task is sorted according to the order of the task request time of the second task to obtain a new task scheduling queue.
[0111] Optionally, the service time acquisition module is further used to:
[0112] Determine whether there are undequeued tasks in the task scheduling queue and whether there are tasks being executed;
[0113] If there is no unqueued task in the task scheduling queue and no task being executed, execute the first task;
[0114] If there are undequeued tasks in the task scheduling queue and / or there are tasks being executed, the following steps are performed: obtaining the service time of the first task and the service time of each task to be executed in the task scheduling queue.
[0115] Optionally, the task sorting module is further used to:
[0116] Monitoring the waiting time of each task in the new task scheduling queue;
[0117] The task whose waiting time is greater than or equal to the preset time threshold is adjusted to the head of the new task scheduling queue.
[0118] Optionally, the task sorting module is further used to:
[0119] Monitoring the waiting time of each task in the new task scheduling queue;
[0120] Determine the response ratio of each task according to the waiting time and service time of each task;
[0121] The task whose response ratio is greater than or equal to a preset response ratio threshold is adjusted to the head of the new task scheduling queue.
[0122] Optionally, the service time acquisition module is further used to:
[0123] Obtaining the service time of the first task and the remaining service time of the currently executed task;
[0124] Determining whether the service time of the first task is greater than or equal to the remaining service time of the currently executed task;
[0125] If yes, then execute the steps: obtaining the service time of the first task and the service time of each task to be executed in the task scheduling queue;
[0126] If not, suspend the execution of the currently executed task, execute the first task, sort the currently executed task and each of the tasks to be executed in the task scheduling queue according to the remaining service time of the currently executed task and the service time of each task to be executed, and obtain a new task scheduling queue.
[0127] Optionally, the task sorting module is further used to:
[0128] Obtaining the actual execution time of each task in the new task scheduling queue, and calculating the absolute value of the difference between the actual execution time and the service time of each task;
[0129] Adding the requester corresponding to the task whose absolute value is greater than or equal to the preset threshold into the task scheduling blacklist;
[0130] When the execution request for the second task from the requesting party is received again, the second task is inserted into and maintained at the end of the current task scheduling queue.
[0131] The methods executed by the above-mentioned program units can refer to the various embodiments of the task scheduling method of the present invention, which will not be described in detail here.
[0132] The present invention also provides a task scheduling device, which includes: a memory, a processor, and a task scheduling program stored in the memory and executable on the processor. The method implemented when the task scheduling program is executed by the processor can refer to the various embodiments of the task scheduling method of the present invention and will not be repeated here.
[0133] The invention also provides a computer storage medium.
[0134] The computer storage medium of the present invention stores a task scheduling program, and when the task scheduling program is executed by a processor, the steps of the task scheduling method described above are implemented.
[0135] Among them, the method implemented when the task scheduling program running on the processor is executed can refer to the various embodiments of the task scheduling method of the present invention, and will not be repeated here.
[0136] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0137] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0138] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0139] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A task scheduling method, characterized in that: The task scheduling method comprises the following steps: Receive a request for executing a first task, and obtain the service time of the first task and the service time of each task to be executed in the task scheduling queue; wherein the service time refers to the time required from the start of task execution to the completion of task execution; the service time is provided by the requesting party; Based on the service time of the first task and the service time of each of the tasks to be executed, the first task and each of the tasks to be executed are sorted according to the service time to obtain a new task scheduling queue, and the tasks in the new task scheduling queue are executed in sequence according to the service time, wherein the tasks with smaller service time are closer to the head of the queue in the new task scheduling queue; Obtaining the actual execution time of each task in the new task scheduling queue, and calculating the absolute value of the difference between the actual execution time and the service time of each task; Adding the requester corresponding to the task whose absolute value is greater than or equal to the preset threshold into the task scheduling blacklist, and sending a low credit warning prompt to the corresponding requester; When the execution request for the second task from the requesting party is received again, the second task is inserted into and maintained at the end of the current task scheduling queue.
2. The task scheduling method according to claim 1, characterized in that: The step of sorting the first task and each of the tasks to be executed according to the service time to obtain a new task scheduling queue comprises: Determine whether there is a second task with the same service time between the first task and the to-be-performed task; If it exists, the second task and other tasks are sorted according to the service time, and the second task is sorted according to the order of the task request time of the second task to obtain a new task scheduling queue.
3. The task scheduling method according to claim 1, characterized in that: After the step of receiving the execution request for the first task, the method further includes: Determine whether there are undequeued tasks in the task scheduling queue and whether there are tasks being executed; If there is no unqueued task in the task scheduling queue and no task being executed, execute the first task; If there are undequeued tasks in the task scheduling queue and / or there are tasks being executed, the following steps are performed: obtaining the service time of the first task and the service time of each task to be executed in the task scheduling queue.
4. The task scheduling method according to claim 1, characterized in that: After the step of sorting the first task and each of the tasks to be executed according to the service time to obtain a new task scheduling queue, the method further includes: Monitoring the waiting time of each task in the new task scheduling queue; The task whose waiting time is greater than or equal to the preset time threshold is adjusted to the head of the new task scheduling queue.
5. The task scheduling method according to claim 1, characterized in that: After the step of sorting the first task and each of the tasks to be executed according to the service time to obtain a new task scheduling queue, the method further includes: Monitoring the waiting time of each task in the new task scheduling queue; Determine the response ratio of each task according to the waiting time, service time and preset response ratio formula of each task; the preset response ratio formula is: R=(Tw+Ts) / Ts, where R is the response ratio of the task, Tw is the waiting time, and Ts is the service time; The task whose response ratio is greater than or equal to a preset response ratio threshold is adjusted to the head of the new task scheduling queue.
6. The task scheduling method according to claim 1, characterized in that: After the step of receiving the execution request for the first task, the method further includes: Obtaining the service time of the first task and the remaining service time of the currently executed task; Determining whether the service time of the first task is greater than or equal to the remaining service time of the currently executed task; If yes, then execute the steps: obtaining the service time of the first task and the service time of each task to be executed in the task scheduling queue; If not, suspend the execution of the currently executed task, execute the first task, sort the currently executed task and each of the tasks to be executed in the task scheduling queue according to the remaining service time of the currently executed task and the service time of each task to be executed, and obtain a new task scheduling queue.
7. A task scheduling system, characterized in that: The task scheduling system comprises: A service time acquisition module, used to receive an execution request for a first task, and obtain the service time of the first task and the service time of each task to be executed in the task scheduling queue; wherein the service time refers to the time required from the start of task execution to the completion of task execution; the service time is provided by the requesting party; A task sorting module is used to sort the first task and each of the tasks to be executed according to the service time based on the service time of the first task and the service time of each of the tasks to be executed, so as to obtain a new task scheduling queue, and execute the tasks in the new task scheduling queue in sequence according to the service time, wherein the task with the smaller service time is closer to the head of the queue in the new task scheduling queue; obtain the actual execution time of each task in the new task scheduling queue, and calculate the absolute value of the difference between the actual execution time and the service time of each task; add the requester corresponding to the task whose absolute value is greater than or equal to a preset threshold to the task scheduling blacklist, and send a low credit warning prompt to the corresponding requester; when receiving the execution request of the second task from the requester again, insert the second task and keep it at the end of the current task scheduling queue.
8. A task scheduling device, characterized in that: The task scheduling device comprises: a memory, a processor, and a task scheduling program stored in the memory and executable on the processor. When the task scheduling program is executed by the processor, the steps of the task scheduling method according to any one of claims 1 to 6 are implemented.
9. A computer storage medium, characterized in that: The computer storage medium stores a task scheduling program, and when the task scheduling program is executed by the processor, the steps of the task scheduling method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Cloud computing platform scheduling method
CN103136056A