Task scheduling
Abstract
One or more implementations of the present specification provide a task scheduling method and apparatus, and relate to the field of computer technologies. The method includes: determining a target task queue from a plurality of pre-constructed task queues, the plurality of pre-constructed task queues being used respectively to store tasks with different priorities, each task queue having a respective scheduling weight, and the scheduling weight being used to control a probability that the task queue is determined as the target task queue; and scheduling a target task in the target task queue to a specified thread in a thread pool, to execute the target task. In the implementations of the present specification, execution of tasks with different priorities can be properly coordinated, thereby avoiding resource contention among the tasks with different priorities in a task scheduling process.
Claims
exact text as granted — not AI-modifiedWhat is claimed is:
1 . A task scheduling method, comprising: determining a target task queue from a plurality of task queues, the plurality of task queues configured to respectively store tasks with different priorities, each task queue having a respective scheduling weight, and the scheduling weight related to a probability that the task queue is determined as the target task queue; and scheduling a target task in the target task queue to a thread in a thread pool, to execute the target task.
2 . The method according to claim 1 , wherein the thread pool includes a first thread and a second thread, and the first thread and the second thread are configured respectively to execute tasks with different priorities; and the scheduling the target task in the target task queue to the thread in the thread pool includes: scheduling the target task to one of the first thread or the second thread based on a priority of the target task.
3 . The method according to claim 2 , wherein the first thread is configured to execute a task with a highest priority stored in the plurality of task queues, the second thread is configured to execute a task with a priority other than the highest priority stored in the plurality of task queues, and a quantity of the first thread is less than or equal to a quantity of the second thread.
4 . The method according to claim 2 , further comprising: determining a total quantity of the plurality of threads in the thread pool; and configuring at least half of the plurality of threads in the thread pool as second threads.
5 . The method according to claim 4 , wherein the determining the total quantity of the plurality of threads in the thread pool includes: preliminarily determining the total quantity of the plurality of threads; predicting, based on the total quantity of threads preliminarily determined, a total memory usage during execution of tasks stored in the plurality of task queues; and in response to the total memory usage exceeding a memory limit, reducing the total quantity of the plurality of threads until the total memory usage predicted satisfies the memory limit.
6 . The method according to claim 5 , wherein the tasks stored in the plurality of pre-constructed task queues are subtasks of a compaction task; and the predicting, based on the total quantity of threads preliminarily determined, the total memory usage during execution of the tasks stored in the plurality of pre-constructed task queues includes: separately predicting macroblock buffer memory usage, macroblock meta information memory usage, deep copy memory usage, and prestored array memory usage that are generated during execution of the compaction task; multiplying a sum of the macroblock buffer memory usage and the macroblock meta information memory usage by a quantity of the compaction task, to obtain a first product; multiplying a sum of the deep copy memory usage and the prestored array memory usage by the total quantity of threads preliminarily determined, to obtain a second product; and adding the first product and the second product to obtain the total memory usage.
7 . The method according to claim 1 , wherein the probability that the task queue is determined as the target task queue is positively correlated with a priority of a task stored in the task queue.
8 . The method according to claim 1 , wherein the scheduling weight is configured by using a weight coefficient interval, and a size of the weight coefficient interval corresponding to each task queue is positively correlated with a priority of a task stored in the task queue; and the determining the target task queue from the plurality of task queues includes: generating a random weight coefficient; and determining a task queue corresponding to a weight coefficient interval within which the random weight coefficient falls as the target task queue.
9 . An electronic device, comprising: one or more processors; and one or more storage devices, individually or collectively having computer executable instructions stored thereon, the computer executable instructions, when executed by the one or more processors, enabling the one or more processors to, individually or collectively, implement acts including: determining a target task queue from a plurality of task queues, the plurality of task queues configured to respectively store tasks with different priorities, each task queue having a respective scheduling weight, and the scheduling weight related to a probability that the task queue is determined as the target task queue; and scheduling a target task in the target task queue to a thread in a thread pool, to execute the target task.
10 . The electronic device according to claim 9 , wherein the thread pool includes a first thread and a second thread, and the first thread and the second thread are configured respectively to execute tasks with different priorities; and the scheduling the target task in the target task queue to the thread in the thread pool includes: scheduling the target task to one of the first thread or the second thread based on a priority of the target task.
11 . The electronic device according to claim 10 , wherein the first thread is configured to execute a task with a highest priority stored in the plurality of task queues, the second thread is configured to execute a task with a priority other than the highest priority stored in the plurality of task queues, and a quantity of the first thread is less than or equal to a quantity of the second thread.
12 . The electronic device according to claim 10 , wherein the acts include: determining a total quantity of the plurality of threads in the thread pool; and configuring at least half of the plurality of threads in the thread pool as second threads.
13 . The electronic device according to claim 12 , wherein the determining the total quantity of the plurality of threads in the thread pool includes: preliminarily determining the total quantity of the plurality of threads; predicting, based on the total quantity of threads preliminarily determined, a total memory usage during execution of tasks stored in the plurality of task queues; and in response to the total memory usage exceeding a memory limit, reducing the total quantity of the plurality of threads until the total memory usage predicted satisfies the memory limit.
14 . The electronic device according to claim 13 , wherein the tasks stored in the plurality of pre-constructed task queues are subtasks of a compaction task; and the predicting, based on the total quantity of threads preliminarily determined, the total memory usage during execution of the tasks stored in the plurality of pre-constructed task queues includes: separately predicting macroblock buffer memory usage, macroblock meta information memory usage, deep copy memory usage, and prestored array memory usage that are generated during execution of the compaction task; multiplying a sum of the macroblock buffer memory usage and the macroblock meta information memory usage by a quantity of the compaction task, to obtain a first product; multiplying a sum of the deep copy memory usage and the prestored array memory usage by the total quantity of threads preliminarily determined, to obtain a second product; and adding the first product and the second product to obtain the total memory usage.
15 . The electronic device according to claim 9 , wherein the probability that the task queue is determined as the target task queue is positively correlated with a priority of a task stored in the task queue.
16 . The electronic device according to claim 9 , wherein the scheduling weight is configured by using a weight coefficient interval, and a size of the weight coefficient interval corresponding to each task queue is positively correlated with a priority of a task stored in the task queue; and the determining the target task queue from the plurality of task queues includes: generating a random weight coefficient; and determining a task queue corresponding to a weight coefficient interval within which the random weight coefficient falls as the target task queue.
17 . A computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and when the computer instructions are executed by one or more processors, the computer instructions enable the one or more processors to, individually or collectively, implement acts comprising: determining a target task queue from a plurality of task queues, the plurality of task queues configured to respectively store tasks with different priorities, each task queue having a respective scheduling weight, and the scheduling weight related to a probability that the task queue is determined as the target task queue; and scheduling a target task in the target task queue to a thread in a thread pool, to execute the target task.
18 . The computer-readable storage medium according to claim 17 , wherein the thread pool includes a first thread and a second thread, and the first thread and the second thread are configured respectively to execute tasks with different priorities; and the scheduling the target task in the target task queue to the thread in the thread pool includes: scheduling the target task to one of the first thread or the second thread based on a priority of the target task.
19 . The computer-readable storage medium according to claim 18 , wherein the first thread is configured to execute a task with a highest priority stored in the plurality of task queues, the second thread is configured to execute a task with a priority other than the highest priority stored in the plurality of task queues, and a quantity of the first thread is less than or equal to a quantity of the second thread.
20 . The computer-readable storage medium according to claim 17 , where the acts comprise: preliminarily determining a total quantity of the plurality of threads; predicting, based on the total quantity of threads preliminarily determined, a total memory usage during execution of tasks stored in the plurality of task queues; and in response to the total memory usage exceeding a memory limit, reducing the total quantity of the plurality of threads until the total memory usage predicted satisfies the memory limit.Cited by (0)
No later patents cite this yet.
References (0)
No backward citations on record.