CN110554921A - Time slice distribution method and device, storage medium and computer equipment - Google Patents

Time slice distribution method and device, storage medium and computer equipment Download PDF

Info

Publication number
CN110554921A
CN110554921A CN201910819019.1A CN201910819019A CN110554921A CN 110554921 A CN110554921 A CN 110554921A CN 201910819019 A CN201910819019 A CN 201910819019A CN 110554921 A CN110554921 A CN 110554921A
Authority
CN
China
Prior art keywords
task
priority
tasks
time
time slice
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.)
Granted
Application number
CN201910819019.1A
Other languages
Chinese (zh)
Other versions
CN110554921B (en
Inventor
查冲
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201910819019.1A priority Critical patent/CN110554921B/en
Publication of CN110554921A publication Critical patent/CN110554921A/en
Application granted granted Critical
Publication of CN110554921B publication Critical patent/CN110554921B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

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

Abstract

the application relates to a time slice allocation method, a device, a computer readable storage medium and a computer device, wherein the method comprises the following steps: acquiring a task to be operated of a time slice to be allocated; determining task priority corresponding to a task to be run; according to the task priority, the time slices are continuously distributed to the high-priority task in the tasks to be operated; the high priority tasks are run in persistently allocated time slices. Compared with the engineering scheduling mode adopted in the prior art, the scheme provided by the application ensures the service quality of the high-priority task directly from the perspective of the kernel time slice, and greatly improves the real-time performance of the scheduled high-priority task.

Description

Time slice distribution method and device, storage medium and computer equipment
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for time slice allocation, a computer-readable storage medium, and a computer device.
background
In order to improve the execution efficiency of the program, the system core can schedule the time slice of each task based on a fair strategy, so that each task can run equally. In actual business, multiple tasks are usually processed simultaneously, and in order to guarantee the quality of service, some tasks need to be satisfied preferentially.
At present, for the situation of simultaneous processing of multiple tasks, the traditional method is to ensure the service quality of the task that needs to be satisfied preferentially by a resource scheduling mode from the perspective of technical engineering. However, this method of engineering scheduling is based on the collection and feedback of data such as monitoring, and for a task that needs to be satisfied preferentially, the scheduling time has already affected the task, and the real-time performance is low.
disclosure of Invention
based on this, it is necessary to provide a time slice allocation method, an apparatus, a computer-readable storage medium, and a computer device for solving the technical problem that the existing method of using engineering scheduling to preferentially satisfy part of tasks has low real-time performance.
A method of time slice allocation, comprising:
Acquiring a task to be operated of a time slice to be allocated;
Determining task priority corresponding to the task to be operated;
According to task priorities, time slices are continuously distributed to high-priority tasks in the tasks to be operated;
running the high priority task within the time slice allocated continuously.
A time slice dispensing apparatus, the apparatus comprising:
The task acquisition module is used for acquiring the tasks to be operated of the time slices to be distributed;
The priority determining module is used for determining task priority corresponding to the task to be operated;
The time slice distribution module is used for continuously distributing time slices to high-priority tasks in the tasks to be operated according to task priorities;
And the task running module is used for running the high-priority task in the time slices which are continuously distributed.
a computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, causes the processor to carry out the steps of the above-mentioned time slice allocation method.
A computer device comprising a memory and a processor, the memory storing a computer program which, when executed by the processor, causes the processor to carry out the steps of the above-mentioned time slice allocation method.
According to the time slice allocation method, the time slice allocation device, the computer readable storage medium and the computer equipment, the concept of task priority is introduced into the allocation logic of the time slices, when the task to be operated requiring the time slices to be allocated is obtained, the time slices are continuously allocated to the high-priority tasks in the task to be operated according to the task priority of the task to be operated, the principle of fair allocation of the time slices is broken, the high-priority tasks can be preferentially met, and therefore the high-priority tasks can be operated in the time slices which are continuously allocated. Compared with the engineering scheduling mode adopted in the prior art, the service quality of the high-priority task is directly ensured from the perspective of the kernel time slice, and the real-time performance of the scheduled high-priority task is greatly improved.
Drawings
FIG. 1 is a diagram of an application environment for the time slice allocation method in one embodiment;
FIG. 2 is a flow diagram that illustrates a method for time slice allocation in one embodiment;
FIG. 3 is a diagram illustrating allocation of time slices by a kernel scheduler in a specific application scenario;
FIG. 4 is a diagram illustrating the allocation of time slices by a kernel scheduler in another specific application scenario;
FIG. 5 is a diagram illustrating the allocation of time slices by a kernel scheduler in yet another specific application scenario;
FIG. 6 is a diagram illustrating the allocation of time slices by a kernel scheduler in yet another specific application scenario;
FIG. 7 is a diagram that illustrates allocating time slices between an online task and an offline task, under an embodiment;
FIG. 8 is a flow diagram that illustrates a method for time slice allocation implemented on a computer device, according to one embodiment;
FIG. 9 is a flow diagram of a method for time slice allocation in one embodiment;
FIG. 10 is a block diagram showing the structure of a time slice distribution apparatus according to an embodiment;
FIG. 11 is a block diagram of a computer device in one embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
Before describing the embodiments of the method of the present application, the related terms referred to in the present application will be described.
Time slice: the CPU (Central Processing Unit) of the computer device allocates the running time of each task. That is, the running time of the CPU is divided into a plurality of time slots, and each task is assigned a time slot, which is called its time slice, i.e., the time that the task is allowed to run, so that the respective tasks are performed seemingly simultaneously. Generally, on a computer device of a Linux operating system, a CPU scheduling policy adopted by a kernel scheduling algorithm is to equally allocate time slices among tasks, that is, to allocate time slices to each task in turn, if a certain task is still running when a current time slice ends, a next time slice of the current time slice is allocated to another task, and if a task is blocked or ended before the current time slice ends, a CPU immediately switches between tasks, so that CPU resource waste is not caused.
Task: a task may be a process or a thread. Generally, a task corresponds to a series of computer operations, such as an input operation, a download operation, a codec operation, and the like, and a process or a thread performs a task by performing the computer operations in the task.
FIG. 1 is a diagram of an embodiment of an application environment for the method for time slice allocation. Referring to fig. 1, the time slice allocation method is performed by a computer device 110. The computer device may be a terminal, and the terminal may specifically be a desktop terminal or a mobile terminal, and the mobile terminal may specifically be at least one of a mobile phone, a tablet computer, a notebook computer, and the like. The computer device may also be a server, which may be implemented as a stand-alone server or as a server cluster comprising a plurality of servers. The operating system employed by the computer device may be a Linux operating system.
It should be noted that the operating system kernel scheduling algorithm in the computer device is implemented by executing the time slice allocation method provided in the present application. The computer equipment can obtain the tasks to be run of the time slices to be distributed; determining task priority corresponding to a task to be run; according to the task priority, the time slices are continuously distributed to the high-priority task in the tasks to be operated; the high priority tasks are run in persistently allocated time slices.
as shown in FIG. 2, in one embodiment, a method of time slice allocation is provided. The embodiment is mainly illustrated by applying the method to the computer device 110 in fig. 1. Referring to fig. 2, the time slice allocation method specifically includes the following steps:
S202, acquiring the task to be run of the time slice to be allocated.
The task to be executed refers to a task which is not executed after being triggered. The computer device needs to allocate the CPU time period to the task to be executed, so that the task to be executed is executed by the CPU within the allocated time slice. The duration of each time slice can be set according to needs, and can be set to 5ms-800ms in general.
because the running time slices of the CPU are distributed in sequence according to the time sequence, one CPU can only execute one task at one moment, if the current time slice is not finished and a certain task is running, when a plurality of tasks are triggered in the current time slice, the computer equipment can acquire a plurality of tasks to be run. For example, a downloading task is running in the current time slice, and at this time, a user triggers a keyboard input event and a mouse click event, so that the keyboard input event and the mouse click event are tasks to be run.
Or, if no task runs in the current time slice, that is, the CPU is not assigned to any task, the computer device may acquire a plurality of tasks to be run when the plurality of tasks are triggered. For example, the user triggers the timing task and the deleting task simultaneously in the current time slice, and then the timing task and the deleting task are both tasks to be run.
and S204, determining the task priority corresponding to the task to be operated.
Wherein the task priority is a task level set for different types of tasks. In some embodiments, the higher the task priority of a task, the higher the task priority the task will be scheduled for execution by the CPU. And, the higher the task priority of the task, the higher the CPU time slice will be allocated to the task according to the time length required by the task running.
in one embodiment, after acquiring a plurality of tasks to be executed, the computer device may configure the tasks to be executed with the same task priority into the same task set according to the task priorities of different tasks, where the probabilities of the tasks in the task set being scheduled and executed by the CPU are the same, that is, the tasks in the task set configured with the tasks to be executed with high priority are scheduled and executed preferentially, and the CPU time slices are evenly distributed to the tasks in the same task set. For example, task a1 and task a2 belong to the same task set a, task B1 and task B2 belong to the same task set B, and the task belonging to task set a corresponds to a task with higher priority than the task belonging to task set B. The computer device may first assign the time slices to task a1 and task a2 in task set a, and then assign the time slices to task B1 and task B2 after task a1 and task a2 are finished running.
In one embodiment, the computer device may determine the task priority corresponding to each task to be executed according to the task type of each task to be executed. The task types can be divided into an online task and an offline task according to whether the tasks need to transmit data through a network, the task priority of the online task is higher than that of the offline task, for example, the online task is a picture downloading task, and the offline task is a local picture compression task. The task types can also be divided into a time-consuming task and a fast task according to the time required for the task to be executed, the task priority of the time-consuming task is lower than that of the fast task, for example, the time-consuming task is a file copy task, and the fast task is a network traffic transmission task or a disk fast read-write task.
And S206, according to the task priority, continuously distributing the time slices to the high-priority task in the tasks to be operated.
The high-priority task is a task with the relatively highest task priority in the acquired tasks to be run. Specifically, for a high-priority task among the tasks to be executed, the computer device may continuously allocate a plurality of consecutive time slices to the high-priority task to ensure that the high-priority task is executed preferentially, that is, if the high-priority task has not been finished or blocked when the first time slice is finished, continuously allocate a second time slice to the high-priority task, and so on until the high-priority task is finished or blocked in advance. After the high priority task is blocked or ended in advance, the computer device may assign the next time slice after the current time to the remaining tasks of the tasks to be run.
The continuous allocation of time slices to high priority tasks is a different way than the uniform allocation of time slices. Generally, in the uniform distribution mode, the running time of the CPU is the same for all tasks, that is, the kernel schedules each task in turn, each task executes a time slice and then switches to the next task, and the kernel needs to spend time when scheduling different tasks, which further results in lower real-time performance of each task. In the application, enough time slices are continuously allocated to the high-priority tasks, so that the high-priority tasks are preferentially met, and the real-time performance of the high-priority tasks can be ensured.
and S208, running the high-priority task in the time slice which is continuously allocated.
in particular, the computer device may run high priority tasks within persistently allocated time slices. It should be noted that the number of time slices allocated continuously is related to the time length required for the high priority task to run, and may be less than one time slice, one time slice or one of multiple time slices. For example, if the high-priority task can be finished in advance or blocked in advance within less than one time slice, the kernel scheduling algorithm can immediately schedule the next task to be run to execute, so that the CPU resource is not wasted; if the high-priority task needs to occupy a plurality of time slices for operation, the remaining tasks to be operated need to continuously wait.
in one embodiment, the above time slice allocation method further comprises:
Adding the rest tasks in the tasks to be operated to a task queue; and when the time slices are stopped being allocated to the high-priority tasks, allocating the time slices to the tasks to be operated in the task queue.
the computer equipment can add the tasks left in the tasks to be operated to the task queue, the tasks in the task queue are in a ready state, and the tasks in the task queue can alternately distribute time slices in a first-in first-out mode. The condition for stopping the allocation of time slices for the high priority task may be that the high priority task runs out or is blocked in advance. When the high priority task is running out or blocked in advance, the computer device can distribute the time slice after the current time to the tasks in the task queue.
In one embodiment, the computer device may alternately and evenly distribute the time slices after the current time to the tasks to be run in the task queue. That is, for the task with relatively low task priority in the task queue, it may be still according to the uniform distribution mode, each time slice executes one task, when the current time slice is over, if a certain task is still running, the next time slice of the current time slice will be distributed to another task, so as to ensure that the tasks in the task queue obtain the running time of the CPU in turn. Of course, if the task is blocked or ended before the current time slice is ended, the CPU can be switched to run the next task immediately in order to avoid wasting the CPU resource.
In a specific application scenario, the high-priority task is an online task, the low-priority task is an offline task, as shown in fig. 3, when the current CPU is in an initialized and unassigned state, the online task a, the offline task B1, and the offline task B2 are triggered at the time t1 at the same time, a time duration between any two adjacent time points is a time slice, and the online task a, the offline task B1, and the offline task B2 are all used as tasks to be run at that time. The operating system kernel can execute the time slice allocation method provided by the application, the online task A is scheduled to be executed preferentially, the executing scheduler can occupy a small part of time t, the time slices are allocated to the online task A continuously after the online task A is scheduled, if the online task A needs to consume 2 time slices, after the online task A is operated, the operating system kernel can execute the scheduler again, the offline tasks are scheduled to be executed, the time slices are uniformly allocated among the offline tasks, namely the time slices are switched between the offline tasks B1 and B2 in turn.
according to the time slice allocation method, the concept of task priority is introduced into the allocation logic of the time slices, when the task to be operated requiring the time slices to be allocated is obtained, the time slices are continuously allocated to the high-priority tasks in the task to be operated according to the task priority of the task to be operated, the principle of fair allocation of the time slices is broken, the high-priority tasks can be preferentially met, and therefore the high-priority tasks can be operated in the time slices which are continuously allocated. Compared with the engineering scheduling mode adopted in the prior art, the service quality of the high-priority task is directly ensured from the perspective of the kernel time slice, and the real-time performance of the scheduled high-priority task is greatly improved.
In one embodiment, the above time slice allocation method further comprises the steps of:
Checking whether a task is currently running;
if so, acquiring the task priority of the current task;
When the task priority of the current task is higher than the task priority corresponding to the task to be operated, then
And continuously allocating the time slices to the current task, and maintaining running the current task in the allocated time slices.
Specifically, since one CPU can only execute one task at a time, after step S204, the computer device may check whether any task is currently running, and if not, that is, the CPU is in an initialization state and does not run a certain task, the computer device may execute step S206 and step S208; if so, that is, when the CPU is in a non-initialized state and a task is running, the computer device may determine a corresponding task priority according to a task type of the task currently running, and when the task priority of the current task is higher than the task priority of the task to be run, continue to allocate the time slice to the current task, that is, if the current task is not finished when the current time slice is finished, continue to allocate a time slice next to the current time slice to the current task, and so on, the computer device may maintain running of the current task within the time slice that is continuously allocated, so as to preferentially meet running of the current task until the current task is finished or blocked in advance, thereby ensuring that the current task with a relatively high task priority can be preferentially run.
Similarly, the above-mentioned continuous allocation of time slices to the current task is different from the uniform allocation of time slices, and since the task priority of the current task is higher, enough time slices are continuously allocated to the current task, so that the high-priority task is preferentially satisfied, and the real-time performance of the high-priority task can be ensured.
In one embodiment, the method further comprises: adding a task to be run to a task queue; and when the time slices are stopped being allocated to the current task, allocating the time slices to the tasks to be operated in the task queue.
specifically, the computer device may add a task to be run, whose task priority is lower than that of the current task, to the task queue, where the task to be run in the task queue is in a ready state, and the tasks in the task queue may alternately allocate time slices in a first-in first-out manner. The condition for stopping the allocation of time slices for the current task is that the current task runs to the end or is blocked in advance. After the current task has run finished or is blocked in advance, the computer device may allocate a time slice after the current time to the task to be run in the task queue.
in one embodiment, the computer device may alternately and evenly distribute the time slices after the current time to the tasks to be run in the task queue. That is to say, for a task to be run corresponding to the current task, which has a relatively low task priority in the task queue, each time slice may execute one task to be run according to an even distribution manner, and if a certain task to be run is still running when the current time slice is over, the next time slice of the current time slice will be distributed to another task to be run, so that it can be ensured that the tasks to be run in the task queue obtain the running time of the CPU in turn. Of course, if the task to be run is blocked or ended before the current time slice is ended, the CPU can be switched to the next task to be run in the run task queue immediately in order to avoid wasting the CPU resource.
In a specific application scenario, a current task is an online task, a task to be executed is an offline task, as shown in fig. 4, when a current CPU is running an online task a, an offline task B is triggered as a task to be executed at time t2, the task priority of the online task a is higher than that of the offline task B, when the online task a is not finished or is blocked in advance, a time slice is continuously allocated to the online task a with a higher task priority, it is ensured that the online task a runs preferentially, it is assumed that the task a needs to consume 3 time slices, after the online task a runs, an operating system kernel may execute a scheduler again, schedule the offline task B to be executed in a 4 th time slice, and if the offline task B runs when the 4 th time slice is finished, the operating system kernel may execute the scheduler again, allocate a 5 th time slice to another task, if offline task B blocks or ends before the 4 th time slice ends, the CPU may schedule another task to execute immediately.
In one embodiment, the above time slice allocation method further comprises the steps of:
When the task priority of the current task is lower than the task priority corresponding to the task to be operated, the task priority of the current task is lower than the task priority corresponding to the task to be operated
and running the current task in the current time slice, continuously distributing the time slices after the current time slice to the task to be run, and running the task to be run in the continuously distributed time slices.
specifically, if the task priority of the current task operated by the current CPU is lower than the task priority corresponding to the task to be operated, the computer device may operate the current task within the current time slice, and regardless of whether the current task is finished or blocked in advance within the current time slice, the computer device may continuously allocate a time slice after the current time slice to the task to be operated with a relatively high task priority, and operate the task to be operated within the continuously allocated time slice, so as to ensure that the task to be operated with the relatively high task priority is preferentially satisfied.
Similarly, the time slices after the current time slice are continuously allocated to the tasks to be operated, which is different from the mode of uniformly allocating the time slices, because the task to be operated has higher priority relative to the current task, the computer equipment continuously allocates enough time slices to the tasks to be operated, so that the tasks to be operated with higher priority are preferentially satisfied, and the real-time performance of the tasks to be operated can be ensured.
in an embodiment, if the current task is ended or blocked in advance in the current time slice, to avoid CPU resource waste, the computer device may also continuously allocate a time slice immediately after the current time to the task to be executed, and execute the task to be executed in the continuously allocated time slice.
In one embodiment, the above time slice allocation method further comprises: shortening the duration of a time slice for running a low-priority task; the low priority task is run within the shortened time slice.
Specifically, by shortening the time length of the time slice for running the low-priority task, if the current task is the low-priority task, the time slice for running the current task is short, and after the current task is run in the short current time slice, the time slice after the current time slice is quickly allocated to the task to be run with the relatively high task priority, so that the task to be run can be ensured to be run in the short time slice after being triggered, and the real-time performance of the task to be run is ensured.
alternatively, the computer device may directly shorten the duration of a CPU time slice for running a task, because a high priority task will be satisfied preferentially, i.e., will be run by a persistently assigned time slice, and the high priority task may be guaranteed for the duration of a time slice that is runnable, even if the duration of the time slice is short. And because the low-priority tasks can only run within the duration of one time slice, the running time of the time slice occupied by the low-priority tasks can be shorter by shortening the duration of the time slice, even if the low-priority tasks occupy the current time slice and run, but the running time is very short, the low-priority tasks can be quickly switched to the high-priority tasks, namely, the high-priority tasks are quickly allocated with the time slices after being triggered, and the waiting time is very short, so that the real-time performance of the high-priority tasks can be ensured.
In a specific application scenario, a current task is an offline task, a task to be executed is an online task, as shown in fig. 5, when a current CPU is running an offline task B, the online task a is triggered at time t as the task to be executed, the task priority of the online task a is higher than that of the offline task B, the computer device can only run the offline task B in a current time slice, when the time slice is finished, the computer device executes a scheduler, and continuously schedules the online task a to run in a time slice after the current time slice until the online task a is finished or is blocked in advance, the computer device executes the kernel scheduler again to schedule another task to execute. If offline task B ends within the current time slice or is blocked ahead of time, the computer device may immediately switch to online task A.
In one embodiment, the above time slice allocation method further comprises:
When the task priority of the current task is consistent with the task priority corresponding to the task to be operated, the task priority of the current task is consistent with the task priority corresponding to the task to be operated
Time slices are evenly distributed between the current task and the task to be run.
Specifically, if the task priority of the current task operated by the current CPU is consistent with the task priority corresponding to the task to be operated, the computer device may uniformly distribute the time slices between the current task and the task to be operated in a uniform distribution manner. That is, time slices are sequentially allocated to each task in turn, if the current task is still running when the current time slice is finished, the next time slice of the current time slice is allocated to the task to be run, and if the current task is blocked or finished in advance before the current time slice is finished, the CPU is switched to run the task to be run immediately, so that the time slices are switched between the current task and the task to be run. The next time slice is taken as the latest "current time slice", and similarly, if the task to be run is still running at the end of the "current time slice", the next time slice of the "current time slice" will be allocated to another task, namely the "current task" described above. By analogy, time slices can be uniformly distributed among a plurality of tasks with consistent task priorities when a plurality of high-priority tasks or a plurality of low-priority tasks are triggered, and the equal real-time performance of the tasks with the same priority is guaranteed.
in a specific application scenario, the current task is an online task, and the task to be executed is an online task, as shown in fig. 6, the online task a and the online task B are alternately executed according to a time slice, that is, the task to be executed is alternately scheduled by the kernel of the operating system, and each time the task to be scheduled is executed by the CPU for a time slice. And when each time slice is finished, triggering the kernel of the operating system to schedule another online task, so that the CPU time slices are uniformly distributed between the online task A and the online task B.
FIG. 7 is a diagram that illustrates the distribution of time slices between online tasks and offline tasks, in one embodiment. The task priority of the online task is higher than that of the offline task, and in order to ensure the real-time performance of the online task, when the CPU time slice is distributed, the priority is ensured that the time slice which can be distributed and the time slice which can be operated by the online task are both preferentially ensured. Referring to fig. 7, a dashed box indicates that the CPU is in an initialized state, a solid box indicates that the CPU is in a running state, the initialized state is a state opposite to the running state, and the initialized state indicates that the CPU time slice is not allocated. When the CPU is in the initialization state (top left in FIG. 7), if the online task is triggered, the CPU time slices may be assigned to the online task (top right in FIG. 7, 4). When the CPU is in the initialization state (top left in fig. 7), if the offline task is triggered, the CPU time slice may be assigned to the offline task (bottom left in fig. 7). When the CPU is in the running state and the CPU is occupied by the online task (upper right in fig. 7), if the offline task is triggered, it is necessary to wait for the online task to end or block in advance, and then the time slice is allocated to the offline task after the CPU is released (lower right in fig. 7). When the CPU is in a running state and the CPU is occupied by the offline task (lower left in fig. 7), if the online task is triggered, the online task may preempt a time slice after the current time slice for maintaining the running of the online task (as lower right in fig. 7). When the CPU is in the running state and the CPU runs the online task and the offline task simultaneously (e.g., lower right in fig. 7), if the online task is triggered, the online task may preempt the time slice of the offline task (e.g., upper right in fig. 7), and if the offline task is triggered, the time slice may be allocated to the offline task after the CPU is released (e.g., lower left in fig. 7) by waiting for the online task to finish or block in advance.
in a specific application scenario, when a user wants to view a picture published in a friend circle, the user usually needs to click the picture before viewing the picture, and actually viewing the picture triggers two tasks, one is a picture downloading task, and the other is a picture compressing task. Obviously, the picture downloading task belongs to an online task, and from the perspective of user experience, the real-time performance of the task needs to be guaranteed, while the picture compression task is an offline task that is locally executed by the user terminal. In order to ensure the real-time performance of the picture downloading task, the time slice allocation method provided by the present application may be adopted to continuously allocate the CPU time slices to the picture downloading task, ensure the preferential operation of the picture downloading task, and allocate the CPU time slices to the picture compression task when the picture downloading task is completed or is blocked due to reasons such as network, that is, the CPU switches to execute the picture compression task. Compared with the method that the time slices are uniformly distributed between the picture downloading task and the picture compression task, the real-time performance of the picture downloading task can be improved, and the user experience is improved.
In one embodiment, the time slice allocation method provided by the present application can be implemented in the following manner, and the effect of the time slice allocation method provided by the present application is verified. As shown in fig. 8, the method specifically includes the following steps:
S802, running a kernel scheduler on the computer device, wherein the kernel scheduler can execute the time slice allocation method provided by the application.
S804, the computer equipment is docker-ized, and the offline task is deployed on the computer equipment in a docker mirror image mode.
And S806, running the online task on the computer equipment which runs the offline task.
And S808, monitoring the running process of the online task. For example, whether the successful running probability of the online task meets a preset threshold value is monitored; if yes, go to step S810; if not, go to step S812.
s810, counting the running delay of the online tasks, and judging whether the occupation ratio of the online tasks with the maximum delay of 1% is increased; if yes, go to step S812; if not, go to step S814.
And S812, taking off the shelf and taking off the line task. The off-line tasks are off-shelf to ensure the real-time performance of the on-line tasks, so that the real-time performance of the on-line tasks is preferentially ensured when the on-line tasks and the off-line tasks are mixed.
S814, the online task and the offline task are maintained to be operated in the computer device in a mixed mode.
In the embodiment, the mixing of the online task and the offline task is realized, the offline task basically occupies 80% of the CPU, and the resource waste is avoided. Although the offline task occupies 80%, the real-time performance of the online service when the online task and the offline task are operated in a mixed manner on the computer equipment is ensured by monitoring the delay, the success rate and the maximum delay of 1% in the operation process of the online task, and the user experience can be improved.
as shown in FIG. 9, in one particular embodiment, the time slice allocation method comprises the steps of:
And S902, acquiring the task to be operated of the time slice to be allocated.
And S904, determining the task type of the task to be operated.
And S906, determining the task priority corresponding to the task to be operated according to the task type.
S908, check if there is a task currently running. If not, go to step S910; if yes, go to step S912.
S910, according to the task priority, time slices are continuously distributed to high-priority tasks in the tasks to be operated; the high priority tasks are run in persistently allocated time slices.
s912, acquiring the task priority of the current task.
S914, comparing the task priority of the current task with the task priority corresponding to the task to be operated;
And S916, when the task priority of the current task is higher than the task priority corresponding to the task to be operated, the time slice is continuously allocated to the current task, and the current task is kept to be operated in the allocated time slice.
s918, adding the task to be operated to a task queue; and when the time slices are stopped being allocated to the current task, allocating the time slices to the tasks to be operated in the task queue.
S920, when the task priority of the current task is lower than the task priority corresponding to the task to be operated, the current task is operated in the current time slice, the time slices after the current time slice are continuously distributed to the task to be operated, and the task to be operated is operated in the time slices which are continuously distributed.
and S922, if the task priority of the current task is consistent with the task priority corresponding to the task to be operated, evenly distributing the time slices between the current task and the task to be operated.
According to the time slice allocation method, the concept of task priority is introduced into the allocation logic of the time slices, when the task to be operated requiring the time slices to be allocated is obtained, the time slices are continuously allocated to the high-priority tasks in the task to be operated according to the task priority of the task to be operated, the principle of fair allocation of the time slices is broken, the high-priority tasks can be preferentially met, and therefore the high-priority tasks can be operated in the time slices which are continuously allocated. Compared with the engineering scheduling mode adopted in the prior art, the service quality of the high-priority task is directly ensured from the perspective of the kernel time slice, and the real-time performance of the scheduled high-priority task is greatly improved.
FIG. 9 is a flowchart of a method for time slice allocation in one embodiment. It should be understood that, although the steps in the flowchart of fig. 9 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a portion of the steps in fig. 9 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
In one embodiment, as shown in FIG. 10, a time slice assigning apparatus 1000 is provided that includes a task obtaining module 1002, a priority determining module 1004, a time slice assigning module 1006, and a task running module 1008, wherein:
a task obtaining module 1002, configured to obtain a task to be run of a time slice to be allocated;
A priority determining module 1004, configured to determine a task priority corresponding to a task to be executed;
The time slice distribution module 1006 is configured to continuously distribute the time slices to high-priority tasks among the tasks to be run according to the task priorities;
a task execution module 1008 to execute the high priority task within the persistently allocated time slices.
In one embodiment, the priority determination module 1004 is further configured to determine a task type of the task to be run; and determining the task priority corresponding to the task to be operated according to the task type.
In one embodiment, the time slice allocation module 1006 is further configured to add remaining tasks of the tasks to be run to the task queue; and when the time slices are stopped being allocated to the high-priority tasks, allocating the time slices to the tasks to be operated in the task queue.
in one embodiment, the time slice distribution apparatus 1000 further comprises:
The checking module is used for checking whether a task is currently running; if so, acquiring the task priority of the current task;
The time slice allocation module 1006 is further configured to, when the task priority of the current task is higher than the task priority corresponding to the task to be executed, continuously allocate the time slice to the current task, and maintain the execution of the current task within the allocated time slice.
In one embodiment, the time slice allocation module 1006 is further configured to add the task to be run to the task queue; and when the time slices are stopped being allocated to the current task, allocating the time slices to the tasks to be operated in the task queue.
in one embodiment, the time slice assignment module 1006 is further configured to: and when the task priority of the current task is lower than the task priority corresponding to the task to be operated, operating the current task in the current time slice, continuously allocating the time slices after the current time slice to the task to be operated, and operating the task to be operated in the continuously allocated time slices.
In one embodiment, the time slice assignment device 1000 further comprises a time slice shortening module for shortening the duration of time slices used to run low priority tasks; the task execution module 1008 is to execute the low priority task within the shortened timeslice.
In one embodiment, the time slice allocation module 1006 is further configured to allocate time slices evenly between the current task and the task to be run when the task priority of the current task is consistent with the task priority corresponding to the task to be run.
in one embodiment, the tasks to be run comprise online tasks and offline tasks, and the task priority of the online tasks is higher than that of the offline tasks.
The time slice allocation device 1000 introduces the concept of task priority in the allocation logic of the time slices, and continuously allocates the time slices to the high-priority tasks in the tasks to be executed according to the task priority of the tasks to be executed when the tasks to be executed requiring the time slices to be allocated are acquired, so that the principle of fair allocation of the time slices is broken, the high-priority tasks can be preferentially satisfied, and the high-priority tasks can be executed in the time slices which are continuously allocated. Compared with the engineering scheduling mode adopted in the prior art, the service quality of the high-priority task is directly ensured from the perspective of the kernel time slice, and the real-time performance of the scheduled high-priority task is greatly improved.
FIG. 11 is a diagram illustrating an internal structure of a computer device in one embodiment. The computer device may specifically be the computer device 110 in fig. 1. As shown in fig. 11, the computer device includes a processor, a memory, and a network interface connected by a system bus. Wherein the memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program which, when executed by the processor, causes the processor to implement the time slice allocation method. The internal memory may also have stored therein a computer program that, when executed by the processor, causes the processor to perform a time slice allocation method.
Those skilled in the art will appreciate that the architecture shown in fig. 11 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
in one embodiment, the time slice distribution apparatus 1000 provided herein may be implemented in the form of a computer program that is executable on a computer device such as that shown in fig. 11. The memory of the computer device may store various program modules constituting the time slice allocation apparatus, such as a task acquisition module 1002, a priority determination module 1004, a time slice allocation module 1006 and a task execution module 1008 shown in fig. 10. The respective program modules constitute computer programs that cause the processors to execute the steps in the time slice allocation methods of the various embodiments of the present application described in the present specification.
for example, the computer apparatus shown in fig. 11 may execute step S202 by the task obtaining module 1002 in the time slice distribution apparatus shown in fig. 10. The computer device may perform step S204 by the priority determination module 1004. The computer device may perform step S206 by the time slice assignment module 1006. The computer device may perform step S208 through the task execution module 1008.
In an embodiment, a computer device is provided, comprising a memory and a processor, the memory storing a computer program which, when executed by the processor, causes the processor to perform the steps of the above-described time slice allocation method. The steps of the time slice allocation method herein may be steps in the time slice allocation methods of the various embodiments described above.
in an embodiment, a computer-readable storage medium is provided, in which a computer program is stored which, when being executed by a processor, causes the processor to carry out the steps of the above-mentioned time slice allocation method. The steps of the time slice allocation method herein may be steps in the time slice allocation methods of the various embodiments described above.
it will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a non-volatile computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the program is executed. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
the technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
the above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present application. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (15)

1. a method of time slice allocation, comprising:
Acquiring a task to be operated of a time slice to be allocated;
Determining task priority corresponding to the task to be operated;
According to task priorities, time slices are continuously distributed to high-priority tasks in the tasks to be operated;
Running the high priority task within the time slice allocated continuously.
2. The method of claim 1, further comprising:
Determining the task type of the task to be run;
and determining the task priority corresponding to the task to be operated according to the task type.
3. The method of claim 1, further comprising:
Adding the rest tasks in the tasks to be operated to a task queue;
And after the time slices are stopped being distributed to the high-priority tasks, distributing the time slices to the tasks to be operated in the task queue.
4. the method of claim 1, further comprising:
checking whether a task is currently running;
If so, acquiring the task priority of the current task;
when the task priority of the current task is higher than the task priority corresponding to the task to be run, the task to be run is executed in the current task
And continuously allocating time slices to the current task, and maintaining the current task in the allocated time slices.
5. The method of claim 4, further comprising:
Adding the task to be operated to a task queue;
And after the time slices are stopped being distributed to the current task, distributing the time slices to the tasks to be operated in the task queue.
6. The method of claim 4, further comprising:
When the task priority of the current task is lower than the task priority corresponding to the task to be operated, the task to be operated is executed according to the task priority
And running the current task in the current time slice, continuously distributing the time slices after the current time slice to the task to be run, and running the task to be run in the continuously distributed time slices.
7. The method of claim 6, further comprising:
shortening the duration of a time slice for running a low-priority task;
The low priority task is run within the shortened time slice.
8. The method of claim 4, further comprising:
when the task priority of the current task is consistent with the task priority corresponding to the task to be operated, the task priority of the current task is consistent with the task priority corresponding to the task to be operated
And equally distributing time slices between the current task and the task to be operated.
9. The method according to any one of claims 1 to 8, wherein the tasks to be run comprise online tasks and offline tasks, and the task priority of the online tasks is higher than the task priority of the offline tasks.
10. A time slice distribution apparatus, characterized in that the apparatus comprises:
The task acquisition module is used for acquiring the tasks to be operated of the time slices to be distributed;
the priority determining module is used for determining task priority corresponding to the task to be operated;
The time slice distribution module is used for continuously distributing time slices to high-priority tasks in the tasks to be operated according to task priorities;
And the task running module is used for running the high-priority task in the time slices which are continuously distributed.
11. The apparatus of claim 10, further comprising:
The checking module is used for checking whether a task is currently running;
The priority determining module is also used for acquiring the task priority of the current task;
the time slice distribution module is also used for continuously distributing time slices to the current task when the task priority of the current task is higher than the task priority corresponding to the task to be operated;
The task running module is further specifically configured to maintain running the current task within the allocated time slice.
12. the apparatus according to claim 11, wherein the time slice allocation module is further configured to, when the task priority of the current task is lower than the task priority corresponding to the task to be run, run the current task within the current time slice, and continuously allocate the time slices after the unit time slice to the task to be run;
The task running module is further specifically configured to run the task to be run within the time slice allocated continuously.
13. The apparatus of claim 11, wherein the time slice allocation module is further configured to evenly allocate time slices between the current task and the task to be executed when a task priority of the current task is consistent with a task priority corresponding to the task to be executed.
14. A computer-readable storage medium, storing a computer program which, when executed by a processor, causes the processor to carry out the steps of the method according to any one of claims 1 to 9.
15. a computer device comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method according to any one of claims 1 to 9.
CN201910819019.1A 2019-08-30 2019-08-30 Time slice distribution method, device, storage medium and computer equipment Active CN110554921B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910819019.1A CN110554921B (en) 2019-08-30 2019-08-30 Time slice distribution method, device, storage medium and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910819019.1A CN110554921B (en) 2019-08-30 2019-08-30 Time slice distribution method, device, storage medium and computer equipment

Publications (2)

Publication Number Publication Date
CN110554921A true CN110554921A (en) 2019-12-10
CN110554921B CN110554921B (en) 2024-02-09

Family

ID=68738635

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910819019.1A Active CN110554921B (en) 2019-08-30 2019-08-30 Time slice distribution method, device, storage medium and computer equipment

Country Status (1)

Country Link
CN (1) CN110554921B (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111488210A (en) * 2020-04-02 2020-08-04 腾讯科技(深圳)有限公司 Task scheduling method and device based on cloud computing and computer equipment
CN112685156A (en) * 2020-12-28 2021-04-20 北京五八信息技术有限公司 Task execution method and device, electronic equipment and computer readable medium
CN113094158A (en) * 2021-03-15 2021-07-09 国政通科技有限公司 Service drive calling method, service drive calling device, electronic equipment and storage medium
CN114285901A (en) * 2021-12-17 2022-04-05 中国电信股份有限公司 Network request processing method and device and electronic equipment
CN114764417A (en) * 2022-06-13 2022-07-19 深圳致星科技有限公司 Distributed processing method and device for privacy calculation, privacy data and federal learning
CN115776524A (en) * 2023-02-10 2023-03-10 广东瑞恩科技有限公司 Internet of things mass data multistage scheduling transmission system for intelligent manufacturing
US11954472B2 (en) * 2021-01-25 2024-04-09 Vmware, Inc. Conflict resolution for device-driven management

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102612157A (en) * 2012-02-24 2012-07-25 哈尔滨工业大学 Embedded real-time scheduling system of wireless sensor network

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102612157A (en) * 2012-02-24 2012-07-25 哈尔滨工业大学 Embedded real-time scheduling system of wireless sensor network

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
ARM社区: "深入理解与实现RTOS", pages 13 - 15, Retrieved from the Internet <URL:https://www.google.com.hk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwj5t_ua68mBAxVOdPUHHbq5CW0QFnoECA0QAQ&url=https%3A%2F%2Fcommunity.arm.com%2Fcfs-file%2F__key%2Ftelligent-evolution-components-attachments%2F01-2671-00-00-00-00-71-44%2F_2C7B_01_E07A_-_4C5D65510F5F_RTOS_FA574078_.pdf&usg=AOvVaw3SEoIDjfm4MIV2CKbrU17l&opi=89978449> *
刘旭明: "《嵌入式实时操作系统原理与最佳实践》", 机械工业出版社, pages: 1 - 17 *

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111488210A (en) * 2020-04-02 2020-08-04 腾讯科技(深圳)有限公司 Task scheduling method and device based on cloud computing and computer equipment
CN112685156A (en) * 2020-12-28 2021-04-20 北京五八信息技术有限公司 Task execution method and device, electronic equipment and computer readable medium
US11954472B2 (en) * 2021-01-25 2024-04-09 Vmware, Inc. Conflict resolution for device-driven management
CN113094158A (en) * 2021-03-15 2021-07-09 国政通科技有限公司 Service drive calling method, service drive calling device, electronic equipment and storage medium
CN114285901A (en) * 2021-12-17 2022-04-05 中国电信股份有限公司 Network request processing method and device and electronic equipment
CN114764417A (en) * 2022-06-13 2022-07-19 深圳致星科技有限公司 Distributed processing method and device for privacy calculation, privacy data and federal learning
CN114764417B (en) * 2022-06-13 2022-08-26 深圳致星科技有限公司 Distributed processing method and device for privacy calculation, privacy data and federal learning
CN115776524A (en) * 2023-02-10 2023-03-10 广东瑞恩科技有限公司 Internet of things mass data multistage scheduling transmission system for intelligent manufacturing
CN115776524B (en) * 2023-02-10 2023-04-25 广东瑞恩科技有限公司 Multi-level scheduling transmission system for mass data of Internet of things for intelligent manufacturing

Also Published As

Publication number Publication date
CN110554921B (en) 2024-02-09

Similar Documents

Publication Publication Date Title
CN110554921B (en) Time slice distribution method, device, storage medium and computer equipment
CN110569123B (en) Thread allocation method and device, computer equipment and storage medium
CN108845884B (en) Physical resource allocation method, device, computer equipment and storage medium
CN109564528B (en) System and method for computing resource allocation in distributed computing
CN111104208B (en) Process scheduling management method, device, computer equipment and storage medium
CN108123980B (en) Resource scheduling method and system
CN111258745B (en) Task processing method and device
CN113282381A (en) Task scheduling method and device, computer equipment and storage medium
CN111338779B (en) Resource allocation method, device, computer equipment and storage medium
CN111897637B (en) Job scheduling method, device, host and storage medium
US20190286582A1 (en) Method for processing client requests in a cluster system, a method and an apparatus for processing i/o according to the client requests
Dimopoulos et al. Big data framework interference in restricted private cloud settings
CN113886069A (en) Resource allocation method and device, electronic equipment and storage medium
CN114003369A (en) System and method for scheduling commands based on resources
CN112817722A (en) Time-sharing scheduling method based on priority, terminal and storage medium
CN115729705A (en) Distributed task batch processing method, device, equipment and storage medium
CN112527490A (en) Node resource control method and device, electronic equipment and storage medium
CN112114958A (en) Resource isolation method, distributed platform, computer device, and storage medium
CN115686782A (en) Resource scheduling method and device based on solid state disk, electronic equipment and storage medium
CN113742059B (en) Task allocation method, device, computer equipment and storage medium
CN113296957B (en) Method and device for dynamically distributing network bandwidth on chip
CN112685158B (en) Task scheduling method and device, electronic equipment and storage medium
US10180858B2 (en) Parallel computing device, parallel computing system, and job control method
CN115809014A (en) Scheduling control method, device and computer storage medium
CN109857539B (en) Resource scheduling method and terminal

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40019346

Country of ref document: HK

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant