CN118277063A - Task scheduling method, system, electronic device and storage medium - Google Patents
Task scheduling method, system, electronic device and storage medium Download PDFInfo
- Publication number
- CN118277063A CN118277063A CN202410623312.1A CN202410623312A CN118277063A CN 118277063 A CN118277063 A CN 118277063A CN 202410623312 A CN202410623312 A CN 202410623312A CN 118277063 A CN118277063 A CN 118277063A
- Authority
- CN
- China
- Prior art keywords
- task
- thread
- channel
- threads
- target task
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4843—Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
- G06F9/4881—Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
- G06F9/5038—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
The disclosure provides a task scheduling method, a task scheduling system, electronic equipment and a storage medium, and relates to the technical field of task scheduling. The task scheduling method disclosed by the invention comprises the following steps: acquiring execution requests of a plurality of target task threads of a target task; respectively judging whether each target task thread is executed or not according to a first preset condition; and respectively judging whether other task threads are executed after the execution of each target task thread is finished according to a second preset condition. According to the technical scheme, the multiple target task threads of the same target task can be executed simultaneously, so that the multiple target task threads do not need to wait in a queuing way one by one, and the execution efficiency of the target task is greatly improved; by setting the first preset condition and the second preset condition, execution of each task thread can be reasonably scheduled. Therefore, each target task thread of the target task and each task thread of other tasks can be timely and efficiently scheduled.
Description
Technical Field
The disclosure relates to the technical field of task scheduling, and in particular relates to a task scheduling method, a task scheduling system, electronic equipment and a storage medium.
Background
In the existing task scheduling method, the highest priority mode is generally adopted for operation, namely, all tasks have different priorities, and if a task with a higher priority occurs in the process of executing the task, the task with the higher priority is preempted to execute. In general, in such a scheduling method, since different tasks adopt the same stack, the tasks are serial, the former task can be executed after the former task is executed, and the execution efficiency of the task is low.
Disclosure of Invention
The disclosure provides a task scheduling method, a task scheduling system, electronic equipment and a storage medium, which are used for solving the technical problem that task execution efficiency is low due to the fact that a task scheduling method adopts task serial and only one task scheduler is adopted in the prior art.
The present disclosure provides this summary section to introduce concepts in a simplified form that are further described below in the detailed description section. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
In order to solve the above technical problems, an embodiment of the present disclosure provides a task scheduling method, which adopts the following technical solutions, including:
Acquiring execution requests of a plurality of target task threads of a target task;
respectively judging whether each target task thread is executed or not according to a first preset condition;
And respectively judging whether other task threads are executed after the execution of each target task thread is finished according to a second preset condition.
In order to solve the above technical problems, an embodiment of the present disclosure further provides a task scheduling system, which adopts the following technical solutions, including:
the task schedulers can run simultaneously and are used for executing each target task thread of the target task and each task thread of other tasks;
the task scheduler includes:
the first scheduling unit is used for judging whether the target task thread is executed or not according to a first preset condition;
and the second scheduling unit is used for respectively judging whether other task threads are executed after the execution of each target task thread is finished according to a second preset condition.
In order to solve the above technical problems, an embodiment of the present disclosure further provides an electronic device, which adopts the following technical scheme, including: a memory and a processor, said memory having stored therein a computer program, said processor implementing the method as described above when executing said computer program.
In order to solve the above technical problems, an embodiment of the present disclosure further provides a computer readable storage medium, which adopts the following technical solutions, including: the computer readable storage medium has stored thereon a computer program which, when executed by a processor, implements a method as described above.
The positive progress effect of the present disclosure:
according to the technical scheme, the multiple target task threads of the same target task can be executed simultaneously, so that the multiple target task threads do not need to wait in a queuing way one by one, and the execution efficiency of the target task is greatly improved; by setting the first preset condition, the execution of each target task thread can be reasonably scheduled; by setting the second preset condition, execution of other task threads can be reasonably scheduled. Therefore, each target task thread of the target task and each task thread of other tasks can be timely and efficiently scheduled.
Drawings
FIG. 1 is a flow chart of a task scheduling method according to an embodiment of the present disclosure;
fig. 2 is a flowchart of step S102 of a task scheduling method according to an embodiment of the present disclosure;
fig. 3 is a flowchart of a task scheduling method according to an embodiment of the present disclosure in the case of no in step S202;
FIG. 4 is a schematic diagram of a channel queue pool of a task scheduling method according to an embodiment of the disclosure;
fig. 5 is a flowchart of step S103 of a task scheduling method according to an embodiment of the present disclosure;
Fig. 6 is a flowchart of step S402 of a task scheduling method according to an embodiment of the present disclosure;
FIG. 7 is a flowchart of a task scheduling method according to an embodiment of the present disclosure;
FIG. 8 is a flow chart of a task scheduling method according to an embodiment of the present disclosure;
FIG. 9 is a schematic diagram of a task scheduling system according to an embodiment of the present disclosure;
fig. 10 is a schematic diagram of an electronic device according to an embodiment of the disclosure.
The above and other features, advantages, and aspects of embodiments of the present disclosure will become more apparent by reference to the following detailed description when taken in conjunction with the accompanying drawings. The same or similar reference numbers will be used throughout the drawings to refer to the same or like elements. It should be understood that the figures are schematic and that elements and components are not necessarily drawn to scale.
Detailed Description
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this disclosure belongs; the terminology used in the description of the applications herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure; the terms "comprising" and "having" and any variations thereof in the description and claims of the present disclosure and in the description of the figures above are intended to cover a non-exclusive inclusion. The terms first, second and the like in the description and in the claims or in the above-described figures, are used for distinguishing between different objects and not necessarily for describing a sequential or chronological order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the present disclosure. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments.
In order to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
The first aspect of the embodiments of the present disclosure is described below: a task scheduling method.
Fig. 1 is a flowchart of a task scheduling method provided in an embodiment of the present disclosure. As shown in fig. 1, the task scheduling method includes steps S101 to S103.
S101, acquiring execution requests of a plurality of target task threads of a target task.
It should be noted that, in this embodiment of the present disclosure, a task refers to an execution entity of a computer program, which is a basic unit of scheduling and managing an operating system, and is a unit of running a program in a computer system, and represents a specific set of operations and logic flows to perform a specific calculation or operation. A task may include an application or a thread, a task may be composed of one or more threads, a thread being the actual execution unit of the task. In multi-threaded programming, tasks may be partitioned into multiple concurrently executing threads, sharing the same resource and context. The creation, scheduling and management of the tasks are all responsible for an operating system, and the operating system decides the allocation sequence and time slice allocation of the tasks through a specific scheduling algorithm so as to realize fair competition and priority control among the tasks. Therefore, the target task can comprise one or more target task threads, and in the embodiment, the execution requests of the target task threads can be acquired simultaneously without acquiring the target task threads one by one, so that the execution efficiency of the target task threads is effectively improved, and the execution time of the target task is further saved.
S102, judging whether each target task thread is executed or not according to a first preset condition.
The embodiment of the disclosure needs to be described herein that the concurrent execution of the threads means that multiple threads can run in the same process at the same time, and each thread independently executes a specified task, so that concurrency is achieved, and responsiveness and processing capability of a program are improved. However, in particular, whether each target task thread is allowed to execute may be limited by the first preset condition. For example, if the first preset condition is a limitation on the number of threads concurrently executing, when each target task thread requests to execute, it needs to be determined whether the number of threads concurrently executing at this time reaches the maximum value of the allowed number of threads.
S103, judging whether other task threads are executed after the execution of each target task thread is finished according to a second preset condition.
Embodiments of the present disclosure are further described herein with reference to scheduling of threads, which refers to an operating system determining which threads obtain CPU time slices and execute tasks by a thread scheduling algorithm. The policy of thread scheduling may be implemented according to priority, time slice rotation, preemption, etc. When the target task thread is executed, in order to make more use of the processor, it may be determined whether to execute other task threads according to the second preset condition. For example, if the second preset condition is the priority of the task thread, the task thread with the highest level in the other task threads is preferentially executed.
Further, in some embodiments of the present disclosure, as shown in fig. 7, the task scheduling method further includes steps S701-S703.
S701, creating a first channel for each task thread to send an execution request.
The embodiment of the present disclosure should be noted here that the first channel is a communication channel, and the communication channel is used to transmit uplink and downlink telecontrol information such as control, measurement, signals, video data, etc. between the scheduling end and the executing end. The first channel is used to pass requests for execution of task threads. And, preferably, the first channel may be used by each task thread.
S702, creating a second channel for each task thread to send an end notification.
The embodiment of the present disclosure should be noted here that the second channel is also one of communication channels, where the second channel is used to transmit an end notification of each task thread after the task thread is executed. And, preferably, the second channel may be used by each task thread.
S703, each task thread respectively creates a third channel for receiving an execution instruction.
It should be noted here that, in the embodiments of the present disclosure, the third channel is also a communication channel, and each task thread is provided with a third channel, so that the third channel is used for receiving an execution instruction to execute the task thread timely and efficiently.
Further, in order to better illustrate the arrangement of the above channels, the Go language is used herein as an example. In the Go language, a channel is a special data structure used for communication and synchronization between threads. It can be seen as a pipe that can transfer data between different threads. Using channels, values can be sent and received between threads. The channels provide a secure, synchronized way to share data. It ensures that the receive operation will wait until the transmit operation is completed and that the transmit operation will also wait until the receive operation is completed. The synchronization mechanism can effectively avoid the competition condition and the data competition which occur when the shared data is accessed concurrently. Thus, the first channel, the second channel, and the third channel described above can be set based on Go language.
Further, in some embodiments of the present disclosure, when step S102 is performed, that is, when determining whether to execute each target task thread according to the first preset condition, the method may be implemented, but is not limited to, as shown in fig. 2, including steps S201 to S202.
S201, acquiring the number of threads being executed and the maximum number of threads allowed to be executed in parallel.
The embodiment of the present disclosure needs to be described herein, where, as described above, concurrent execution of threads means that multiple threads may run in the same process at the same time, and each thread independently executes a specified task, so as to achieve concurrency, and improve responsiveness and processing capability of a program. However, in general, the number of concurrently executing threads is limited, and thus the maximum number of concurrently executing threads, i.e., the maximum number of threads allowed to be executed simultaneously by a processor or the like when executing the threads, occurs.
S202, judging whether the number of threads being executed is smaller than the maximum number of threads allowed to be executed in parallel:
If yes, notifying the target task thread to execute the target task through the corresponding third channel;
If not, the corresponding target task thread continues to wait for execution.
The embodiment of the present disclosure needs to be described herein, where if the number of threads being executed is smaller than the maximum number of threads allowed to be executed in parallel, the processor that describes the executing thread may also execute a new thread at the same time, and the corresponding target task thread may be executed directly without waiting. If the number of executing threads is equal to the maximum number of threads allowed to be executed in parallel, the processor of the executing thread is in a saturated working state, and the corresponding target task thread cannot be executed immediately and needs to wait continuously.
Further, in some embodiments of the present disclosure, when the yes in step S202 is performed, the corresponding target task thread continues to wait for execution, which may be implemented by, but is not limited to, the following method, as shown in fig. 3, including steps S301-S303.
S301, acquiring the priority of each task thread of the target task and other tasks.
It should be noted here that, in the operating system, the threads may be prioritized, and the higher priority threads obtain more CPU resources, that is, the CPU preferentially executes the task of the higher priority thread object. Therefore, the priorities of the task threads of the target task thread and other tasks that continue to wait for execution need to be acquired first in order to determine the threads that execute preferentially later.
S302, queuing the third channels created by the task threads according to priorities, wherein the same priority is the same channel queue.
It should be noted here that, in order to more clearly and more intuitively describe the queuing rule of the task thread, this embodiment is illustrated by fig. 4, and as shown in fig. 4, a first channel queue 401, a second channel queue 402, and a third channel queue 403 with channel queue priorities from high to low are exemplarily given in a channel queue pool 400. The first channel queue 401 exemplarily shows a first task thread third channel, a second task thread third channel and a third task thread third channel which are sequentially executed from the head of the queue to the tail of the queue in the present channel queue; the second channel queue 402 illustratively presents a fourth task thread third channel; the third channel queue 403 illustratively shows a fifth task thread third channel and a sixth task thread third channel that are sequentially executed in order from head to tail within the present channel queue. Therefore, when queuing is performed, the third channels of all task threads divide channel queues according to the priority, the same channel queues with the same priority are sequentially executed in the same channel queues from the head of the queue to the tail of the queue. Therefore, when judging the task thread which is executed preferentially, the task thread can be started from the channel queue with the highest priority, and the third channel is not selected randomly for judgment, so that the task scheduling efficiency is improved.
S303, judging whether a peer channel queue with the same priority as the corresponding target task thread exists or not:
if yes, the corresponding target task thread is put into the tail of the peer channel queue;
If not, a new channel queue is created for the third channel of the corresponding target task thread.
The embodiment of the disclosure needs to be described here that if there is a channel queue with the same priority as that of the target task thread, a new channel queue is not required to be created again, and the third channel corresponding to the target task thread is directly placed in the tail of the channel queue, where the placement is that the priorities of the task threads corresponding to the third channels in the channel queue are the same, so that the task threads are sequentially executed in the order from the head of the queue to the tail of the queue; if the channel queue with the same priority as the target task thread does not exist, a new channel queue needs to be created, and at the moment, a third channel corresponding to the target task thread is located at the head of the new channel queue.
Further, in some embodiments of the present disclosure, when step S103 is executed, that is, whether to execute other task threads after each target task thread is executed according to the second preset condition is determined, the method may be implemented by, but is not limited to, the following method, as shown in fig. 5, including steps S501-S502.
S501, acquiring the priority of each task thread of the target task and other tasks.
It should be noted here that, as described above, in an operating system, threads may be prioritized, where higher priority threads obtain more CPU resources, i.e., the CPU preferentially performs tasks of higher priority thread objects. Thus, all task threads are acquired here first, including the priorities of the task threads of the target task and other tasks that continue to wait, in order to subsequently determine the task threads that execute preferentially.
S502, executing the task thread with the highest priority in the task threads after the target task thread is executed.
The embodiments of the present disclosure should be described herein in which task threads with higher priority need to execute preferentially, i.e., ensure that task threads that are more "urgent" can be executed preferentially, so as to reasonably schedule the execution sequence of each task thread.
Further, in some embodiments of the present disclosure, after executing step S502, that is, after the target task thread is executed, executing the task thread with the highest priority in each task thread may be implemented by, but is not limited to, the following method, as shown in fig. 6, including steps S601-S603.
S601, queuing the third channels created by the task threads according to the priorities, wherein the same channel queues with the same priority.
The embodiment of the disclosure should be described here, referring to fig. 4 again, when queuing, the third channels of all task threads divide the channel queues according to the priorities, where the same priority is the same channel queue, and the corresponding task threads are sequentially executed in the same channel queue from the head of the queue to the tail of the queue. Therefore, when judging the task thread which is executed preferentially, the task thread can be started from the channel queue with the highest priority, and the third channel is not selected randomly for judgment, so that the task scheduling efficiency is improved.
S602, acquiring the priority and the length of each channel queue.
The embodiments of the present disclosure should be described herein as the priority of the channel queue, that is, the priority of the task thread in the channel queue, and the length of the channel queue, that is, the number of third channels included in the channel queue. The priority and the length of the channel queue are acquired firstly, so that convenience and rapidness can be brought to the follow-up task thread which is executed preferentially when judging.
S603, judging whether the length of each channel queue is smaller than one according to the order of priority from high to low:
if the length of each channel queue is smaller than one, terminating the judgment;
If the channel queue with the length being more than or equal to one exists, the task thread corresponding to the third channel positioned at the head of the channel queue is selected to execute when the channel queue appears for the first time, and the judgment is terminated.
The embodiments of the present disclosure should be described herein in which the priority of the task thread in the channel queue with high priority is higher, and thus the length of the channel queue with high priority is preferentially determined. If the length of each channel queue is smaller than one, the number of the third channels in each channel queue is zero, namely, no task thread waiting for execution is needed, and the task thread to be executed next is not needed to be selected, so that the judgment is terminated; if the channel queue with the length being greater than or equal to one appears, the channel queue is provided with a third channel corresponding to the task thread waiting to be executed, and the judgment of the channel queue is carried out according to the priority from high to low, so that the channel queue appearing for the first time is the channel queue with the highest priority in all the channel queues, the task thread corresponding to the third channel at the head of the channel queue is executed, and the judgment is terminated immediately.
In order to more clearly and fully describe the present disclosure, a more specific embodiment is provided below, and as shown in fig. 8, after the target task scheduling starts, for a certain target task thread, it is required to assign the priority of the target task thread first, and create a third channel. Then a first scheduling unit (to be described later) acquires application execution information and priority information of the target task thread through a first channel, judges whether the number of executing threads is smaller than the maximum allowed execution thread number, if not, inserts a third channel corresponding to the target task thread into the tail of a queue of the same priority channel, and continues to wait for execution; if yes, the execution instruction is sent through the third channel, and the target task thread executes after the execution instruction is received. And after the execution of the target task thread is finished, sending an end notification through a second channel. After receiving the end notification, a second scheduling unit (which will be described later) subtracts one from the number of executing threads, and selects a third channel corresponding to the next task thread to be executed in a channel queue pool, and if the third channel corresponding to the next task thread to be executed exists in the channel queue pool, sends an execution instruction through the third channel to execute the task thread; if the third channel of the task thread waiting to be executed does not exist in the channel queue pool, deleting the empty channel queue, ending the judgment, and continuing waiting for a new ending notification.
The second aspect of the embodiments of the present disclosure is described below: a task scheduling system.
Fig. 9 shows a task scheduling system according to an embodiment of the present disclosure. As shown in fig. 9, the task scheduling system 900 includes:
the task schedulers can run simultaneously and are used for executing each target task thread of the target task and each task thread of other tasks;
the task scheduler includes:
and the first scheduling unit is used for respectively judging whether the target task thread is executed or not according to a first preset condition. Specifically, the execution flow of the first scheduling unit may refer to fig. 8 and refer to the foregoing description.
And the second scheduling unit is used for respectively judging whether other task threads are executed after the execution of each target task thread is finished according to a second preset condition. Specifically, the execution flow of the second scheduling unit may refer to fig. 8 and refer to the foregoing description.
Specifically, in the present embodiment, the task scheduling system 900 exemplarily gives an a task scheduler 901 and an b task scheduler 902. The first task scheduler 901 includes a first scheduling unit 903 and a second scheduling unit 904, and the second task scheduler 902 includes a second first scheduling unit 905 and a second scheduling unit 906. For example, when a target task has a first target task thread and a second target task thread, the first target task thread may be executed by the first task scheduler 901 and the second target task thread may be executed by the second task scheduler 902. Thus, the first target task thread and the second target task thread can be performed simultaneously by using different task schedulers without queuing one by one, and the execution efficiency of the target task is improved by introducing a plurality of task schedulers. The execution of the first target task thread by the first task fetcher may be described with reference to the flow shown in fig. 8 and described above, and similarly, the execution of the second target task thread by the second task fetcher may be described with reference to the flow shown in fig. 8 and described above, which will not be repeated here. In addition, in this embodiment, two task schedulers for executing the target task thread in parallel are provided, and in other optional embodiments, the target task thread may also be executed in series, for example, when the execution of the target task thread b can be started after the execution of the target task thread a is completed, the corresponding task thread a and task thread b need to be executed by the corresponding task schedulers according to the sequence.
In an embodiment of the present disclosure, the task scheduling system further includes:
a first channel, configured to send an execution request to the first scheduling unit by each task thread;
A second channel, configured to send an end notification to the second scheduling unit by each task thread;
And the third channels are configured for each task thread, and are used for receiving the execution instructions of the first scheduling unit or the second scheduling unit.
Further, the first channel, the second channel and the third channel can be set based on the Go language, so that the resources occupied by the Go language channel are small, and the resource occupation of a system is saved. Meanwhile, the Go language has the advantages of high-efficiency compiling, strong concurrent processing capability, excellent memory management, type safety, rich standard library, cross-platform support, simplicity, easiness in learning, multi-core support and the like. The compiling speed of the Go language is very fast, and executable files can be generated rapidly; and the concurrency processing capability of the Go language is strong, and the concepts of goroutine and channel are adopted to realize concurrency and parallel programming, so that the Go language is very suitable for processing concurrency request and high concurrency application scenes. In this embodiment, the task scheduler a and the task scheduler b operate in WEB services developed by the Go language, and perform communication scheduling using a channel specific to the Go language in the whole course. On the same WEB service, a plurality of task schedulers can be operated, for example, a task scheduler can be created for a task accessing a database, a task scheduler can be created for a task accessing a cache, the same task scheduler can be created for different types of tasks, and the like. Which task scheduler the current task is submitted to for scheduling depends on the needs of the service.
The third and fourth aspects of embodiments of the present disclosure are described below: an electronic device and a computer-readable storage medium.
The electronic device comprises a memory and a processor, wherein the memory stores a computer program, and the processor realizes the task scheduling method when executing the computer program.
A computer readable storage medium having stored thereon a computer program which when executed by a processor implements the task scheduling method described above.
As shown in fig. 10, a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure is shown. The electronic device in the embodiments of the present disclosure is only one example, and should not impose any limitation on the functions and scope of use of the embodiments of the present disclosure.
With continued reference to fig. 10, the electronic apparatus includes a processing device 1001, a storage device 1002, a sensor device 1003, a bus 1004, an input/output (I/O) interface 1005, a multimedia device 1006, a power supply device 1007, a communication device 1008, and the like.
The processing device 1001 (e.g., a central processing unit, a graphics processor, etc.) is used to control the overall operation of the electronic device. The processing device 1001 may include one or more processors to execute instructions to perform all or part of the steps of the methods described above. The processing device 1001 may also include one or more modules for processing interactions with other devices.
The storage device 1002 is configured to store various types of data, and the storage device 1002 may be a system, a device or a component including various types of computer readable storage media, or a combination thereof, such as an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or a combination of any of the above.
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 disclosure, 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.
The sensor means 1003 for sensing prescribed measured information and converting it into usable output signals according to a certain rule may comprise one or more sensors. For example, it may include an acceleration sensor, a gyro sensor, a magnetic sensor, a pressure sensor, a temperature sensor, or the like for detecting changes in the on/off state, relative positioning, acceleration/deceleration, temperature, humidity, light, or the like of the electronic apparatus.
The processing means 1001, the storage means 1002 and the sensor means 1003 are connected to each other by a bus 1004. An input/output (I/O) interface 1005 is also connected to bus 1004.
The multimedia device 1006 may include an input device such as a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, etc. for receiving input signals from a user, and may be used to perform gesture operation input, image recognition input, distance detection input, etc. in combination with various sensors of the above-mentioned sensor device; the multimedia device may also include an output device such as a Liquid Crystal Display (LCD), speaker, vibrator, etc.
The power supply device 1007, which is used to provide power to various devices in the electronic apparatus, may include a power management system, one or more power supplies, and components to distribute power to other devices.
The communication means 1008 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data.
Each of the above devices may also be connected to the I/O interface 1005 to enable application of the electronic apparatus.
While an electronic device having various means is shown in the figures, it is to be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may be implemented or provided instead.
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 non-transitory computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such embodiments, the computer program may be downloaded and installed from a network via a communications device, or from a storage device. The above-described functions defined in the methods of the embodiments of the present disclosure are performed when the computer program is executed by a processing device.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
It is noted that the computer readable medium described above in the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. In the present disclosure, 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: electrical wires, fiber optic cables, RF (radio frequency), and the like, or any suitable combination of the foregoing.
The computer readable medium may be contained in the electronic device; or may exist alone without being incorporated into the electronic device.
Further, computer program code for carrying out operations of the present disclosure may be written in one or more programming languages, including, but not limited to, an object oriented programming language such as Java, python, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of remote computers, the remote computer may be connected to the user computer through any kind of network or may be connected to an external computer (e.g., connected through the internet using an internet service provider).
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 disclosure. 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 and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments of the present disclosure may be implemented by means of software, or may be implemented by means of hardware. Wherein the names of the units do not constitute a limitation of the units themselves in some cases.
The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: a Field Programmable Gate Array (FPGA), an Application Specific Integrated Circuit (ASIC), an Application Specific Standard Product (ASSP), a system on a chip (SOC), a Complex Programmable Logic Device (CPLD), and the like.
The following briefly summarizes and lists the features of the embodiments described above in accordance with the present disclosure.
According to one or more embodiments of the present disclosure, a task scheduling method is provided, which adopts the following technical solutions, including:
Acquiring execution requests of a plurality of target task threads of a target task;
respectively judging whether each target task thread is executed or not according to a first preset condition;
And respectively judging whether other task threads are executed after the execution of each target task thread is finished according to a second preset condition.
According to one or more embodiments of the present disclosure, a task scheduling method is provided, and the following technical solution is adopted, where the task scheduling method further includes:
creating a first channel for each task thread to send an execution request;
Creating a second channel for each task thread to send an end notification;
and each task thread respectively creates a third channel for receiving an execution instruction.
According to one or more embodiments of the present disclosure, a task scheduling method is provided, which adopts a technical scheme that according to a first preset condition, respectively determines whether to execute each target task thread, including:
acquiring the number of threads being executed and the maximum number of threads allowed to be executed in parallel;
Judging whether the number of threads being executed is smaller than the maximum number of threads allowed to be executed in parallel:
If yes, notifying the target task thread to execute the target task through the corresponding third channel;
If not, the corresponding target task thread continues to wait for execution.
According to one or more embodiments of the present disclosure, a task scheduling method is provided, where the following technical solution is adopted, and if not, the corresponding target task thread continues to wait for execution, including:
Acquiring the priority of each task thread of the target task and other tasks;
queuing the third channels created by the task threads according to priorities, wherein the same priority is the same channel queue;
judging whether a peer channel queue with the same priority as the corresponding target task thread exists or not:
if yes, the corresponding target task thread is put into the tail of the peer channel queue;
If not, a new channel queue is created for the third channel of the corresponding target task thread.
According to one or more embodiments of the present disclosure, a task scheduling method is provided, which adopts a technical scheme that according to a second preset condition, whether to execute other task threads after each target task thread is executed is determined, including:
Acquiring the priority of each task thread of the target task and other tasks;
And executing the task thread with the highest priority in the task threads after the target task thread is executed.
According to one or more embodiments of the present disclosure, a task scheduling method is provided, which adopts a technical scheme that after the target task thread is executed, executing a task thread with a highest priority in the task threads, including:
queuing the third channels created by the task threads according to priorities, wherein the same priority is the same channel queue;
acquiring the priority and the length of each channel queue;
Judging whether the length of each channel queue is smaller than one according to the order of priority from high to low:
if the length of each channel queue is smaller than one, terminating the judgment;
If the channel queue with the length being more than or equal to one exists, the task thread corresponding to the third channel positioned at the head of the channel queue is selected to execute when the channel queue appears for the first time, and the judgment is terminated.
According to one or more embodiments of the present disclosure, there is provided a task scheduling system for implementing the method described above, where the task scheduling system includes:
the task schedulers can run simultaneously and are used for executing each target task thread of the target task and each task thread of other tasks;
the task scheduler includes:
the first scheduling unit is used for judging whether the target task thread is executed or not according to a first preset condition;
and the second scheduling unit is used for respectively judging whether other task threads are executed after the execution of each target task thread is finished according to a second preset condition.
According to one or more embodiments of the present disclosure, there is provided a task scheduling system, which adopts the following technical solution, and the task scheduling system further includes:
a first channel, configured to send an execution request to the first scheduling unit by each task thread;
A second channel, configured to send an end notification to the second scheduling unit by each task thread;
And the third channels are configured for each task thread, and are used for receiving the execution instructions of the first scheduling unit or the second scheduling unit.
According to one or more embodiments of the present disclosure, there is provided an electronic device comprising a memory having a computer program stored therein and a processor, which when executing the computer program implements the method as described above.
According to one or more embodiments of the present disclosure, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a method as described above.
The foregoing description is only of the preferred embodiments of the present disclosure and description of the principles of the technology being employed. It will be appreciated by persons skilled in the art that the scope of the disclosure referred to in this disclosure is not limited to the specific combinations of features described above, but also covers other embodiments which may be formed by any combination of features described above or equivalents thereof without departing from the spirit of the disclosure. Such as those described above, are mutually substituted with the technical features having similar functions disclosed in the present disclosure (but not limited thereto).
Moreover, although operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. In certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are example forms of implementing the claims.
Claims (10)
1. A method for task scheduling, comprising:
Acquiring execution requests of a plurality of target task threads of a target task;
respectively judging whether each target task thread is executed or not according to a first preset condition;
And respectively judging whether other task threads are executed after the execution of each target task thread is finished according to a second preset condition.
2. The method of claim 1, wherein the task scheduling method further comprises:
creating a first channel for each task thread to send an execution request;
Creating a second channel for each task thread to send an end notification;
and each task thread respectively creates a third channel for receiving an execution instruction.
3. The method according to claim 2, wherein the determining whether to execute each of the target task threads according to the first preset condition includes:
acquiring the number of threads being executed and the maximum number of threads allowed to be executed in parallel;
Judging whether the number of threads being executed is smaller than the maximum number of threads allowed to be executed in parallel:
If yes, notifying the target task thread to execute the target task through the corresponding third channel;
If not, the corresponding target task thread continues to wait for execution.
4. A method according to claim 3, wherein if not, the corresponding target task thread continues to wait for execution, comprising:
Acquiring the priority of each task thread of the target task and other tasks;
queuing the third channels created by the task threads according to priorities, wherein the same priority is the same channel queue;
judging whether a peer channel queue with the same priority as the corresponding target task thread exists or not:
if yes, the corresponding target task thread is put into the tail of the peer channel queue;
If not, a new channel queue is created for the third channel of the corresponding target task thread.
5. The method according to claim 2, wherein the determining whether to execute the other task thread after the execution of each target task thread is completed according to the second preset condition includes:
Acquiring the priority of each task thread of the target task and other tasks;
And executing the task thread with the highest priority in the task threads after the target task thread is executed.
6. The method according to claim 5, wherein executing the task thread with the highest priority among the task threads after the target task thread is executed, comprises:
queuing the third channels created by the task threads according to priorities, wherein the same priority is the same channel queue;
acquiring the priority and the length of each channel queue;
Judging whether the length of each channel queue is smaller than one according to the order of priority from high to low:
if the length of each channel queue is smaller than one, terminating the judgment;
If the channel queue with the length being more than or equal to one exists, the task thread corresponding to the third channel positioned at the head of the channel queue is selected to execute when the channel queue appears for the first time, and the judgment is terminated.
7. A task scheduling system for implementing the method of any one of claims 1-6, the task scheduling system comprising:
the task schedulers can run simultaneously and are used for executing each target task thread of the target task and each task thread of other tasks;
the task scheduler includes:
the first scheduling unit is used for judging whether the target task thread is executed or not according to a first preset condition;
and the second scheduling unit is used for respectively judging whether other task threads are executed after the execution of each target task thread is finished according to a second preset condition.
8. The system of claim 7, wherein the task scheduling system further comprises:
a first channel, configured to send an execution request to the first scheduling unit by each task thread;
A second channel, configured to send an end notification to the second scheduling unit by each task thread;
And the third channels are configured for each task thread, and are used for receiving the execution instructions of the first scheduling unit or the second scheduling unit.
9. An electronic device comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the method of any of claims 1-6 when executing the computer program.
10. A computer readable storage medium, characterized in that the computer readable storage medium has stored thereon a computer program which, when executed by a processor, implements the method according to any of claims 1-6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410623312.1A CN118277063A (en) | 2024-05-17 | 2024-05-17 | Task scheduling method, system, electronic device and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410623312.1A CN118277063A (en) | 2024-05-17 | 2024-05-17 | Task scheduling method, system, electronic device and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118277063A true CN118277063A (en) | 2024-07-02 |
Family
ID=91648318
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202410623312.1A Pending CN118277063A (en) | 2024-05-17 | 2024-05-17 | Task scheduling method, system, electronic device and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118277063A (en) |
-
2024
- 2024-05-17 CN CN202410623312.1A patent/CN118277063A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111950988B (en) | Distributed workflow scheduling method and device, storage medium and electronic equipment | |
CN114020470B (en) | Resource allocation method and device, readable medium and electronic equipment | |
CN109117260B (en) | Task scheduling method, device, equipment and medium | |
US8924977B2 (en) | Sequential cooperation between map and reduce phases to improve data locality | |
US9176774B2 (en) | Workflow control of reservations and regular jobs using a flexible job scheduler | |
RU2454704C2 (en) | Method and system for executing program applications and machine-readable medium | |
CN111191777B (en) | Neural network processor and control method thereof | |
CN111580974B (en) | GPU instance allocation method, device, electronic equipment and computer readable medium | |
CN107832143B (en) | Method and device for processing physical machine resources | |
CN111352711B (en) | Multi-computing engine scheduling method, device, equipment and storage medium | |
US11311722B2 (en) | Cross-platform workload processing | |
CN111240834B (en) | Task execution method, device, electronic equipment and storage medium | |
RU2453901C2 (en) | Hard-wired method to plan tasks (versions), system to plan tasks and machine-readable medium | |
US9471387B2 (en) | Scheduling in job execution | |
CN112905342A (en) | Resource scheduling method, device, equipment and computer readable storage medium | |
CN113722056A (en) | Task scheduling method and device, electronic equipment and computer readable medium | |
CN120256056A (en) | Machine learning training task communication scheduling method, device, equipment and storage medium | |
CN111813541B (en) | Task scheduling method, device, medium and equipment | |
CN118277063A (en) | Task scheduling method, system, electronic device and storage medium | |
CN116821187A (en) | Database-based data processing method and device, medium and electronic equipment | |
CN113792869B (en) | Video processing method and device based on neural network chip and electronic equipment | |
CN115756874A (en) | Multi-machine-room job scheduling method, device, medium and electronic equipment | |
CN112148448B (en) | Resource allocation method, apparatus, device and computer readable medium | |
CN113760524B (en) | Task execution method and device | |
US20140139533A1 (en) | Graphic processing unit virtual apparatus, graphic processing unit host apparatus, and graphic processing unit program processing methods thereof |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |