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

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

Info

Publication number
CN110554921B
CN110554921B CN201910819019.1A CN201910819019A CN110554921B CN 110554921 B CN110554921 B CN 110554921B CN 201910819019 A CN201910819019 A CN 201910819019A CN 110554921 B CN110554921 B CN 110554921B
Authority
CN
China
Prior art keywords
task
priority
time slice
tasks
operated
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910819019.1A
Other languages
Chinese (zh)
Other versions
CN110554921A (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 time slice allocation device, a computer readable storage medium and computer equipment, 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 operated; continuously distributing the time slices to high-priority tasks in the tasks to be operated according to the task priorities; the high priority tasks are run within the continuously allocated time slices. Compared with the engineering scheduling mode adopted in the prior art, the scheme provided by the application directly ensures the service quality of the high-priority task from the angle of the kernel time slice, and greatly improves the real-time performance of the scheduled high-priority task.

Description

Time slice distribution method, device, storage medium and computer equipment
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a time slice allocation method, a time slice allocation device, a computer readable storage medium, and a computer device.
Background
In order to improve the execution efficiency of the program, the system core may schedule a time slice of each task based on a fairness policy, so that each task can run equally. In actual service, multiple tasks are usually processed simultaneously, and in order to ensure service quality, some tasks need to be satisfied preferentially.
At present, in the case of simultaneous processing of multiple tasks, the conventional method is to ensure the service quality of the tasks needing to be preferentially satisfied in a resource scheduling manner from the technical engineering point of view. However, this way of engineering scheduling is based on the feedback of data collection such as monitoring, and for tasks that need to be preferentially satisfied, scheduling time has an influence on the tasks, and the real-time performance is low.
Disclosure of Invention
Based on this, it is necessary to provide a time slice allocation method, apparatus, computer readable storage medium and computer device, aiming at the technical problem that the existing method of using engineering dispatch to preferentially satisfy part of tasks has low real-time.
A time slice allocation method, comprising:
acquiring a task to be operated of a time slice to be allocated;
determining task priority corresponding to the task to be operated;
continuously distributing the time slices to high-priority tasks in the tasks to be operated according to the task priorities;
and running the high-priority task in the time slices which are continuously allocated.
A time slice dispensing apparatus, the apparatus comprising:
the task acquisition module is used for acquiring a task to be operated of a time slice to be allocated;
The priority determining module is used for determining the task priority corresponding to the task to be operated;
the time slice distribution module is used for continuously distributing the time slices to the high-priority tasks in the tasks to be operated according to the task priorities;
and the task running module is used for running the high-priority task in the continuously allocated time slices.
A computer readable storage medium storing a computer program which, when executed by a processor, causes the processor to perform the steps of the time slice allocation method described above.
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 perform the steps of the time slice allocation method described above.
According to the time slice distribution method, the time slice distribution device, the computer readable storage medium and the computer equipment, the concept of task priority is introduced into the distribution logic of the time slices, when the task to be operated which needs to be distributed with the time slices is obtained, the time slices are continuously distributed 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 distribution of the time slices is broken, and the high-priority tasks can be preferentially met, so that the high-priority tasks can be operated in the continuously distributed time slices. Compared with the engineering scheduling mode adopted in the prior art, the service quality of the high-priority task is guaranteed directly from the perspective of a kernel time slice, and the real-time performance of the high-priority task to be scheduled is greatly improved.
Drawings
FIG. 1 is a diagram of an application environment for a time slice allocation method in one embodiment;
FIG. 2 is a flow chart of a method of time slice allocation in one embodiment;
FIG. 3 is a schematic diagram illustrating a time slice allocated by a kernel scheduler in a specific application scenario;
FIG. 4 is a schematic diagram of a core scheduler allocation time slice in another specific application scenario;
FIG. 5 is a schematic diagram of a core scheduler allocation time slice in yet another specific application scenario;
FIG. 6 is a schematic diagram of a kernel scheduler allocation time slice in yet another specific application scenario;
FIG. 7 is a schematic diagram of time slices allocated between online and offline tasks in one embodiment;
FIG. 8 is a flow diagram of a method for implementing time slice allocation on a computer device in one embodiment;
FIG. 9 is a flowchart of a method for time slice allocation in one embodiment;
FIG. 10 is a block diagram of a time slice apparatus in one 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 will be further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
Before describing the method embodiments of the present application, description will be first made of related terms referred to in the present application.
Time slice: the CPU (Central Processing Unit ) of the computer device is assigned to the run time of each task. That is, the run time of the CPU is divided into a number of time periods, and each task is assigned a time period called its time slice, i.e., the time that the task is allowed to run, such that the respective tasks are seemingly simultaneous. In general, on a computer device of a Linux operating system, a CPU scheduling policy adopted by a kernel scheduling algorithm is to allocate time slices equally among tasks, that is, allocate time slices for each task in turn, if a certain task is still running at the end of a current time slice, then the next time slice of the current time slice will be allocated to another task, if a task is blocked or ended before the end of the current time slice, then the CPU switches between tasks, so that CPU resource waste is not caused.
Tasks: is a series of computer instructions capable of achieving a particular purpose, a task being either 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, etc., and a process or thread completes a task by executing the computer operations in the task.
FIG. 1 is a diagram of an application environment for a time slice allocation method in one embodiment. 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 be a desktop terminal or a mobile terminal, and the mobile terminal may 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 cluster 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 by the present application. The computer equipment can acquire a task to be operated of a time slice to be allocated; determining task priority corresponding to a task to be operated; continuously distributing the time slices to high-priority tasks in the tasks to be operated according to the task priorities; the high priority tasks are run within the continuously allocated time slices.
As shown in fig. 2, in one embodiment, a time slice allocation method is provided. The present embodiment is mainly exemplified by the application of the method to the computer device 110 in fig. 1. Referring to fig. 2, the time slice allocation method specifically includes the steps of:
S202, acquiring a task to be operated of a time slice to be allocated.
The task to be operated refers to a task which is not executed after being triggered. The computer device needs to allocate the CPU to the task to be executed in time slots to execute the task to be executed by the CPU in the allocated time slots. The duration of each time slice can be set as required, for example, can be generally set to 5ms-800ms.
Because the running time slices of the CPU are distributed in time sequence, one CPU can only execute one task at one moment, and if the current time slice is not finished and a certain task is running, the computer equipment can acquire a plurality of tasks to be run when a plurality of tasks are triggered in the current time slice. For example, a downloading task is running in the current time slice, and at this time, the 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 is running in the current time slice, that is, the CPU is not allocated to any task, when a plurality of tasks are triggered, the computer device acquires a plurality of tasks to be run. For example, when the user triggers the timing task and the deleting task in the current time slice, the timing task and the deleting task are both tasks to be operated.
S204, determining 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 task will be scheduled for execution by the CPU. And, the higher the task priority of a task, the CPU time slices are preferentially allocated to the task according to the time length required by the task operation.
In one embodiment, after acquiring a plurality of tasks to be executed, the computer device may form the same task set according to task priorities of different tasks, where tasks in the task set are identical in probability of being scheduled and executed by the CPU, that is, tasks in the task set formed by the tasks to be executed with high priority are scheduled and executed preferentially, and CPU time slices are distributed uniformly to each task in the same task set. For example, the task A1 and the task A2 belong to the same task set a, the task B1 and the task B2 belong to the same task set B, and the task corresponding to the task belonging to the task set a has higher task priority than the task belonging to the task set B. The computer device may allocate time slices to the task A1 and the task A2 in the task set a first, and allocate time slices to the task B1 and the task B2 after the task A1 and the task A2 are finished.
In one embodiment, the computer device may determine, according to a task type of each task to be executed, a task priority corresponding to the task to be executed. The task types can be divided into an online task and an offline task according to whether the task needs to transmit data through a network, wherein 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 compressing task. The task types can be further divided into time-consuming tasks and quick tasks according to the time required by the task to be executed, wherein the task priority of the time-consuming tasks is lower than that of the quick tasks, for example, the time-consuming tasks are file copy tasks, and the quick tasks are network traffic transmission tasks or disk quick read-write tasks.
S206, continuously distributing the time slices to high-priority tasks in the tasks to be operated according to the task priorities.
The task with the high priority is a task with the highest task priority corresponding to the acquired task to be operated. Specifically, for a high-priority task of the tasks to be run, the computer device may continuously allocate a plurality of consecutive time slices to the high-priority task to ensure that the high-priority task runs preferentially, that is, if the high-priority task has not ended or blocked at the end of the first time slice, continuously allocate a second time slice to the high-priority task, and so on until the high-priority task ends or blocks in advance. After the high priority task blocks or ends in advance, the computer device may allocate the next time slice after the current time to the remaining tasks in the tasks to be run.
The continuous allocation of time slices to high priority tasks is different from the way time slices are evenly allocated. In general, in a uniform allocation manner, the running time of the CPU is the same for all tasks, that is, the kernel schedules each task in turn, and switches to the next task after each task executes a time slice, so that the kernel needs to spend time scheduling different tasks, which further results in lower real-time performance of each task being run. In the application, for the task with high priority, enough time slices are continuously allocated to the task with high priority, so that the task with high priority is preferentially satisfied, and the real-time performance of the task with high priority can be ensured.
And S208, running the high-priority task in the continuously allocated time slices.
In particular, the computer device may run high priority tasks within a continuously allocated time slice. It should be noted that the number of time slices that are continuously allocated is related to the duration of time required for the high priority task to run, and may be less than one time slice, or one of a plurality of time slices. For example, if the task with high priority can be finished in advance or blocked in advance in less than one time slice, the kernel scheduling algorithm can schedule the next task to be operated to be executed immediately, so that CPU resources are not wasted; if the high-priority task needs to occupy a plurality of time slices to run, the rest tasks to be run need to wait continuously.
In one embodiment, the above-mentioned time slice allocation method further includes:
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.
The tasks to be operated are tasks which are remained except for the tasks with high priority, the priorities of the tasks corresponding to the remained tasks are relatively low, the remained tasks can comprise a plurality of tasks, the computer equipment can add the remained tasks in the tasks to be operated to a 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 to the high priority task may be that the high priority task is running out or blocked in advance. When the high priority task is finished running or blocked in advance, the computer device may allocate a time slice after the current time to the task in the task queue.
In one embodiment, the computer device may alternately, evenly distribute the time slices after the current time to the tasks to be run in the task queue. That is, for tasks with relatively low task priorities in the task queue, each time slice can execute a task in a uniform allocation manner, if a certain task is still running when the current time slice is finished, the next time slice of the current time slice will be allocated to another task, so that the task in the task queue can be ensured to acquire the running time of the CPU in turn. Of course, if a task is blocked or ended before the end of the current time slice, the CPU may switch to running the next task immediately in order to avoid wasting CPU resources.
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 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, and the time between any two adjacent time points is a time slice, and the online task a and the offline tasks B1 and B2 are all tasks to be operated at the time. The kernel of the operating system can execute the time slice allocation method provided by the application, the scheduled online task A is preferentially executed, the execution of the scheduling program itself also occupies a small part of time t, after the scheduled online task A, the time slice is continuously allocated to the online task A, the time slice is supposed to be 2 time slices required by the online task A, when the operation of the online task A is finished, the kernel of the operating system can execute the scheduling program again, the scheduled offline task is scheduled to be executed, the time slices are evenly allocated among the offline tasks, namely, the time slices are sequentially switched among the offline tasks B1 and B2 in turn.
According to the time slice distribution method, the concept of the task priority is introduced into the distribution logic of the time slices, when the task to be operated which needs the time slices to be distributed is obtained, the time slices are continuously distributed 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 distribution 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 distributed. Compared with the engineering scheduling mode adopted in the prior art, the service quality of the high-priority task is guaranteed directly from the perspective of a kernel time slice, and the real-time performance of the high-priority task to be scheduled is greatly improved.
In one embodiment, the above-mentioned time slice allocation method further includes the steps of:
checking whether a task is running currently;
if yes, acquiring the task priority of the current task;
and when the task priority of the current task is higher than the task priority corresponding to the task to be operated, continuing to allocate the time slice to the current task, and maintaining operation of the current task in the allocated time slice.
Specifically, since a CPU can only execute one task at a time, after step S204, the computer device may check whether a task is currently running, if not, that is, the CPU is in an initialized state and does not run a certain task, the computer device may execute step S206 and step S208; if the CPU is in a non-initialized state and is running a certain task, the computer equipment can determine the corresponding task priority according to the task type of the task currently running, if the task priority of the current task is higher than the task priority of the task to be running, the time slice is continuously distributed to the current task, namely, if the current task is not finished when the current time slice is finished, the next time slice of the current time slice is continuously distributed to the current task, and the like, the computer equipment can maintain the running of the current task in the time slice which is continuously distributed so as to preferentially meet the running of the current task until the current task is finished or blocked in advance, so that the current task with relatively higher task priority can be preferentially operated.
Similarly, the above-mentioned continuous allocation of the time slices to the current task is different from the uniform allocation of the time slices, and since the task priority of the current task is higher, the time slices are continuously allocated to the current task, so that the task with high priority is preferentially satisfied, and the real-time performance of the task with high priority can be ensured.
In one embodiment, the method further comprises: adding the task to be operated to a task queue; and after the time slice is stopped being distributed to the current task, distributing the time slice to the task to be operated in the task queue.
Specifically, the computer device may add a task to be executed whose task priority is lower than that of the current task to a task queue, where the task to be executed 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 time slice allocation for the current task is that the current task is finished running or blocked in advance. After the running of the current task is finished or blocked in advance, the computer equipment can allocate the time slices after the current moment to the tasks to be run in the task queue.
In one embodiment, the computer device may alternately, evenly distribute the time slices after the current time to the tasks to be run in the task queue. That is, for the task to be operated with relatively low task priority in the task queue corresponding to the current task, each time slice can execute one task to be operated in a uniform allocation manner, and if one task to be operated is still operating when the current time slice is finished, the next time slice of the current time slice is allocated to another task to be operated, so that the task to be operated in the task queue can be ensured to acquire the CPU operation time in turn. Of course, if the task to be run is blocked or ended before the end of the current time slice, in order to avoid wasting CPU resources, the CPU can switch to the next task to be run in the task queue immediately.
In a specific application scenario, the current task is an online task, the task to be operated is an offline task, as shown in fig. 4, when the current CPU is operating the online task a, the offline task B is triggered at time t2 to be used as the task to be operated, the task priority of the online task a is higher than that of the offline task B, if the online task a is not finished or is blocked in advance, the time slice is continuously allocated to the online task a with higher task priority, the online task a is guaranteed to operate preferentially, the time consumption of 3 time slices is required for the task a, when the online task a is finished, the operating system kernel can execute the scheduler again, and schedule the execution of the offline task B in the 4 th time slice, if the offline task B is still running when the 4 th time slice is finished, the operating system kernel can execute the scheduler again, and if the offline task B is blocked or finished before the 4 th time slice is finished, the CPU can schedule the execution of another task promptly.
In one embodiment, the above-mentioned time slice allocation method further includes the steps of:
when the task priority of the current task is lower than the task priority corresponding to the task to be operated, then
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 in the current time slice, whether the current task is ended or blocked in advance in the current time slice, and the computer device may continuously allocate the time slice after the current time slice to the task to be operated with relatively higher task priority, and operate the task to be operated in the continuously allocated time slice, so as to ensure that the task to be operated with relatively higher task priority is preferentially satisfied.
Similarly, the continuous allocation of the time slices after the current time slice to the task to be operated is different from the uniform allocation of the time slices, and because the task to be operated has higher task priority than the current task, the computer equipment continuously allocates enough time slices to the task to be operated, so that the task to be operated with higher task priority is preferentially satisfied, and the instantaneity of the task to be operated can be ensured.
In one embodiment, if the current task ends or blocks in advance in the current time slice, in order to avoid CPU resource waste, the computer device may also continuously allocate the time slice after the current time to the task to be operated, and operate the task to be operated in the continuously allocated time slice.
In one embodiment, the above-mentioned time slice allocation method further includes: shortening the time slice duration for running the low priority task; and running the low-priority task in the shortened time slice.
Specifically, by shortening the time duration 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 shorter, and after the current task is run in the shorter current time slice, the time slice after the current time slice is quickly distributed to the task to be run with relatively higher task priority, so that the task to be run can be ensured to run in the very 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 the CPU time slices for running the tasks, because the high priority tasks may be preferentially satisfied, that is, may be continuously allocated to the time slice for running, and even if the duration of the time slices is short, the high priority tasks may be guaranteed on the runnable time slice duration. The low-priority task can only run in the duration of one time slice, so that the time for which the low-priority task occupies the time slice to run is shorter by shortening the duration of the time slice, and even if the low-priority task occupies the current time slice to run, the running time is very short, the low-priority task can be quickly switched to the high-priority task, namely the high-priority task can be quickly allocated with the time slice after being triggered, and the waiting time is very short, so that the instantaneity of the high-priority task can be ensured.
In a specific application scenario, the current task is an offline task, the task to be operated is an online task, as shown in fig. 5, when the current CPU is operating the offline task B, the online task a is triggered at time t to be used as the task to be operated, the task priority of the online task a is higher than that of the offline task B, the computer device can only operate the offline task B in the current time slice, when the time slice is finished, the computer device can execute the scheduler, and when the time slice is finished, the online task a is continuously scheduled to operate until the online task a is finished or blocked in advance, the computer device can execute the kernel scheduler again to schedule the execution of another task. If offline task B ends or blocks ahead of time within the current time slice, the computer device may switch to online task a as soon as possible.
In one embodiment, the above-mentioned time slice allocation method further includes:
when the task priority of the current task is consistent with the task priority corresponding to the task to be operated, uniformly distributing the time slices between the current task and the task to be operated.
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 allocate the time slices between the current task and the task to be operated in a uniform allocation 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 will be 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 switches to run the task to be run immediately, so that the time slice switches between the current task and the task to be run. The next time slice is taken as the latest "current time slice", and likewise, if the task to be executed is still running at the end of the "current time slice", the next time slice is allocated to another task, namely the "current task" described above. And so on, when a plurality of high-priority tasks or a plurality of low-priority tasks are triggered, time slices can be uniformly distributed among a plurality of tasks with the same task priority, and the tasks with the same priority are guaranteed to have equal instantaneity.
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 run in turn according to time slices, that is, the scheduled task of the kernel of the operating system is obtained in turn, and each scheduled task is executed by the CPU for a time slice. At the end of each time slice, the operating system kernel is triggered to schedule another online task so that the CPU time slices are evenly distributed between online task A and online task B.
FIG. 7 is a schematic diagram of time slices allocated between online tasks and offline tasks in one embodiment. The task priority of the online task is higher than that of the offline task, so that the real-time performance of the online task is guaranteed, and when CPU time slices are distributed, the online task can be preferentially guaranteed in the time slices which can be distributed and the time slices which can be operated. Referring to fig. 7, a dotted line box indicates that the CPU is in an initialized state, a solid line box indicates that the CPU is in an operating state, the initialized state is a state opposite to the operating state, and the initialized state indicates that a CPU time slice is unassigned. When the CPU is in an initialized state (top left of FIG. 7), if an online task is triggered, a CPU time slice may be assigned to the online task (top right 4 of FIG. 7). When the CPU is in an initialized state (top left of FIG. 7), if an offline task is triggered, a CPU time slice may be assigned to the offline task (bottom left of FIG. 7). When the CPU is in an operation state and occupied by an online task (upper right of fig. 7), if the offline task is triggered, the CPU can be distributed to the offline task after being released by waiting for the end or blocking in advance of the online task (lower right of fig. 7). When the CPU is in an operating state and the CPU is occupied by an 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 operation of the online task (lower right in fig. 7). When the CPU is in an operation state and the CPU runs an online task and an offline task simultaneously (as shown in fig. 7, the online task can preempt a time slice of the offline task (as shown in fig. 7, right-hand upper part) if the online task is triggered, and the time slice can be allocated to the offline task after the CPU is released (as shown in fig. 7, left-hand lower part) if the offline task is triggered, the CPU needs to wait 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 on the picture to view, and actually viewing the picture triggers two tasks, namely, a picture downloading task and a picture compressing task. Obviously, the task of downloading the picture belongs to an online task, and from the viewpoint of user experience, the real-time performance of the task needs to be ensured, and the task of compressing the picture is an offline task running locally by a user terminal. In order to ensure the real-time performance of the picture downloading task, the time slice distribution method provided by the application can be adopted to continuously distribute the CPU time slices to the picture downloading task, ensure the priority operation of the picture downloading task, and distribute the CPU time slices to the picture compression task when the picture downloading task is completed or blocked due to the network and other reasons, namely, the CPU is switched to execute the picture compression task. And for uniformly distributing the time slices between the picture downloading task and the picture compressing task, the instantaneity of the picture downloading task can be improved, and the user experience is improved.
In one embodiment, the time slice allocation method provided in the present application may be implemented in the following manner, and the effect of the time slice allocation method provided in the present application is verified. As shown in fig. 8, the method specifically comprises the following steps:
S802, a kernel scheduler capable of executing the time slice allocation method provided by the application runs on computer equipment.
S804, the computer equipment is docker-typed, and the offline tasks are deployed on the computer equipment in a docker mirror image mode.
S806, running the online task on the computer device on which the offline task has been run.
S808, monitoring the running process of the online task. For example, monitoring whether the running success probability of the online task meets a preset threshold; if yes, go to step S810; if not, go to step S812.
S810, counting the running delay of the online task, and judging whether the duty ratio of the online task with the maximum delay of 1% is increased or not; if yes, go to step S812; if not, go to step S814.
S812, off-line tasks are carried out. Off-line tasks are put off 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 mixed part of the on-line tasks and the off-line tasks is realized.
S814, maintaining the online task and the offline task running in the upmix of the computer device.
In the embodiment, a mixed part of an online task and an offline task is realized, and the offline task basically occupies 80% of a CPU, so that resource waste is avoided. Although the offline task occupies 80%, the real-time performance of online service of the online task and the offline task in the process of the up-mixed part operation of the computer equipment is ensured by monitoring the time delay, the success rate and the maximum time delay of 1% in the operation process of the online task, so that the user experience can be improved.
As shown in fig. 9, in a specific embodiment, the time slice allocation method includes the steps of:
s902, acquiring a task to be operated of a time slice to be allocated.
S904, determining the task type of the task to be operated.
S906, determining task priority corresponding to the task to be operated according to the task type.
S908 checks whether a task is currently running. If not, go to step S910; if yes, go to step S912.
S910, continuously distributing the time slices to high-priority tasks in the tasks to be operated according to the task priorities; the high priority tasks are run within the continuously 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;
s916, when the task priority of the current task is higher than the task priority corresponding to the task to be operated, continuing to distribute the time slices to the current task, and maintaining operation of the current task in the distributed time slices.
S918, adding the task to be operated to a task queue; and after the time slice is stopped being distributed to the current task, distributing the time slice to the task 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 continuously distributed time slices.
S922, if the task priority of the current task is consistent with the task priority corresponding to the task to be operated, the time slices are evenly distributed between the current task and the task to be operated.
According to the time slice distribution method, the concept of the task priority is introduced into the distribution logic of the time slices, when the task to be operated which needs the time slices to be distributed is obtained, the time slices are continuously distributed 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 distribution 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 distributed. Compared with the engineering scheduling mode adopted in the prior art, the service quality of the high-priority task is guaranteed directly from the perspective of a kernel time slice, and the real-time performance of the high-priority task to be scheduled is greatly improved.
Fig. 9 is a flow chart illustrating a method of allocating time slices in an 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 strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in fig. 9 may include multiple sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, or the order in which the sub-steps or stages are performed is not necessarily sequential, but may be performed in rotation or alternatively with at least a portion of the sub-steps or stages of other steps or steps.
In one embodiment, as shown in fig. 10, a time slice allocation apparatus 1000 is provided, which includes a task acquisition module 1002, a priority determination module 1004, a time slice allocation module 1006, and a task execution module 1008, wherein:
a task obtaining module 1002, configured to obtain a task to be executed of a time slice to be allocated;
a priority determining module 1004, configured to determine a task priority corresponding to a task to be run;
a time slice allocation module 1006, configured to allocate time slices to high-priority tasks in the tasks to be run continuously according to task priorities;
a task running module 1008 for running high priority tasks within the continuously allocated time slices.
In one embodiment, the priority determining module 1004 is further configured to determine a task type of the task to be executed; 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 the remaining tasks in the tasks to be run 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.
In one embodiment, the time slice apparatus 1000 further includes:
The checking module is used for checking whether a task is running currently or not; if yes, 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, allocate the time slice to the current task continuously, and maintain the execution of the current task in the allocated time slice.
In one embodiment, the time slice allocation module 1006 is further configured to add the task to be run to a task queue; and after the time slice is stopped being distributed to the current task, distributing the time slice to the task to be operated in the task queue.
In one embodiment, the time slice allocation module 1006 is further configured to: 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 continuously distributed time slices.
In one embodiment, the time slice allocation apparatus 1000 further includes a time slice shortening module for shortening a duration of a time slice for running the low priority task; the task running module 1008 is configured to run low priority tasks in a shortened time slice.
In one embodiment, the time slice allocation module 1006 is further configured to, when the task priority of the current task is consistent with the task priority corresponding to the task to be executed, evenly allocate the time slices between the current task and the task to be executed.
In one embodiment, the tasks to be run include an online task and an offline task, the online task having a higher task priority than the offline task.
In the above-mentioned time slice allocation device 1000, in the allocation logic of the time slices, the concept of task priority is introduced, when the task to be run requiring the time slices to be allocated is obtained, according to the task priority of the task to be run, the time slices are continuously allocated to the high priority task in the task to be run, so as to break the principle of fair allocation of the time slices, so that the high priority task can be preferentially satisfied, and thus the high priority task can be run 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 guaranteed directly from the perspective of a kernel time slice, and the real-time performance of the high-priority task to be scheduled is greatly improved.
FIG. 11 illustrates an internal block diagram of a computer device in one embodiment. The computer device may be specifically the computer device 110 of fig. 1. As shown in fig. 11, the computer device includes a processor, a memory, and a network interface connected by a system bus. The memory includes a nonvolatile 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 that, when executed by a processor, causes the processor to implement a time slice allocation method. The internal memory may also have stored therein a computer program which, when executed by the processor, causes the processor to perform the time slice allocation method.
It will be appreciated by those skilled in the art that the structure shown in fig. 11 is merely a block diagram of a portion of the structure associated with the present application and is not limiting of the computer device to which the present application applies, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In one embodiment, the time slice apparatus 1000 provided herein may be implemented in the form of a computer program that is executable on a computer device as shown in fig. 11. The memory of the computer device may store various program modules that make up the time slice allocation apparatus, such as the task acquisition module 1002, the priority determination module 1004, the time slice allocation module 1006, and the task execution module 1008 shown in fig. 10. The computer program constituted by the respective program modules causes the processor to execute the steps in the time slice allocation method of the respective embodiments of the present application described in the present specification.
For example, the computer apparatus shown in fig. 11 may perform step S202 by the task acquisition module 1002 in the time slice allocation apparatus as shown in fig. 10. The computer device may perform step S204 through the priority determination module 1004. The computer device may perform step S206 by the time slice allocation module 1006. The computer device may perform step S208 through the task execution module 1008.
In one embodiment, a computer device is provided that includes 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 above-described time slice allocation method. The steps of the time slice allocation method herein may be the steps in the time slice allocation method of the above-described respective embodiments.
In one embodiment, a computer readable storage medium is provided, storing a computer program which, when executed by a 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 the steps in the time slice allocation method of the above-described respective embodiments.
Those skilled in the art will appreciate that all or part of the processes in the methods of the above embodiments may be implemented by a computer program for instructing relevant hardware, where the program may be stored in a non-volatile computer readable storage medium, and where the program, when executed, may include processes in the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the various embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile 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), memory bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples only represent a few embodiments of the present application, which are described in more detail and are not to be construed as limiting the scope of the present application. It should be noted that it would be apparent to those skilled in the art that various modifications and improvements could be made without departing from the spirit of the present application, which would be within the scope of the present application. Accordingly, the scope of protection of the present application is to be determined by the claims appended hereto.

Claims (14)

1. A time slice allocation method, comprising:
acquiring a task to be operated of a time slice to be allocated;
checking whether a task is running currently;
if yes, acquiring the task priority of the current task;
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 a current time slice, continuously distributing the time slices after the current time slice to the task to be operated, and operating the task to be operated in the continuously distributed time slices;
The method further comprises the steps of:
shortening the time slice duration for running the low priority task;
running the low-priority task in the shortened time slice;
under the condition that the running success probability corresponding to the high-priority task accords with a preset threshold value, counting the running delay of the high-priority task, and judging whether the duty ratio of the high-priority task with the maximum running delay is increased or not according to the running delay;
if yes, putting down the low-priority task which is mixed and deployed with the high-priority task;
if not, maintaining the mixed operation of the high-priority task and the low-priority task;
the high-priority tasks are online tasks, the low-priority tasks are offline tasks, and the task priority of the online tasks is higher than that of the offline tasks.
2. The method according to claim 1, wherein the method further comprises:
determining the task type of the task to be operated;
and determining the task priority corresponding to the task to be operated according to the task type.
3. The method according to claim 1, wherein the method further comprises:
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 according to claim 1, wherein the method further comprises:
when the task priority of the current task is higher than the task priority corresponding to the task to be operated, then
And continuing to allocate the time slices to the current task, and maintaining running the current task in the allocated time slices.
5. The method according to claim 4, wherein the method further comprises:
adding the task to be operated to a task queue;
and after the time slice is stopped being distributed to the current task, distributing the time slice to the task to be operated in the task queue.
6. The method according to claim 1, wherein the method further comprises:
when the task priority of the current task is consistent with the task priority corresponding to the task to be operated, then
And evenly distributing time slices between the current task and the task to be operated.
7. A time slice dispensing apparatus, said apparatus comprising:
the task acquisition module is used for acquiring a task to be operated of a time slice to be allocated;
The priority determining module is used for checking whether a task is running currently or not, and if yes, acquiring the task priority of the current task;
the task operation module is used for operating the current task in the current time slice when the task priority of the current task is lower than the task priority corresponding to the task to be operated;
the time slice distribution module is used for continuously distributing the time slices after the current time slice to the task to be operated;
the task operation module is used for operating the task to be operated in the continuously allocated time slices;
the time slice shortening module is used for shortening the time slice duration for running the low-priority task and running the low-priority task in the shortened time slice;
the task monitoring module is used for counting the running delay of the high-priority task under the condition that the running success probability corresponding to the high-priority task is monitored to be in accordance with a preset threshold value, and judging whether the duty ratio of the high-priority task with the maximum running delay is increased or not according to the running delay; if yes, putting down the low-priority task which is mixed and deployed with the high-priority task; if not, maintaining the mixed operation of the high-priority task and the low-priority task;
The high-priority tasks are online tasks, the low-priority tasks are offline tasks, and the task priority of the online tasks is higher than that of the offline tasks.
8. The apparatus of claim 7, wherein the priority determining module is further configured to determine a task type of the task to be executed, and determine a task priority corresponding to the task to be executed according to the task type.
9. The apparatus of claim 7, wherein the time slice allocation module is further configured to add remaining tasks of the tasks to be run 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.
10. The apparatus of claim 7, wherein the time slice allocation module is further configured to, when a task priority of a current task is higher than a task priority corresponding to the task to be executed, continue allocating a time slice to the current task, and maintaining execution of the current task for the allocated time slice.
11. The apparatus of claim 10, wherein the time slice allocation module is further configured to add the task to be run to a task queue; and after the time slice is stopped being distributed to the current task, distributing the time slice to the task to be operated in the task queue.
12. The apparatus of claim 7, wherein the time slice allocation module is further configured to, when a task priority of a current task is consistent with a task priority corresponding to the task to be executed, evenly allocate time slices between the current task and the task to be executed.
13. A computer readable storage medium storing a computer program which, when executed by a processor, causes the processor to perform the steps of the method of any one of claims 1 to 6.
14. 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 of any of claims 1 to 6.
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 CN110554921A (en) 2019-12-10
CN110554921B true 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)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111488210B (en) * 2020-04-02 2023-04-07 腾讯科技(深圳)有限公司 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
US11526341B2 (en) * 2021-01-25 2022-12-13 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
CN114764417B (en) * 2022-06-13 2022-08-26 深圳致星科技有限公司 Distributed processing method and device for privacy calculation, privacy data and federal learning
CN115776524B (en) * 2023-02-10 2023-04-25 广东瑞恩科技有限公司 Multi-level scheduling transmission system for mass data of Internet of things for intelligent manufacturing

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 (1)

* Cited by examiner, † Cited by third party
Title
刘旭明.《嵌入式实时操作系统原理与最佳实践》.机械工业出版社,2014,第1-17页. *

Also Published As

Publication number Publication date
CN110554921A (en) 2019-12-10

Similar Documents

Publication Publication Date Title
CN110554921B (en) Time slice distribution method, device, storage medium and computer equipment
CN110297711B (en) Batch data processing method, device, computer equipment and storage medium
CN110569123B (en) Thread allocation method and device, computer equipment and storage medium
CN108845884B (en) Physical resource allocation method, device, computer equipment and storage medium
Shah et al. The MDS queue: Analysing the latency performance of erasure codes
CN109936604B (en) Resource scheduling method, device and system
CN109918184B (en) Picture processing system, method and related device and equipment
CN109564528B (en) System and method for computing resource allocation in distributed computing
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
Wang et al. A throughput optimal algorithm for map task scheduling in mapreduce with data locality
CN113282381A (en) Task scheduling method and device, computer equipment and storage medium
Dimopoulos et al. Big data framework interference in restricted private cloud settings
CN113886069A (en) Resource allocation method and device, electronic equipment and storage medium
CN111258741B (en) Warehouse task execution method, distributed server cluster and computer equipment
CN112860387A (en) Distributed task scheduling method and device, computer 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
CN113742059B (en) Task allocation method, device, computer equipment and storage medium
CN113296957B (en) Method and device for dynamically distributing network bandwidth on chip
CN115729705A (en) Distributed task batch processing method, device, equipment and storage medium
CN111556126B (en) Model management method, system, computer device and storage medium
CN115809014A (en) Scheduling control method, device and computer storage medium
KR101915945B1 (en) A Method for processing client requests in a cluster system, a Method and an Apparatus for processing I/O according to the client requests
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