CN113760494B - Task scheduling method and device - Google Patents

Task scheduling method and device Download PDF

Info

Publication number
CN113760494B
CN113760494B CN202011325603.0A CN202011325603A CN113760494B CN 113760494 B CN113760494 B CN 113760494B CN 202011325603 A CN202011325603 A CN 202011325603A CN 113760494 B CN113760494 B CN 113760494B
Authority
CN
China
Prior art keywords
target
task
time
queue
wheel
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
CN202011325603.0A
Other languages
Chinese (zh)
Other versions
CN113760494A (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.)
Beijing Jingdong Zhenshi Information Technology Co Ltd
Original Assignee
Beijing Jingdong Zhenshi Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Zhenshi Information Technology Co Ltd filed Critical Beijing Jingdong Zhenshi Information Technology Co Ltd
Priority to CN202011325603.0A priority Critical patent/CN113760494B/en
Publication of CN113760494A publication Critical patent/CN113760494A/en
Application granted granted Critical
Publication of CN113760494B publication Critical patent/CN113760494B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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/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)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention discloses a task scheduling method and device, and relates to the technical field of computers. One embodiment of the method comprises the following steps: determining the task type of a target task; adding the target task into a target queue corresponding to the task type; adding the target task from the target queue to a target time slot of the time wheel; the target queue corresponds to a time wheel, and the time wheel comprises a plurality of time slots; and scheduling the target task in the time period of the target time slot. The embodiment can reduce the problems of resource waste or system blockage caused by different processing time of each task.

Description

Task scheduling method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a task scheduling method and apparatus.
Background
The system typically assigns each task an equal length of run time period based on a fairness policy so that each task can run equally. In actual business, however, the required run time for each task is often different. If the duration of the operation time period is set to be shorter, more task processing failures can be caused, and the CPU efficiency is reduced; if the duration of the operation period is set longer, system resources may be exhausted to cause system blocking.
Disclosure of Invention
In view of the above, embodiments of the present invention provide a task scheduling method and apparatus, which can reduce the problem of resource waste or system blockage caused by different processing times of each task.
In a first aspect, an embodiment of the present invention provides a task scheduling method, including:
determining the task type of a target task;
adding the target task into a target queue corresponding to the task type;
adding the target task from the target queue to a target time slot of the time wheel; the target queue corresponds to a time wheel, and the time wheel comprises a plurality of time slots;
and scheduling the target task in the time period of the target time slot.
Alternatively, the process may be carried out in a single-stage,
adding the target task to a target queue corresponding to the task type comprises:
according to the corresponding relation between the task types and the queues, searching whether a target queue corresponding to the task type of the target task exists in a plurality of preset queues, and if so, adding the target task into the target queue; otherwise, the target task is added into a preset initial queue.
Alternatively, the process may be carried out in a single-stage,
adding the target task from the target queue to a target time slot of the time wheel, comprising:
taking out a plurality of tasks from the target queue; among the several tasks include: a target task and a plurality of other tasks;
for each task: determining a time slot of a time wheel corresponding to the task; adding the task into the corresponding time slot; the time slot corresponding to the target task is a target time slot;
scheduling the target task within a time period of the target time slot, comprising:
for each task: the tasks are scheduled during the time period of their corresponding time slots.
Alternatively, the process may be carried out in a single-stage,
before adding the target task from the target queue to the target time slot of the time wheel, further comprising:
determining whether a time wheel exists, and if not, creating and starting the time wheel according to a preset fission rule.
Alternatively, the process may be carried out in a single-stage,
after scheduling the target task within the time period of the target time slot, further comprising:
determining whether the target task is overtime, if so, adding the target task into a next-stage queue of the target queue; the time slot time length of the time wheel corresponding to the next-stage queue is longer than that of the time wheel corresponding to the target queue.
Alternatively, the process may be carried out in a single-stage,
after adding the target task to the next-level queue of the target queue, further comprising:
acquiring load parameters of a server;
determining whether the load parameter meets a preset fission condition, if so, creating a next time wheel of the time wheel according to a preset fission rule; adding the target task into a time slot of a next-stage time wheel from a next-stage queue; and scheduling the target task in the time slot of the next stage time wheel.
Optionally, the method further comprises:
and if the load parameter does not meet the fission condition, acquiring the load parameter of the server after the preset time period.
Optionally, the method further comprises:
and if the target task does not execute overtime, updating the corresponding relation between the task type and the queue according to the corresponding relation between the task type and the next-stage queue.
Alternatively, the process may be carried out in a single-stage,
after scheduling the target task within the time period of the target time slot, further comprising:
determining the execution time of a target task;
determining an optimization queue corresponding to the task type according to the execution time;
if the optimized queue is different from the target queue, updating the corresponding relation between the task type and the queue according to the corresponding relation between the task type and the optimized queue.
In a second aspect, an embodiment of the present invention provides a task scheduling device, including:
the type determining module is configured to determine the task type of the target task;
a queue adding module configured to add a target task to a target queue corresponding to a task type thereof;
a time wheel adding module configured to add a target task from the target queue into a target time slot of the time wheel; the target queue corresponds to a time wheel, and the time wheel comprises a plurality of time slots;
and the task scheduling module is configured to schedule the target task in the time period of the target time slot.
In a third aspect, an embodiment of the present invention provides an electronic device, including:
one or more processors;
storage means for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the methods of any of the embodiments described above.
In a fourth aspect, embodiments of the present invention provide a computer readable medium having a computer program stored thereon, which when executed by a processor, implements a method of any of the above embodiments.
One embodiment of the above invention has the following advantages or benefits: the system is provided with a multi-stage queue and a multi-stage time wheel corresponding to the multi-stage queue. The running time length of the time slots of each stage of time wheel is different. The task type of a task is related to the length of time that the task needs to run. According to the task types of the tasks, the tasks with different task types are added into the time wheel with different operation time lengths to be scheduled, so that the resource waste or system blockage caused by different operation time lengths required by the tasks can be reduced.
Further effects of the above-described non-conventional alternatives are described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic illustration of a task scheduling method according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of a flow of another task scheduling method provided by an embodiment of the present invention;
FIG. 3 is a schematic illustration of a flow of yet another task scheduling method provided by an embodiment of the present invention;
FIG. 4 is a schematic diagram of a task scheduler according to an embodiment of the present invention;
FIG. 5 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
fig. 6 is a schematic diagram of a computer system suitable for use in implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
The embodiment of the invention provides a task scheduling method, as shown in fig. 1, comprising the following steps:
step 101: and determining the task type of the target task.
Tasks in embodiments of the present invention are a series of computer instructions capable of accomplishing a certain purpose. A task may be a process, a thread, or a group of threads. Tasks correspond to a series of computer operations such as input operations, download operations, encoding/decoding, face recognition, image segmentation, etc.
Tasks may be categorized according to the run time of the target task, the purpose of execution, the resources required, the number of processes involved, etc. The operation time length required by each task belonging to the same task type is in the same time length range.
Step 102: the target task is added to the target queue corresponding to its task type.
The system is provided with a multi-stage queue and a multi-stage time wheel corresponding to the multi-stage queue. The queues are used to store tasks to be scheduled. The task types and the queues can be in one-to-one correspondence, or in a many-to-one relationship, i.e. the tasks of the same task type can only be added into the same queue, and the same queue can store the tasks of a plurality of task types. The running time of each task added to the same queue is the same or the difference is smaller than a preset threshold value.
The task information added to the target queue may include: task type, task message, task processor, etc. The target task enters the corresponding queue, and the time which needs to elapse before the target task starts to execute can be calculated by the following formula: the order of the target tasks in the target queue x the time interval of the time wheel corresponding to the target queue.
Step 103: adding the target task from the target queue to a target time slot of the time wheel; wherein the target queue corresponds to a time wheel, the time wheel comprising a number of time slots.
The time period allowed by the task to run can be allocated to each task through a time wheel, and the tasks are scheduled in batches. The time wheel may include a number of time slots therein. A number of tasks to be scheduled may be stored in each time slot. The duration of the time period corresponding to each time slot in the same time wheel is the same. The time duration of the allowed time period allocated to each task added to the same time wheel is the same.
Multiple time wheels can be arranged in the system, and each time wheel corresponds to different time period duration. For example: an initial time wheel is used for processing tasks with timeout time of 0 to 1 second. A second stage time wheel for processing tasks with timeout time between 1 second and 3 seconds. And a third stage time wheel for processing tasks with timeout time ranging from 3 seconds to 5 seconds. A fourth level time wheel, processing tasks with timeout time between 5 seconds and 8 seconds, etc. It can be seen that the higher the level of the time wheel, the longer the time wheel is allocated to the running time of the task.
The queues and the time wheel are in one-to-one correspondence. Tasks in the same queue may be added to the same time wheel. The same time wheel can only accept tasks from the same queue. I.e. tasks in the primary queue can only be added to the initial round. Tasks in the primary queue can only be added to the primary time wheel.
In addition, since tasks of the same task type can only be added into the same queue, tasks of the same task type can only be scheduled and run by the same rotating wheel. Adding the task to be processed into a time slot of a time wheel, wherein the tasks added into the time slot all have corresponding execution wheel numbers, and the execution wheel numbers = delay execution time/(the wheel numbers of the time wheel times the time interval of the time wheel). The delay execution time is the time that the task in the slot needs to wait.
For example, the delay execution time of a task is 20 seconds, the number of wheels is 5, that is, the wheels have 5 slots, and the duration of the time slot is 2 seconds, then the number of execution wheels of the task is: 20/(5*2) =2 (circles).
Step 104: and scheduling the target task in the time period of the target time slot.
The duration of the time period of the target time slot is the time interval of the time wheel. The running time length of the time slots of each stage of time wheel is different. The task type can be allocated to the task according to the time length required by the task operation, and the task is added into time wheels with different operation time lengths to be scheduled according to the task type. Therefore, the method of the embodiment of the invention can solve a plurality of problems caused by the time period of the equal duration allocated to each task.
Individual longer running tasks may be added to longer time-spaced time-wheels for running. Therefore, the method of the embodiment of the invention can also effectively solve the problem that the processing speed of other tasks is dragged due to overlong running time of the individual tasks.
In one embodiment of the invention, adding a target task to a target queue corresponding to its task type includes:
according to the corresponding relation between the task types and the queues, searching whether a target queue corresponding to the task type of the target task exists in a plurality of preset queues, and if so, adding the target task into the target queue; otherwise, the target task is added into a preset initial queue.
And if the target queue corresponding to the task type is not found, adding the target task into the initial queue. The initial queue corresponds to an initial time wheel. Compared with other time wheels, the time interval of the initial time wheel is usually set to be minimum, and under the condition that the time wheel with the minimum time interval is uncertain, the target task is firstly scheduled by the time wheel with the minimum time interval, if the target task is overtime, the target task is scheduled by the time wheel with the high level, and the consumption of system resources can be reduced.
In one embodiment of the invention, adding a target task from a target queue to a target time slot of a time wheel includes:
taking out a plurality of tasks from the target queue; among the several tasks include: a target task and a plurality of other tasks;
for each task: determining a time slot of a time wheel corresponding to the task; adding the task into the corresponding time slot; the time slot corresponding to the target task is a target time slot;
scheduling the target task within a time period of the target time slot, comprising:
for each task: the tasks are scheduled during the time period of their corresponding time slots.
And taking out a plurality of tasks from the target queue, determining the time slot corresponding to each task, adding each task into the corresponding time slot, and sequentially scheduling each target task in the time period of the target time slot. The embodiment of the invention provides a method for batch scheduling of tasks based on time wheels, which is simple and easy to implement and has strong operability.
In one embodiment of the present invention, before adding the target task from the target queue to the target time slot of the time wheel, further comprising:
determining whether a time wheel exists, and if not, creating and starting the time wheel according to a preset fission rule.
The fission rules are used to create a time wheel corresponding to the target queue. The fission rules may include configuration information for each level of time wheel. For example: an initial time wheel is used for processing tasks with timeout time of 0 to 1 second. A second stage time wheel for processing tasks with timeout time between 1 second and 3 seconds. And a third stage time wheel for processing tasks with timeout time ranging from 3 seconds to 5 seconds. A fourth level time wheel, processing tasks with timeout time between 5 seconds and 8 seconds, etc. If the current target queue is a primary queue, the initial time wheel should be created according to the configuration information of the initial time wheel. If the current target queue is a third level queue, a third level time wheel should be created according to configuration information of the third level time wheel.
The embodiment of the invention provides a task scheduling method, as shown in fig. 2, comprising the following steps:
step 201: and determining the task type of the target task.
Step 202: the target task is added to the target queue corresponding to its task type.
Step 203: adding the target task from the target queue to a target time slot of the time wheel; wherein the target queue corresponds to a time wheel, the time wheel comprising a number of time slots.
Step 204: and scheduling the target task in the time period of the target time slot.
Step 205: it is determined whether the target task is executing over time.
If so, the following step 206 is performed; otherwise, the target task is already running and can be directly exited.
Step 206: adding the target task into a next-stage queue of the target queue; the time slot time length of the time wheel corresponding to the next-stage queue is longer than that of the time wheel corresponding to the target queue.
Since the target task runs out in the target time wheel, the target task needs to be added to the next time wheel with a longer time interval to run. For example: if the target task runs out in the initial time wheel, the target task needs to be added to the second-stage time wheel. If the target task runs out in the second level time wheel, it is necessary to add the target task to the third level time wheel, and so on.
Step 207: and acquiring the load parameters of the server, and determining whether the load parameters meet preset fission conditions.
The load parameters may include CPU usage of the server, memory usage of the server, and the like. Because of the creation and starting of the time wheel, system resources are required to be consumed, and fission conditions can be set according to the system load condition and specific requirements. The time wheel is created and started only if the fission condition is met. The fission condition may be set according to CPU usage of the server, memory usage of the server, and the like. For example: it may be provided that if the server CPU usage and/or the server memory usage does not exceed 80%, a time wheel may be created and started. If the server CPU usage and/or server memory usage exceeds 80%, the creation and starting of the time wheel is stopped. By setting the fission conditions, the server downtime can be prevented, so that the system can safely and stably run.
If the loading parameter satisfies the fission condition, the following step 208 is performed; if the loading parameters do not meet the fission conditions, step 207 is re-executed after a preset period of time, so that the system executes the following step 208 only if the fission conditions are met, to ensure safe and smooth operation of the entire system.
Step 208: creating a next-stage time wheel of the time wheel according to a preset fission rule; adding the target task into a time slot of a next-stage time wheel from a next-stage queue; and scheduling the target task in the time slot of the next stage time wheel.
The target time wheel corresponds to a target queue. And under the condition that the operation of the target task in the target time wheel is overtime, adding the target task into a next stage time wheel for scheduling, wherein the time interval of the next stage time wheel is larger than that of the target time wheel so as to enable the target task to normally operate.
Step 209: it is determined whether the target task is executing over time.
And judging whether the target task is overtime. If the target task is overtime, the target task needs to be added into the next time wheel with longer time interval, and the steps 206-209 are re-executed until the target task is finished; otherwise, the target task is completely executed.
Step 210: and if the target task does not execute overtime, updating the corresponding relation between the task type and the queue according to the corresponding relation between the task type and the next-stage queue.
The target task does not execute overtime, which indicates that the target task has successfully executed, and the corresponding relation between the task type of the target task and the next-stage queue can be saved. The subsequent tasks of the same target type can be directly added into the corresponding time wheel to operate according to the corresponding relation, so that useless rotating wheel execution scheduling is reduced, and further resources and task operation time required by task scheduling are reduced.
According to the method provided by the embodiment of the invention, under the condition that the operation of the target task is overtime, the target task is gradually added into different time wheels from low to high until the target task is operated. Because the time interval of the time wheel is lengthened step by step from low to high, the method of the embodiment of the invention can more accurately determine the target queue corresponding to the target task and the target time wheel, and schedule the target task at more reasonable time intervals.
The method of the embodiment of the invention can automatically adjust the time required by the task or the message according to the requirement, treat the task or the message with different processing capacities differently, greatly improve the processing speed of the task or the message and solve the problem of setting the processing time of the task or the message.
The embodiment of the invention provides a task scheduling method, as shown in fig. 3, comprising the following steps:
step 301: and determining the task type of the target task.
Step 302: the target task is added to the target queue corresponding to its task type.
Step 303: adding the target task from the target queue to a target time slot of the time wheel; wherein the target queue corresponds to a time wheel, the time wheel comprising a number of time slots.
Step 304: and scheduling the target task in the time period of the target time slot.
Step 305: the execution time of the target task is determined.
Step 306: and determining an optimized queue corresponding to the task type according to the execution time.
The optimized queue is a queue corresponding to execution time. For example, a four-stage time wheel is provided in the system, including: an initial time wheel is used for processing tasks with timeout time of 0 to 1 second. A second stage time wheel for processing tasks with timeout time between 1 second and 3 seconds. And a third stage time wheel for processing tasks with timeout time ranging from 3 seconds to 5 seconds. A fourth stage time wheel for processing tasks with timeout time between 5 seconds and 8 seconds. If the execution time of the target task is 2 seconds, the optimized queue is a second-level queue. If the execution time is 6 seconds, the optimized queue is the fourth-level queue.
Step 307: if the optimized queue is different from the target queue, updating the corresponding relation between the task type and the queue according to the corresponding relation between the task type and the optimized queue.
In the embodiment of the invention, the execution time of the task type is recorded, so that the processing time of the target task is prevented from being shortened due to the fact that the task processing flow is changed from complex to simple or the configuration of a server is changed, and the processing time of the target task is required to be processed by a time wheel with less time, wherein the specific flow comprises the following steps: the execution time of the recorded task type is monitored, and whether the execution time is within a time interval regularly configured by the target time wheel is detected.
And if the execution time is not in the time interval regularly configured by the target time wheel, changing the corresponding relation between the task type and the queue. For example: when the task of a specific task type is successfully executed for the first time, the execution time is between 3 seconds and 5 seconds, and the corresponding time round series is the third stage. In the later stage, due to the fact that a system server is upgraded or codes are optimized, the execution time is shortened to be between 1 second and 3 seconds, and a target queue corresponding to the task is changed into a second-level queue. Thus, when this type of newly added task is subsequently rescheduled, the system will schedule the newly added task to be executed in a more reasonable time round.
As shown in fig. 4, an embodiment of the present invention provides a task scheduling device, including:
a type determining module 401 configured to determine a task type of the target task;
a queue adding module 402 configured to add a target task to a target queue corresponding to its task type;
a time wheel adding module 403 configured to add the target task from the target queue to a target time slot of the time wheel; the target queue corresponds to a time wheel, and the time wheel comprises a plurality of time slots;
the task scheduling module 404 is configured to schedule the target task within a time period of the target time slot.
In one embodiment of the present invention, the queue adding module 402 is configured to search whether a target queue corresponding to a task type of a target task exists in a plurality of preset queues according to a corresponding relationship between the task type and the queues, and if so, add the target task to the target queue; otherwise, the target task is added into a preset initial queue.
In one embodiment of the present invention, the time wheel adding module 403 is configured to take out a number of tasks from the target queue; among the several tasks include: a target task and a plurality of other tasks;
for each task: determining a time slot of a time wheel corresponding to the task; adding the task into the corresponding time slot; the time slot corresponding to the target task is a target time slot;
scheduling the target task within a time period of the target time slot, comprising:
for each task: the tasks are scheduled during the time period of their corresponding time slots.
In one embodiment of the present invention, the time wheel adding module 403 is configured to determine whether a time wheel is present, and if not, create and initiate a time wheel according to a preset fission rule.
In one embodiment of the present invention, the task scheduling module 404 is configured to determine whether the target task performs a timeout, and if so, add the target task to a next-level queue of the target queue; the time slot time length of the time wheel corresponding to the next-stage queue is longer than that of the time wheel corresponding to the target queue.
In one embodiment of the present invention, the time wheel adding module 403 is configured to obtain a load parameter of a server where the time wheel adding module is located;
determining whether the load parameter meets a preset fission condition, if so, creating a next time wheel of the time wheel according to a preset fission rule; adding the target task into a time slot of a next-stage time wheel from a next-stage queue; and scheduling the target task in the time slot of the next stage time wheel.
In one embodiment of the present invention, the time wheel adding module 403 is configured to perform obtaining the load parameter of the server after the preset period if the load parameter does not meet the fission condition.
In one embodiment of the present invention, the task scheduling module 404 is configured to update the correspondence between the task type and the queue according to the correspondence between the task type and the next-stage queue if the target task does not execute the timeout.
In one embodiment of the present invention, the task scheduling module 404 is configured to determine an execution time of the target task;
determining an optimization queue corresponding to the task type according to the execution time;
if the optimized queue is different from the target queue, updating the corresponding relation between the task type and the queue according to the corresponding relation between the task type and the optimized queue.
The embodiment of the invention provides electronic equipment, which comprises:
one or more processors;
storage means for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the methods of any of the embodiments described above.
Fig. 5 illustrates an exemplary system architecture 500 to which the abnormal behavior recognition method or apparatus of the present invention may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, a network 504, and servers 503, 505. The network 504 serves as a medium for providing communication links between the terminal devices 501, 502, the server 503, and the server 505. The network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A plurality of time wheels with different time intervals may be provided in the terminal devices 501, 502 and the server 503 for scheduling tasks of different task types. The server 505 adds the target task to a target queue corresponding to its task type; and then respectively distributing different tasks from the target queues to the time wheels set in the different terminal devices 501 and 502 and the server 503, so as to schedule the tasks of different task types by the time wheels of different time intervals.
It should be noted that different time wheels may be set according to the configurations of the terminal devices 501, 502 and the server 503. The time wheel with larger time interval and higher number of stages can be arranged on the terminal equipment or the server with higher configuration. The time wheel with smaller time interval and lower progression is arranged on the terminal equipment or the server with lower configuration.
It should be noted that, the task scheduling method provided in the embodiment of the present invention is generally executed by the server 505, and accordingly, the task scheduling device is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks and servers in fig. 5 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 6, there is illustrated a schematic diagram of a computer system 600 suitable for use in implementing an embodiment of the present invention. The terminal device shown in fig. 6 is only an example, and should not impose any limitation on the functions and the scope of use of the embodiment of the present invention.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other through a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, mouse, etc.; an output portion 607 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The drive 610 is also connected to the I/O interface 605 as needed. Removable media 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is installed as needed on drive 610 so that a computer program read therefrom is installed as needed into storage section 608.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication portion 609, and/or installed from the removable medium 611. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 601.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules involved in the embodiments of the present invention may be implemented in software or in hardware. The described modules may also be provided in a processor, for example, as: a processor includes a sending module, an obtaining module, a determining module, and a first processing module. The names of these modules do not in some cases limit the module itself, and for example, the transmitting module may also be described as "a module that transmits a picture acquisition request to a connected server".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include:
determining the task type of a target task;
adding the target task into a target queue corresponding to the task type;
adding the target task from the target queue to a target time slot of the time wheel; the target queue corresponds to a time wheel, and the time wheel comprises a plurality of time slots;
and scheduling the target task in the time period of the target time slot.
According to the technical scheme of the embodiment of the invention, a plurality of multi-level time wheels with different operation time lengths are arranged, task types are allocated to the tasks according to the time lengths required by the task operation, and the tasks are added into the time wheels with different operation time lengths for scheduling according to the task types, so that the resource waste or system blockage caused by different operation time lengths required by each task is reduced.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (10)

1. A method for task scheduling, comprising:
determining the task type of a target task; the operation time length required by each task belonging to the same task type is in the same time length range;
adding the target task into a target queue corresponding to the task type;
adding the target task to a target time slot of a time wheel by the target queue; wherein the target queue corresponds to the time wheel, the time wheel comprising a plurality of time slots;
scheduling the target task within a time period of the target time slot;
determining whether the target task is overtime, if so, adding the target task into a next-stage queue of the target queue; the time slot time length of the time wheel corresponding to the next-stage queue is longer than the time slot time length of the time wheel corresponding to the target queue;
acquiring load parameters of a server;
determining whether the load parameter meets a preset fission condition, if so, creating a next time wheel of the time wheel according to the preset fission rule; adding the target task into a time slot of the next-stage time wheel by the next-stage queue; and scheduling the target task in the time slot of the next stage time wheel.
2. A method according to claim 1, characterized in that,
the adding the target task to the target queue corresponding to the task type comprises the following steps:
according to the corresponding relation between the task types and the queues, searching whether the target queues corresponding to the task types of the target tasks exist in a plurality of preset queues, and if so, adding the target tasks into the target queues; otherwise, adding the target task into a preset initial queue.
3. A method according to claim 1, characterized in that,
the adding the target task to the target time slot of the time wheel by the target queue comprises the following steps:
fetching a number of tasks from the target queue; wherein the number of tasks includes: the target task and a plurality of other tasks;
for each of the tasks: determining a time slot of the time wheel corresponding to the task; adding the task to its corresponding time slot; the time slot corresponding to the target task is the target time slot;
the scheduling the target task within the time period of the target time slot includes:
for each of the tasks: the task is scheduled during the time period of its corresponding time slot.
4. A method according to claim 1, characterized in that,
before the target task is added to the target time slot of the time wheel by the target queue, the method further comprises:
determining whether a time wheel exists, and if not, creating and starting the time wheel according to a preset fission rule.
5. The method according to claim 1, further comprising:
and if the load parameter does not meet the fission condition, executing the acquisition of the load parameter of the server after the preset duration.
6. The method according to claim 1, further comprising:
and if the target task does not execute overtime, updating the corresponding relation between the task type and the next-stage queue according to the corresponding relation between the task type and the next-stage queue.
7. A method according to claim 1, characterized in that,
after the target task is scheduled in the time period of the target time slot, the method further comprises:
determining the execution time of the target task;
determining an optimized queue corresponding to the task type according to the execution time;
and if the optimized queue is different from the target queue, updating the corresponding relation between the task type and the queue according to the corresponding relation between the task type and the optimized queue.
8. A task scheduling device, comprising:
the type determining module is configured to determine the task type of the target task; the operation time length required by each task belonging to the same task type is in the same time length range;
a queue adding module configured to add the target task to a target queue corresponding to a task type thereof;
a time wheel adding module configured to add the target task from the target queue to a target time slot of a time wheel; wherein the target queue corresponds to the time wheel, the time wheel comprising a plurality of time slots;
a task scheduling module configured to schedule the target task within a time period of the target time slot; determining whether the target task is overtime, if so, adding the target task into a next-stage queue of the target queue; the time slot time length of the time wheel corresponding to the next-stage queue is longer than the time slot time length of the time wheel corresponding to the target queue; acquiring load parameters of a server; determining whether the load parameter meets a preset fission condition, if so, creating a next time wheel of the time wheel according to the preset fission rule; adding the target task into a time slot of the next-stage time wheel by the next-stage queue; and scheduling the target task in the time slot of the next stage time wheel.
9. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs,
when executed by one or more processors, causes the one or more processors to implement the method of any of claims 1-7.
10. A computer readable medium on which a computer program is stored, characterized in that the program, when executed by a processor, implements the method according to any one of claims 1-7.
CN202011325603.0A 2020-11-23 2020-11-23 Task scheduling method and device Active CN113760494B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011325603.0A CN113760494B (en) 2020-11-23 2020-11-23 Task scheduling method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011325603.0A CN113760494B (en) 2020-11-23 2020-11-23 Task scheduling method and device

Publications (2)

Publication Number Publication Date
CN113760494A CN113760494A (en) 2021-12-07
CN113760494B true CN113760494B (en) 2023-09-26

Family

ID=78786086

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011325603.0A Active CN113760494B (en) 2020-11-23 2020-11-23 Task scheduling method and device

Country Status (1)

Country Link
CN (1) CN113760494B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116149867A (en) * 2023-04-12 2023-05-23 阿里巴巴(中国)有限公司 Resource scheduling method and equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102043667A (en) * 2010-11-25 2011-05-04 深圳市科陆电子科技股份有限公司 Task scheduling method for embedded operating system
CN104035818A (en) * 2013-03-04 2014-09-10 腾讯科技(深圳)有限公司 Multiple-task scheduling method and device
CN107766129A (en) * 2016-08-17 2018-03-06 北京金山云网络技术有限公司 A kind of task processing method, apparatus and system
CN110119323A (en) * 2019-05-13 2019-08-13 重庆八戒电子商务有限公司 It is a kind of to take turns the method and system for executing delay queue based on the time
CN110196766A (en) * 2019-05-31 2019-09-03 中车青岛四方机车车辆股份有限公司 Task schedule and processing method and processing device, storage medium and processor

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8887163B2 (en) * 2010-06-25 2014-11-11 Ebay Inc. Task scheduling based on dependencies and resources
US20190102223A1 (en) * 2017-09-29 2019-04-04 Niall Power System, Apparatus And Method For Real-Time Activated Scheduling In A Queue Management Device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102043667A (en) * 2010-11-25 2011-05-04 深圳市科陆电子科技股份有限公司 Task scheduling method for embedded operating system
CN104035818A (en) * 2013-03-04 2014-09-10 腾讯科技(深圳)有限公司 Multiple-task scheduling method and device
CN107766129A (en) * 2016-08-17 2018-03-06 北京金山云网络技术有限公司 A kind of task processing method, apparatus and system
CN110119323A (en) * 2019-05-13 2019-08-13 重庆八戒电子商务有限公司 It is a kind of to take turns the method and system for executing delay queue based on the time
CN110196766A (en) * 2019-05-31 2019-09-03 中车青岛四方机车车辆股份有限公司 Task schedule and processing method and processing device, storage medium and processor

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Vx Works下基于多任务调度的分析和研究;李慧, 李涛, 杨占华, 万玮;微机发展(06);32-34 *
时间轮算法(TimingWheel)是如何实现的;luzhiyun;博客园;1-9 *

Also Published As

Publication number Publication date
CN113760494A (en) 2021-12-07

Similar Documents

Publication Publication Date Title
CN108182111B (en) Task scheduling system, method and device
CN113535367B (en) Task scheduling method and related device
CN109992403B (en) Optimization method and device for multi-tenant resource scheduling, terminal equipment and storage medium
CN107832143B (en) Method and device for processing physical machine resources
US11311722B2 (en) Cross-platform workload processing
US10514949B1 (en) Efficient data processing in a serverless environment
CN112000457A (en) Method, apparatus and computer program product for managing tasks in a processing system
CN106020984B (en) Method and device for creating process in electronic equipment
CN113760494B (en) Task scheduling method and device
CN110008187B (en) File transmission scheduling method, device, equipment and computer readable storage medium
CN110413210B (en) Method, apparatus and computer program product for processing data
CN114490048A (en) Task execution method and device, electronic equipment and computer storage medium
CN112559179A (en) Job processing method and device
CN112486638A (en) Method, apparatus, device and storage medium for executing processing task
CN114327918B (en) Method and device for adjusting resource amount, electronic equipment and storage medium
US9626226B2 (en) Cross-platform workload processing
CN115934291A (en) Task execution method and device, electronic equipment and storage medium
CN113595887B (en) Flow control method and device in mail system
CN115525411A (en) Method, device, electronic equipment and computer readable medium for processing service request
CN115562859A (en) Data processing method and device, electronic equipment and computer storage medium
CN114595047A (en) Batch task processing method and device
CN114064403A (en) Task delay analysis processing method and device
CN114926045A (en) Operation management method and device
CN114579191A (en) Instruction transmitting method and device, electronic equipment and storage medium
JP2008225641A (en) Computer system, interrupt control method and program

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