Task scheduling method and system

By setting up queues to be executed and candidate queues and scheduling according to the task type, the problems of fairness and effectiveness of task scheduling in the prior art are solved, and the fairness of task scheduling and the full utilization of CPU resources are achieved.

CN113360254BActive Publication Date: 2025-01-10BEIJING SOGOU TECHNOLOGY DEVELOPMENT CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010150940.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-03-06
Publication Date
2025-01-10
Estimated Expiration
2040-07-09

AI Technical Summary

Technical Problem

Existing task scheduling methods are difficult to ensure the fairness and effectiveness of task scheduling, and tasks are often hungry or CPU resources are idle.

Method used

By presetting the queue to be executed and the candidate queue corresponding to each task type, adding tasks to the candidate queue according to the task type, and copying tasks in the candidate queue to the queue to be executed when the execution conditions are met, ensuring that each candidate is required There is at most one task in the queue, and the idle executor is executed in sequence according to the first-in-first-out principle.

Benefits of technology

It effectively avoids the long-tail problem of response time, ensures the fairness and effectiveness of task scheduling, and ensures the full utilization of CPU resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113360254B_ABST
    Figure CN113360254B_ABST
Patent Text Reader

Abstract

The present invention discloses a task scheduling method and system, which includes: presetting a queue to be executed and a candidate queue corresponding to each task type; after receiving a task, adding the task to the end of the candidate queue corresponding to the type according to the type of the task; when the execution condition is met, copying the task in the candidate queue to the queue to be executed, and ensuring that there is at most one task corresponding to each candidate queue in the queue to be executed; and extracting tasks from the queue to be executed as tasks to be executed in sequence according to the first-in-first-out principle by an idle execution body. By using the present invention, the fairness and effectiveness of task scheduling can be guaranteed, and CPU resources can be fully utilized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of task scheduling, and in particular to a task scheduling method and system. Background Art

[0002] In computer science and Internet applications, many scenarios require task scheduling. Existing task scheduling methods generally use simple queuing methods, assembly line methods, or priority queue methods. In multi-task scheduling applications without hierarchical differences, no matter which existing scheduling method is used, it is difficult to ensure the fairness and effectiveness of task scheduling, and task starvation or CPU resources being idle often occur. Summary of the invention

[0003] The embodiments of the present invention provide a task scheduling method and system to solve the above problems existing in the existing task scheduling solutions.

[0004] To this end, the present invention provides the following technical solutions:

[0005] A task scheduling method, the method comprising:

[0006] Pre-set the queue to be executed and the candidate queue corresponding to each task type;

[0007] Receive a task and, according to the type of the task, add the task to the end of a candidate queue corresponding to the type;

[0008] When the execution condition is met, the tasks in the candidate queue are copied to the queue to be executed, and it is ensured that there is at most one task in the queue to be executed corresponding to each candidate queue;

[0009] The idle execution body extracts tasks from the queue to be executed in sequence according to the first-in-first-out principle as tasks to be executed.

[0010] Optionally, the method further comprises:

[0011] After the idle execution body extracts the to-be-executed task from the head of the to-be-executed queue, the to-be-executed task is deleted from the candidate queue where it is located.

[0012] Optionally, when the execution condition is met, copying the tasks in the candidate queue to the to-be-executed queue includes:

[0013] After adding the task to the end of the candidate queue, if the length of the candidate queue is 1, copy the task to the end of the queue to be executed;

[0014] After deleting the to-be-executed task from the candidate queue where it is located, if the candidate queue where the to-be-executed task is located is not empty, copying the task at the head of the candidate queue where the to-be-executed task is located to the end of the to-be-executed queue.

[0015] Optionally, each task type corresponds to one or more candidate queues.

[0016] Optionally, the executable body includes any one or more of the following: a process, a thread.

[0017] A task scheduling system, the system comprising:

[0018] A setting module is used to pre-set the queue to be executed and the candidate queue corresponding to each task type, and each type corresponds to a candidate queue;

[0019] A task submission module, used for receiving a task and adding the task to the end of a candidate queue corresponding to the type of the task according to the type of the task;

[0020] A scheduling module, used for copying the tasks in the candidate queue to the queue to be executed when the execution condition is met, and ensuring that there is at most one task in the queue to be executed corresponding to each candidate queue;

[0021] The execution body is used to extract tasks from the to-be-executed queue in order according to the first-in-first-out principle when idle as to-be-executed tasks for execution.

[0022] Optionally, the scheduling device further includes:

[0023] The task maintenance module is used to delete the to-be-executed task from the candidate queue where it is located after the idle execution body extracts the to-be-executed task from the head of the to-be-executed queue.

[0024] Optionally, the scheduling module includes:

[0025] A first scheduling unit, configured to copy the task to the end of the queue to be executed after the task submission module adds the task to the end of the candidate queue if the length of the candidate queue is 1;

[0026] The second scheduling unit is used to copy the task at the head of the candidate queue where the task to be executed is located to the end of the queue to be executed after the task maintenance module deletes the task to be executed from the candidate queue where the task to be executed is located, if the candidate queue where the task to be executed is located is not empty.

[0027] Optionally, each task type corresponds to one or more candidate queues.

[0028] Optionally, the executable body includes any one or more of the following: a process, a thread.

[0029] An electronic device, comprising: one or more processors and a memory;

[0030] The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the aforementioned method.

[0031] A readable storage medium stores instructions thereon, wherein the instructions are executed to implement the above-mentioned method.

[0032] The task scheduling method and system provided by the embodiment of the present invention schedules different types of tasks based on multiple queues by setting a queue to be executed and a candidate queue corresponding to each type of task, and controls that there is at most one task corresponding to each candidate queue in the queue to be executed, so that the length of the queue to be executed is controllable, and there will not be a situation where a certain type of task is queued up and other types of tasks need to wait for it to be executed before they can be executed, thereby avoiding the long tail problem of response time and effectively ensuring the fairness and effectiveness of task scheduling. Moreover, all tasks share a set of executable bodies, so that the executable bodies can be better dynamically allocated between tasks, so that CPU resources are fully utilized. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.

[0034] Figure 1 is a flowchart of a task scheduling method according to an embodiment of the present invention;

[0035] Figure 2 is a flowchart of a task submission process in an embodiment of the present invention;

[0036] Figure 3 is a flowchart of a task execution process in an embodiment of the present invention;

[0037] Figure 4 A structural block diagram of a task scheduling system according to an embodiment of the present invention;

[0038] Figure 5 A block diagram of a device for a task scheduling method according to an exemplary embodiment;

[0039] Figure 6 A schematic diagram of the structure of a server in an embodiment of the present invention. DETAILED DESCRIPTION

[0040] In order to enable persons skilled in the art to better understand the solutions of the embodiments of the present invention, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings and implementation modes.

[0041] The task scheduling method and system provided by the embodiment of the present invention pre-sets a queue to be executed and a candidate queue corresponding to each task type. After receiving a task, it is submitted to the corresponding candidate queue according to the type of the task; when the execution condition is met, the task in the candidate queue is copied to the queue to be executed, and it is ensured that there is at most one task in the queue to be executed corresponding to each candidate queue; the idle execution body executes the tasks in the queue to be executed in sequence according to the first-in-first-out principle.

[0042] like Figure 1 FIG. 1 is a flowchart of a task scheduling method according to an embodiment of the present invention, comprising the following steps:

[0043] Step 101 , pre-set a queue to be executed and a candidate queue corresponding to each task type.

[0044] That is to say, if there are several types of tasks, several candidate queues are set. The division of task types can be set as needed, and this embodiment of the present invention does not limit this.

[0045] In actual applications, each task type can correspond to a candidate queue. Considering that in some applications, some types of tasks may have a large amount or a high priority, in this case, two or more candidate queues can be set for tasks of this type. Accordingly, after receiving a task of this type, one of the candidate queues can be selected to submit the task according to the number of tasks in the candidate queue of the corresponding type, either randomly or according to a certain algorithm.

[0046] In the embodiment of the present invention, all tasks share a queue to be executed and a group of execution bodies, and the execution bodies may be processes and / or threads.

[0047] Step 102: Receive a task and, according to the type of the task, add the task to the end of a candidate queue corresponding to the type.

[0048] Step 103, when the execution condition is met, copy the tasks in the candidate queue to the queue to be executed, and ensure that there is at most one task in the queue to be executed corresponding to each candidate queue.

[0049] In order to ensure that there is at most one task in the queue to be executed corresponding to each candidate queue, for each candidate queue, when copying the task in the candidate queue as a task to be executed to the queue to be executed, it is necessary to consider whether the execution conditions are met. In other words, the copying will be performed only when certain conditions are met, otherwise the corresponding tasks are only submitted and executed independently, that is, submitting tasks and executing tasks are two independently running processes.

[0050] Step 104 : An idle execution body extracts tasks from the queue to be executed in sequence according to the first-in-first-out principle as tasks to be executed.

[0051] It should be noted that after the idle executor extracts the to-be-executed task from the head of the to-be-executed queue, it is also necessary to delete the to-be-executed task from the candidate queue where it is located.

[0052] In the embodiment of the present invention, the scheduling of tasks in the candidate queue, i.e., the process of copying tasks from the candidate queue to the queue to be executed, needs to be determined according to the number of tasks in the candidate queue after the tasks are submitted to the candidate queue or deleted from the candidate queue. Specifically, there are the following two situations:

[0053] (1) When adding a task to the candidate queue

[0054] Specifically, after adding the task to the end of the candidate queue, if the length of the candidate queue is 1, copying the task to the end of the queue to be executed;

[0055] (2) When deleting a task from the candidate queue

[0056] Specifically, after the to-be-executed task is deleted from the candidate queue where it is located, if the candidate queue where the to-be-executed task is located is not empty, the task at the head of the candidate queue where the to-be-executed task is located is copied to the end of the to-be-executed queue.

[0057] like Figure 2 FIG. 1 is a flowchart of a task submission process according to an embodiment of the present invention, comprising the following steps:

[0058] Step 201, receiving a task.

[0059] Step 202: Add the task to the end of a candidate queue corresponding to the type of the task according to the type of the task.

[0060] Step 203 , determining whether the length of the candidate queue is 1. If yes, executing step 204 ; otherwise executing step 205 .

[0061] Step 204: copy the task to the end of the queue to be executed.

[0062] Step 205: Task submission is completed.

[0063] like Figure 3 FIG. 1 is a flowchart of a task execution process in an embodiment of the present invention, which includes the following steps:

[0064] Step 301: An idle execution body extracts a task from the head of a queue to be executed as a task to be executed.

[0065] Step 302: Delete the to-be-executed task from the candidate queue where it is located.

[0066] Step 303, determine whether the candidate queue where the task to be executed is located is empty. If yes, execute step 305; otherwise, execute step 304.

[0067] Step 304: copy the task at the head of the candidate queue where the to-be-executed task is located to the end of the to-be-executed queue.

[0068] Step 305: the execution body executes the task to be executed, and returns to an idle state after the execution is completed.

[0069] It should be noted that in order to avoid conflicts between multiple threads operating on the same task, a locking mechanism can be used to avoid conflicts between the task submission phase and the task execution phase. Specifically, a lock is set on each candidate queue and queue to be executed. The time points for locking and unlocking are as follows:

[0070] Task submission phase:

[0071] 1) After selecting the candidate queue to which the task is to be added, lock the candidate queue;

[0072] 2) After placing the task at the end of the candidate queue, if the length of the candidate queue is 1, the queue to be executed is locked; after copying the task to the end of the queue to be executed, the queue to be executed is unlocked;

[0073] 3) After the task submission is completed, the candidate queue is unlocked.

[0074] Task execution phase:

[0075] 1) The idle executor locks the queue to be executed, takes the task at the head of the queue as the task to be executed, and immediately unlocks the queue to be executed;

[0076] 2) Locking the candidate queue where the task to be executed is located;

[0077] 3) The to-be-executed task is deleted from the candidate queue. If the length of the candidate queue is greater than or equal to 1, the to-be-executed queue is locked, the head task in the candidate queue is copied to the end of the to-be-executed queue, and then the to-be-executed queue is unlocked.

[0078] 4) Unlock the candidate queue.

[0079] The task scheduling method provided by the embodiment of the present invention schedules different types of tasks based on multiple queues by setting a queue to be executed and a candidate queue corresponding to each type of task, and controls that there is at most one task corresponding to each candidate queue in the queue to be executed, so that the length of the queue to be executed is controllable, and there will not be a situation where a certain type of task is queued up and other types of tasks need to wait for it to be executed before they can be executed, thereby avoiding the long tail problem of response time and effectively ensuring the fairness and effectiveness of task scheduling. Moreover, all tasks share a set of executable bodies, so that the executable bodies can be better dynamically allocated between tasks, so that CPU resources are fully utilized.

[0080] Accordingly, an embodiment of the present invention further provides a task scheduling system, such as Figure 4 The figure shows a structural block diagram of the system.

[0081] In this embodiment, the system includes the following modules:

[0082] The setting module 401 is used to pre-set the queue to be executed and the candidate queue corresponding to each task type, and each type corresponds to a candidate queue;

[0083] A task submission module 402, for receiving a task and adding the task to the end of a candidate queue corresponding to the type of the task according to the type of the task;

[0084] The scheduling module 403 is used to copy the tasks in the candidate queue to the queue to be executed when the execution condition is met, and ensure that there is at most one task in the queue to be executed corresponding to each candidate queue;

[0085] The execution body 404 is used to extract tasks from the queue to be executed in order according to the first-in-first-out principle when idle as tasks to be executed.

[0086] Furthermore, if Figure 4 As shown, the scheduling device further includes: a task maintenance module 405, which is used to delete the to-be-executed task from the candidate queue where it is located after the idle execution body extracts the to-be-executed task from the head of the to-be-executed queue.

[0087] It should be noted that, in actual applications, each task type may correspond to one or more candidate queues; the division of task types may be set as needed, and the embodiment of the present invention does not limit this. Accordingly, in the case where a certain task type corresponds to multiple candidate queues, after the task submission module 402 receives a task of this type, it may select one of the candidate queues to submit the task according to the number of tasks in the candidate queue corresponding to the type, or randomly, or according to a certain algorithm.

[0088] In the embodiment of the present invention, all tasks share a queue to be executed and a group of execution bodies, and the execution bodies may be processes and / or threads.

[0089] In order to ensure that there is at most one task in the queue to be executed corresponding to each candidate queue, for each candidate queue, when copying the task in the candidate queue as the task to be executed to the queue to be executed, it is necessary to consider whether the execution condition is met. In the embodiment of the present invention, there are two situations for scheduling the tasks in the candidate queue, namely: when adding a task to the candidate queue, and when deleting a task from the candidate queue.

[0090] Accordingly, the scheduling module 404 may include a first scheduling unit and a second scheduling unit to respectively complete the task scheduling in the above two situations.

[0091] A first scheduling unit, configured to copy the task to the end of the queue to be executed after the task submission module 402 adds the task to the end of the candidate queue if the length of the candidate queue is 1;

[0092] The second scheduling unit is used to copy the task at the head of the candidate queue where the task to be executed is located to the end of the queue to be executed after the task maintenance module 405 deletes the task to be executed from the candidate queue where the task to be executed is located, if the candidate queue where the task to be executed is located is not empty.

[0093] In the embodiment of the present invention, the idle execution body needs to wait for the second scheduling unit to complete the above-mentioned scheduling task before executing the task. After the task is executed, it returns to the idle state.

[0094] In addition, it should be noted that the above modules are just different units divided from the perspective of function, and some modules may exist independently in different physical entities or may be integrated in the same physical entity, which is not limited in the embodiments of the present invention.

[0095] The task scheduling system provided by the embodiment of the present invention schedules different types of tasks based on multiple queues by setting a queue to be executed and a candidate queue corresponding to each type of task, and controls that there is at most one task corresponding to each candidate queue in the queue to be executed, so that the length of the queue to be executed is controllable, and there will not be a situation where a certain type of task is queued up and other types of tasks need to wait for it to be executed before they can be executed, thereby avoiding the long tail problem of response time and effectively ensuring the fairness and effectiveness of task scheduling. Moreover, all tasks share a set of executable bodies, so that the executable bodies can be better dynamically allocated between tasks, so that CPU resources are fully utilized.

[0096] Figure 5 8 is a block diagram of an apparatus 800 for a task scheduling method according to an exemplary embodiment. For example, the apparatus 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0097] Reference Figure 5 , the device 800 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output (I / O) interface 812 , a sensor component 814 , and a communication component 816 .

[0098] The processing component 802 generally controls the overall operation of the device 800, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.

[0099] The memory 804 is configured to store various categories of data to support operations on the device 800. Examples of such data include instructions for any application or method operating on the device 800, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any category of volatile or non-volatile storage devices or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0100] The power component 806 provides power to the various components of the device 800. The power component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 800.

[0101] The multimedia component 808 includes a screen that provides an output interface between the device 800 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0102] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the device 800 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.

[0103] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: home button, volume button, start button, and lock button.

[0104] The sensor assembly 814 includes one or more sensors for providing various aspects of status assessment for the device 800. For example, the sensor assembly 814 can detect the open / closed state of the device 800, the relative positioning of components, such as the display and keypad of the device 800, and the sensor assembly 814 can also detect the position change of the device 800 or a component of the device 800, the presence or absence of user contact with the device 800, the orientation or acceleration / deceleration of the device 800, and the temperature change of the device 800. The sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0105] The communication component 816 is configured to facilitate wired or wireless communication between the device 800 and other devices. The device 800 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0106] In an exemplary embodiment, the apparatus 800 may be implemented by one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.

[0107] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 804 including instructions, and the instructions can be executed by the processor 820 of the device 800 to complete the above-mentioned task scheduling method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0108] The present invention also provides a non-temporary computer-readable storage medium. When the instructions in the storage medium are executed by a processor of a mobile terminal, the mobile terminal can execute all or part of the steps in the above-mentioned method embodiment of the present invention.

[0109] Figure 6 1 is a schematic diagram of the structure of the server in an embodiment of the present invention. The server 1900 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 1922 (for example, one or more processors) and memory 1932, and one or more storage media 1930 (for example, one or more mass storage devices) storing application programs 1942 or data 1944. Among them, the memory 1932 and the storage medium 1930 can be short-term storage or permanent storage. The program stored in the storage medium 1930 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 1922 can be configured to communicate with the storage medium 1930 and execute a series of instruction operations in the storage medium 1930 on the server 1900.

[0110] The server 1900 may also include one or more power supplies 1926, one or more wired or wireless network interfaces 1950, one or more input and output interfaces 1958, one or more keyboards 1956, and / or, one or more operating systems 1941, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0111] Those skilled in the art will readily appreciate other embodiments of the invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art that are not disclosed in this disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present invention are indicated by the following claims.

[0112] It should be understood that the present invention is not limited to the exact construction that has been described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.

[0113] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A task scheduling method, characterized in that: The method comprises: Pre-set the queue to be executed and the candidate queue corresponding to each task type; Receive a task and, according to the type of the task, add the task to the end of a candidate queue corresponding to the type; When the execution condition is met, the tasks in the candidate queue are copied to the queue to be executed, and it is ensured that there is at most one task in the queue to be executed corresponding to each candidate queue; The idle execution body extracts tasks from the queue to be executed in sequence according to the first-in-first-out principle as tasks to be executed; After the idle execution body extracts the task to be executed from the head of the queue to be executed, the task to be executed is deleted from the candidate queue where it is located; When the execution condition is met, copying the tasks in the candidate queue to the to-be-executed queue includes: After adding the task to the end of the candidate queue, if the length of the candidate queue is 1, copy the task to the end of the queue to be executed; After deleting the task to be executed from the candidate queue where it is located, if the candidate queue where the task to be executed is located is not empty, copying the task at the head of the candidate queue where the task to be executed is located to the end of the queue to be executed; Each task type corresponds to a plurality of candidate queues; All tasks share one queue to be executed and a group of execution bodies, wherein the execution bodies include processes and / or threads; The queue to be executed and each candidate queue are locked, and the time points for locking and unlocking include: In the task submission stage, after selecting the candidate queue to which the task is to be added, the candidate queue is locked, and after the task is placed at the end of the candidate queue, if the length of the candidate queue is 1, the queue to be executed is locked, and after the task is copied to the end of the queue to be executed, the queue to be executed is unlocked. After the task is submitted, the candidate queue is unlocked; During the task execution phase, the idle execution body locks the queue to be executed, takes the task at the head of the queue as the task to be executed, unlocks the queue to be executed, locks the candidate queue where the task to be executed is located, deletes the task to be executed from the candidate queue, and if the length of the candidate queue is greater than or equal to 1, locks the queue to be executed, copies the queue tasks in the candidate queue to the end of the queue to be executed, unlocks the queue to be executed, and then unlocks the candidate queue.

2. A task scheduling system, characterized in that: The system comprises: A setting module, used to pre-set a queue to be executed and a candidate queue corresponding to each task type, each type corresponds to a candidate queue; each task type corresponds to a plurality of candidate queues; A task submission module, used for receiving a task and adding the task to the end of a candidate queue corresponding to the type of the task according to the type of the task; A scheduling module, used for copying the tasks in the candidate queue to the queue to be executed when the execution condition is met, and ensuring that there is at most one task in the queue to be executed corresponding to each candidate queue; An execution body, used to extract tasks from the queue to be executed in order according to the first-in-first-out principle when idle as tasks to be executed; all tasks share one queue to be executed and a group of execution bodies, and the execution bodies include processes and / or threads; A task maintenance module, configured to delete the to-be-executed task from the candidate queue where the task is located after an idle execution body extracts the to-be-executed task from the head of the to-be-executed queue; A first scheduling unit, configured to copy the task to the end of the queue to be executed after the task submission module adds the task to the end of the candidate queue if the length of the candidate queue is 1; A second scheduling unit is configured to copy the task at the head of the candidate queue where the task to be executed is located to the end of the queue to be executed after the task maintenance module deletes the task to be executed from the candidate queue where the task to be executed is located, if the candidate queue where the task to be executed is located is not empty; The locking unit is used to lock the queue to be executed and each of the candidate queues, and the time points for locking and unlocking include: In the task submission stage, after selecting the candidate queue to which the task is to be added, the candidate queue is locked, and after the task is placed at the end of the candidate queue, if the length of the candidate queue is 1, the queue to be executed is locked, and after the task is copied to the end of the queue to be executed, the queue to be executed is unlocked. After the task is submitted, the candidate queue is unlocked; During the task execution phase, the idle execution body locks the queue to be executed, takes the task at the head of the queue as the task to be executed, unlocks the queue to be executed, locks the candidate queue where the task to be executed is located, deletes the task to be executed from the candidate queue, and if the length of the candidate queue is greater than or equal to 1, locks the queue to be executed, copies the queue tasks in the candidate queue to the end of the queue to be executed, unlocks the queue to be executed, and then unlocks the candidate queue.

3. An electronic device, characterized in that: include: One or more processors, memory; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the method according to claim 1.

4. A readable storage medium having instructions stored thereon, wherein the instructions are executed to implement the method according to claim 1.

Citation Information

Patent Citations

  • Downloading task queuing method and device and electronic equipment

    CN110187957A