Task scheduling method and device
Through the task scheduling method based on core scheduling scheduling algorithm and preset rules, the problems of poor elasticity, poor adaptability and large overhead in the existing CPU business hybrid deployment technology are solved, and timely preemption of high-end tasks and hyperthread isolation are achieved. Adapt to the latest version of Linux kernel, ensuring the quality and performance of online business.
Patent Information
- Application Number
- CN202411027062.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2024-11-15
AI Technical Summary
The existing hybrid deployment technology of CPU services has problems such as poor core binding solution flexibility, Group Identity cannot be applied to the new version of Linux kernel, high adaptation cost of BT scheduling algorithms, and high overhead of throttle mechanism technology, making it difficult to effectively guarantee high-priority online services. quality.
By obtaining the task queue for hybrid deployment, prioritization is determined based on the task's cookie value, and task scheduling is carried out based on the core scheduling scheduling algorithm and preset rules, the timely preemption of high-optimal tasks on low-optimal tasks and prevention of hyper-threaded interference by high-optimal tasks, and using core The hyperthreaded isolation mechanism of the scheduling scheduling strategy is adapted to the latest version of the Linux kernel.
It realizes timely preemption and hyperthread isolation of high-end tasks for low-end tasks in hybrid deployment scenarios, avoids interference from low-end services to high-end services, has higher compatibility and lower adaptation costs, and ensures the performance of online services. and quality.
Smart Images

Figure CN118963945A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of Internet technology, and in particular, to a task scheduling method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art
[0002] CPU services can be divided into online services and offline services in production practice. In order to make full use of CPU resources, different types of services will be mixed on the CPU, but mixed service running may not guarantee the quality of high-priority online services. Therefore, the industry has been working hard to ensure the priority of online services and make full use of CPU resources.
[0003] The mainstream CPU service hybrid deployment technologies in the industry can be divided into core binding solutions, Group Identity, BT scheduling algorithm, throttle mechanism to limit offline tasks, etc. However, the core binding solution has the problem of poor elasticity, the Group Identity solution has the problem of not being directly applicable to the new version of the Linux kernel, the BT solution has the problem of high cost of adapting the new version of the Linux kernel, and the throttle mechanism has the problem of too much technical implementation overhead.
[0004] It should be noted that the above content is not necessarily prior art, nor is it intended to limit the scope of patent protection of this application. Summary of the invention
[0005] Embodiments of the present application provide a task scheduling method, apparatus, computer device, computer-readable storage medium, and computer program product to solve or alleviate one or more of the technical problems raised above.
[0006] One aspect of an embodiment of the present application provides a task scheduling method, the method comprising:
[0007] Get a hybrid deployment task queue, where the task queue contains at least one task, and each task has a one-to-one corresponding cookie value;
[0008] Determine the priority of each task according to the cookie value;
[0009] Based on the core scheduling algorithm, the tasks in the task queue are scheduled according to the priority and preset rules, wherein the preset rules are used for timely preemption of low-priority tasks by high-priority tasks and prevention of hyperthreading interference.
[0010] Optionally, before the step of obtaining the hybrid deployed task queue, the method further includes:
[0011] receiving a configuration request for a task to be performed;
[0012] In response to the configuration request, a cookie value corresponding to the task to be executed is configured.
[0013] Optionally, in response to the configuration request, configuring a cookie value corresponding to the task to be executed includes:
[0014] In the case where the configuration request carries the priority of the task to be executed, the cookie value corresponding to the task to be executed is configured as a first-class interface value; or,
[0015] When the configuration request does not carry the priority level of the task to be executed, the cookie value corresponding to the task to be executed is configured as a second-class interface value, and the second-class interface value represents the native logic supporting the core scheduling algorithm.
[0016] Optionally, the preset rule includes a timely preemption rule, and the core scheduling algorithm is based on which the tasks in the task queue are scheduled according to the priority and the preset rule, including:
[0017] Based on the core scheduling algorithm, when the priority corresponding to the first task that needs to be executed is high priority and the priority corresponding to the second task being executed is low priority, the first task is scheduled to preempt the second task according to the timely preemption rule.
[0018] Optionally, the task scheduling method is applied to a physical core including a first logical core and a second logical core, and the preset rules further include: no isolation is performed for tasks of non-strict mixed deployment, and low-priority tasks are isolated for strict high-priority tasks.
[0019] Optionally, the scheduling of tasks in the task queue according to the priority and preset rules based on the core scheduling algorithm further includes:
[0020] Based on the core scheduling algorithm, when the priority corresponding to the task currently executed on the first logical core is a strict high priority, the execution of the low-priority task on the second logical core is abandoned.
[0021] Optionally, the scheduling of tasks in the task queue according to the priority and preset rules based on the core scheduling algorithm further includes:
[0022] When the priority corresponding to the task currently executed on the first logical core is a strict high priority and there are only low priority tasks in the task queue corresponding to the second logical core, the preset idle task is executed on the second logical core.
[0023] Another aspect of an embodiment of the present application provides a task scheduling device, the device comprising:
[0024] A task queue acquisition module is used to acquire a hybrid deployed task queue, wherein the task queue contains at least one task, and each task has a one-to-one corresponding cookie value;
[0025] A priority determination module, used to determine the priority corresponding to each task according to the cookie value;
[0026] The task scheduling module is used to schedule the tasks in the task queue according to the priority and preset rules based on the core scheduling scheduling algorithm, wherein the preset rules are used for timely preemption of low-priority tasks by high-priority tasks and prevention of hyperthreading interference.
[0027] Another aspect of an embodiment of the present application provides a computer device, including:
[0028] at least one processor; and
[0029] a memory communicatively coupled to the at least one processor;
[0030] Wherein: the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the task scheduling method as described above.
[0031] Another aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the task scheduling method described above is implemented.
[0032] Another aspect of an embodiment of the present application provides a computer program product, including a computer program, which implements the task scheduling method described above when executed by a processor.
[0033] The technical solution adopted in the embodiment of the present application may include the following advantages: by pre-configuring a cookie value for an online or offline task, the cookie value can not only be used as a mark of the task priority, but also the high-priority task will ignore some scheduling rules when scheduling tasks, ensuring the timely preemption of the low-priority task, and can also utilize the hyperthreading isolation mechanism of the core scheduling scheduling strategy itself, and through preset rules, realize the expulsion of the low-priority service from the strict high-priority service on a pair of hyperthreads. At the same time, by utilizing the cookie field of the process in the core scheduling scheduling strategy and adding custom preset rules, the high- and low-priority classification of the process is realized, and the hyperthreading interference of the low-priority service on the strict high-priority service is avoided. Even in the latest version of the Linux kernel where the scheduler has been greatly modified, the logic of corescheduling exists, so it is more compatible with the new version of the kernel, less invasive, and has a lower adaptation cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The accompanying drawings exemplarily illustrate the embodiments and constitute a part of the specification, and together with the text description of the specification, are used to explain the exemplary implementation of the embodiments. The embodiments shown are for illustrative purposes only and do not limit the scope of the claims. In all drawings, the same reference numerals refer to similar but not necessarily identical elements.
[0035] Figure 1 The following schematically shows an operating environment diagram of a task scheduling method according to Embodiment 1 of the present application;
[0036] Figure 2 A flowchart of a task scheduling method according to Embodiment 1 of the present application is schematically shown;
[0037] Figure 3 A schematic diagram of a cgroup interface classification framework is shown schematically;
[0038] Figure 4 A schematic diagram schematically shows a high-priority process preempting a low-priority process;
[0039] Figure 5 A schematic diagram of the ready task queues on CPU0 and CPU1 is shown schematically;
[0040] Figure 6 The schematic diagram schematically shows the task matching on CPU0 and CPU1;
[0041] Figure 7 A schematic diagram showing task matching on CPU1 is shown schematically;
[0042] Figure 8 The schematic diagram schematically shows that there is no task matching on CPU1;
[0043] Fig. 9 A framework diagram of a task scheduling method is schematically shown;
[0044] Fig.10 A schematic diagram schematically shows a preset rule;
[0045] Fig.11 The schematic diagram shows the delay of a single online service.
[0046] Fig.12 The schematic diagram shows the delay of online services when services are running simultaneously without isolation.
[0047] Fig.13 The schematic diagram shows the delay of online services when services are mixed after resource isolation;
[0048] Fig.14 A block diagram schematically shows a task scheduling device according to the second embodiment of the present application; and
[0049] Fig.15 The hardware architecture diagram of the computer device according to the third embodiment of the present application is schematically shown. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0051] It should be noted that the descriptions involving "first", "second", etc. in the embodiments of the present application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0052] In the description of the present application, it should be understood that the numerical labels before the steps do not indicate the order in which the steps are executed, but are only used to facilitate the description of the present application and to distinguish each step, and therefore should not be understood as a limitation on the present application.
[0053] First, the following terms are explained:
[0054] Linux kernel: is an open source operating system kernel, the core of the operating system, responsible for managing the system's hardware and software resources.
[0055] Cgroup: Control group is a function in the Linux kernel used to uniformly monitor and limit resources for process groups.
[0056] CPU: Central Processing Unit, as the computing and control core of the computer system, is the final execution unit for information processing and program running. CPU is not equal to physical core, let alone logical core.
[0057] CPU physical core: The real CPU core that can be seen. The number of cores can be seen at the hardware level. It has independent circuit elements and L1 and L2 caches and can execute instructions independently.
[0058] CPU logical core: a core at the logical level within the same physical core. The physical core uses high-speed computing to make the application program think that there are two CPUs operating.
[0059] HT: Hyper-threading. Hyper-threading can allocate time slices to another logical core when one logical core is waiting for instruction execution (waiting to get the next instruction from cache or memory). High-speed switching between the two logical cores makes the application unaware of the interval and mistakenly thinks that it has monopolized one core. Intel-based hyper-threading technology can split a physical core into two logical cores, execute CPU instructions more efficiently and utilize L1 cache.
[0060] Hybrid deployment: For CPUs, hybrid deployment means deploying online services (usually latency-sensitive high-priority tasks) and offline tasks (usually latency-insensitive low-priority tasks) of different priorities on the same CPU to share CPU resources.
[0061] Core Scheduling: It is an improvement to the kernel's CPU scheduler, used to control which processes can run simultaneously on the same CPU physical core. In terms of technical implementation, different cookie values are assigned to different tasks, and when selecting tasks, the cookie values are checked to see if they are equal to isolate untrusted tasks. For example: a physical core is divided into two logical cores, and the two logical cores are hyperthreaded to each other. If there are three tasks A (cookie = x), B (cookie = y), and C (cookie = z), the corescheduling strategy can achieve that when task A is running on logical core 1, tasks B and C will not run on logical core 2, thus achieving the purpose of isolation.
[0062] Secondly, in order to facilitate those skilled in the art to understand the technical solutions provided in the embodiments of the present application, the relevant technologies are described below:
[0063] CPU services can be divided into online services and offline services in production practice. In order to make full use of CPU resources, different types of services will be mixed on the CPU, but mixed service running may not guarantee the quality of high-priority online services. Therefore, the industry has been working hard to ensure the priority of online services and make full use of CPU resources.
[0064] The mainstream CPU business colocation technologies in the industry can be divided into core binding solutions, Group Identity, BT scheduling algorithms, and throttle mechanisms to limit offline tasks. The core binding solution reduces the impact on online business by binding some fixed CPU logical cores to offline business and setting a smaller cpu.share; Group Identity sets different identities for each CPU cgroup to distinguish the priorities of process tasks in different CPU cgroups; the BT scheduling algorithm designs a dedicated offline scheduling class for offline business by adding a scheduling class to distinguish high and low priorities of business; the throttle mechanism restricts offline tasks and adds the cfs_rq corresponding to the offline group to a global percpu linked list throttle_list, thereby completely giving CPU resources to online tasks.
[0065] However, the current colocation technology in the industry has the following problems in implementation:
[0066] 1. The core binding technology needs to bind cores to online or offline services. On the one hand, it does not achieve true CPU isolation. When the service load is heavy, the impact on online services is still very serious. On the other hand, due to the binding of cores, the elasticity is poor.
[0067] 2. With the update of Linux kernel version, the core scheduling technology was introduced in the 5.15 version scheduler, and the CFS scheduler logic was replaced by the EEVDF scheduler after the 6.6 version. The hyperthreading isolation technology in the Group identity technology based on the 5.10 version was replaced by core scheduling and cannot be directly applied to the new kernel;
[0068] 3. The BT scheduling algorithm guarantees the priority of services by adding offline scheduling classes, but its open source solution cannot guarantee the eviction of hyperthreading. At the same time, this solution has the problem of high cost of adapting to the new version of the kernel;
[0069] 4. The throttle mechanism ensures the priority of the two services to a certain extent, but the technical implementation overhead of this method is too high.
[0070] To this end, an embodiment of the present application provides a technical solution for task scheduling. In this technical solution, a mixed-deployment task queue is obtained, wherein the task queue contains at least one task, and each task has a one-to-one corresponding cookie value; the priority corresponding to each task is determined according to the cookie value; based on the core scheduling scheduling algorithm, the tasks in the task queue are scheduled according to the priority and preset rules, wherein the preset rules are used for timely preemption of low-priority tasks by high-priority tasks and prevention of hyper-threading interference. Thus, by pre-configuring cookie values for online or offline tasks, the cookie values can be used as a mark of task priority. When performing task scheduling, high-priority tasks will ignore some scheduling rules to ensure timely preemption of low-priority tasks, and the hyper-threading isolation mechanism of the core scheduling scheduling strategy itself can be used to achieve strict expulsion of low-priority services from high-priority services on the same pair of hyper-threads. At the same time, by using the cookie field of the process in the core scheduling policy, adding custom preset rules, realizing the high and low priority classification of processes, and avoiding the hyperthreading interference of low-priority services on strictly high-priority services, even in the latest version of the Linux kernel with major changes to the scheduler, the corescheduling logic still exists, so it is more compatible with the new version of the kernel, less invasive, and has a lower adaptation cost. See the following for details.
[0071] Finally, for ease of understanding, an exemplary operating environment is provided below.
[0072] like Figure 1 As shown, the environment diagram includes a service platform 2, a network 4, and a client 6, wherein:
[0073] The service platform 2 may be composed of a single or multiple computing devices. The multiple computing devices may include virtualized computing instances. Virtualized computing instances may include virtual machines, such as simulations of computer systems, operating systems, servers, etc. The computing device may load a virtual machine based on a virtual image and / or other data defining specific software (e.g., operating system, dedicated application, server) for simulation. As the demand for different types of processing services changes, different virtual machines may be loaded and / or terminated on one or more computing devices. A hypervisor may be implemented to manage the use of different virtual machines on the same computing device.
[0074] The service platform 2 may be configured to communicate with the client 6 or the like via a network 4. The network 4 includes various network devices, such as routers, switches, multiplexers, hubs, modems, bridges, repeaters, firewalls, proxy devices, and / or the like. The network 4 may include physical links, such as coaxial cable links, twisted pair cable links, optical fiber links, combinations thereof, and the like, or wireless links, such as cellular links, satellite links, Wi-Fi links, and the like.
[0075] The service platform 2 can provide storage, reading, writing, querying, deleting and other services, such as providing task scheduling services for clients.
[0076] Client 6 can be a Windows, Android TM ) or iOS operating systems, such as smart phones, tablet devices, laptop computers, virtual reality devices, gaming devices, set-top boxes, vehicle terminals, and smart TVs. Based on the above operating systems, various applications, such as processes for task scheduling, can be run.
[0077] The client 6 may provide / configure a user access page for manipulating the service platform 2 or uploading an object, etc.
[0078] It should be noted that the above devices are exemplary, and the number and type of devices are adjustable in different scenarios or according to different needs.
[0079] The following uses the service platform 2 as the execution subject to introduce the technical solution of the present application through multiple embodiments. It should be noted that these embodiments can be implemented in a variety of different forms and should not be interpreted as being limited to the embodiments described here.
[0080] Embodiment 1
[0081] Figure 2 The flowchart of the task scheduling method according to the first embodiment of the present application is schematically shown.
[0082] like Figure 2 As shown, the task scheduling method may include steps S202 to S206, wherein:
[0083] Step S202, obtaining a hybrid deployment task queue, wherein the task queue contains at least one task, and each task has a one-to-one corresponding cookie value;
[0084] Step S204, determining the priority corresponding to each task according to the cookie value;
[0085] Step S206, based on the core scheduling algorithm, the tasks in the task queue are scheduled according to the priority and preset rules, wherein the preset rules are used for timely preemption of low-priority tasks by high-priority tasks and prevention of hyperthreading interference.
[0086] The task scheduling method provided in this embodiment: by pre-configuring a cookie value for an online or offline task, the cookie value can be used as a mark of the task priority. When performing task scheduling, high-priority tasks will ignore some scheduling rules to ensure timely preemption of low-priority tasks. In addition, the hyperthreading isolation mechanism of the core scheduling scheduling strategy itself can be used to achieve the expulsion of low-priority services from strictly high-priority services on the same pair of hyperthreads. At the same time, by using the cookie field of the process in the corescheduling scheduling strategy and adding custom preset rules, the high- and low-priority classification of the process is achieved, and the hyperthreading interference of low-priority services on strictly high-priority services is avoided. Even in the latest version of the Linux kernel where the scheduler has been greatly modified, the logic of corescheduling still exists, so it is more compatible with the new version of the kernel, less invasive, and has a lower adaptation cost.
[0087] The following combination Figure 2 , each step in steps S202 to S206 and other optional steps are described in detail.
[0088] Step S202 , obtain a hybrid deployment task queue, wherein the task queue contains at least one task, and each task has a one-to-one corresponding cookie value;
[0089] Among them, hybrid deployment is to deploy online services (usually delay-sensitive high-priority tasks) and offline tasks (usually delay-insensitive low-priority tasks) of different priorities on the same CPU to share CPU resources. In this embodiment, the task queue contains at least one task, and each task has a one-to-one corresponding cookie value, which can be used as a mark of the priority of the task, and different cookie values correspond to different priorities.
[0090] Step S204, determine the priority corresponding to each task according to the cookie value;
[0091] Specifically, different cookie values correspond to different priorities. A mapping relationship between cookie values and priorities can be maintained in advance. When scheduling tasks, the priority corresponding to each task can be determined according to the cookie value corresponding to each task according to the mapping relationship.
[0092] Step S206 , based on the core scheduling algorithm, the tasks in the task queue are scheduled according to the priority and preset rules, wherein the preset rules are used to prevent hyperthreading interference.
[0093] Specifically, the core scheduling algorithm isolates untrusted tasks by assigning different cookie values to different tasks and checking whether the cookie values are equal when selecting tasks. In this embodiment, in order to be applicable to the scenario of mixed deployment of services, preset rules are customized to bypass some native protection rules of the core scheduling algorithm in the Linux kernel. When scheduling tasks, tasks in the task queue are scheduled based on the core scheduling algorithm according to the priority of the task and the preset rules, wherein the preset rules can be used to prevent hyperthreading interference.
[0094] For example, the preset rules may include timely preemption rules to ensure timely preemption of high-priority processes. The preset rules may also include not isolating non-strict mixed deployment tasks, isolating low-priority tasks for strict high-priority tasks, thereby avoiding hyperthreading interference of low-priority tasks on strict high-priority tasks. Since offline tasks are usually low-priority, online tasks can be configured as strictly high-priority, thus avoiding hyperthreading interference of offline services on online services. It should be noted that the priority tagging through cookie values can not only take effect when selecting tasks for the same pair of hyperthreads, but also ignore some Linux kernel scheduling rules during task scheduling to ensure timely preemption of high-priority tasks for low-priority tasks. For example, for a low-priority task that has just started running on CPU1, the native Linux kernel mechanism will ensure that it has a minimum running time, but if the next selected task is high-priority, the preset rules will ignore this guarantee mechanism and directly preempt the low-priority task.
[0095] In an optional embodiment of the present application, before step S202, the method further includes:
[0096] A configuration request for a task to be executed is received; and in response to the configuration request, a cookie value corresponding to the task to be executed is configured.
[0097] Among them, the cpu.stamp interface is used to manage the cookie value of the core scheduling algorithm characteristics.
[0098] In the specific implementation, you can add the cpu.stamp interface for managing the core scheduling feature cookie value under the cgroupcpu subsystem. Users can configure the cookie value corresponding to the task through the cpu.stamp interface.
[0099] In an optional embodiment of the present application, in response to the configuration request, configuring the cookie value corresponding to the task to be executed includes:
[0100] In the case where the configuration request carries the priority of the task to be executed, the cookie value corresponding to the task to be executed is configured as a first-class interface value; or,
[0101] When the configuration request does not carry the priority level of the task to be executed, the cookie value corresponding to the task to be executed is configured as a second-class interface value, and the second-class interface value represents the native logic supporting the core scheduling algorithm.
[0102] In this embodiment, the interface values of cgroup are divided into two categories. The first type of interface value represents a special cookie for hybrid deployment, and tasks with different cookie values have different priorities; the second type of interface value is intended to enable the corescheduling native logic. By carrying the priority corresponding to the task to be executed in the configuration request, the cookie value corresponding to the task to be executed is configured as the first type of interface value, and the specific cookie value can be configured according to the priority corresponding to the task to be executed. In the case where the priority corresponding to the task to be executed is not carried in the configuration request, the cookie value corresponding to the task to be executed is configured as the second type of interface value. The second type of interface value represents the native logic that supports the core scheduling scheduling algorithm. At this time, tasks are scheduled and isolated according to the cookie value corresponding to the task, and tasks with mismatched cookie values cannot run simultaneously on the same CPU physical core.
[0103] like Figure 3The figure shows a framework diagram of the interface classification of cgroup, where the interface of cgroup includes the first type of interface value and the second type of interface value. The first type of interface value includes four priorities, namely, normal priority, low priority, high priority and strict high priority. As an example, cpu.stamp can be configured as a dedicated interface value for hybrid deployment, such as cpu.stamp=1 for group 1 and cpu.stamp=3 for group 2. In this way, group 2 is a strictly high priority task group and group 1 is a low priority task group. The running quality of the strictly high priority process is guaranteed in the kernel. As another example, if the second type of interface value needs to be configured, a special cookie value will be given to the task group. For example, if cpu.stamp=4 is set for both group 3 and group 4, the two task groups will have their own cookie values, and the core scheduling mechanism can isolate the two groups of tasks based on the cookie value.
[0104] In an optional embodiment of the present application, the preset rule includes a timely preemption rule, and the core scheduling algorithm is based on which the tasks in the task queue are scheduled according to the priority and the preset rule, including:
[0105] Based on the core scheduling algorithm, when the priority corresponding to the first task that needs to be executed is high priority and the priority corresponding to the second task being executed is low priority, the first task is scheduled to preempt the second task according to the timely preemption rule.
[0106] In this embodiment, for tasks that want to be deployed in a mixed manner, different cookie values can be configured to assign high and low priorities to the tasks. The technical implementation mainly adds some custom rules to bypass some native protection rules in the Linux kernel to ensure that high-priority processes preempt low-priority processes in a timely manner.
[0107] To illustrate this problem, the following is an example of a custom rule. Figure 3 , here we make the following assumptions:
[0108] 1. Assume that there are high-priority task A (cookie=2), ordinary task B (cookie=0), and low-priority task C (cookie=1).
[0109] 2. If the CPU is running a low-priority task C, and there are two tasks A and B on the ready queue,
[0110] Then, in the CFS periodic scheduling, it will check whether to preempt the currently running C process. According to the native logic of the Linux kernel, in order to prevent frequent process switching, it will ensure that the process runs for at least sched_min_granularity, that is, the C process will run for at least a period of time before the A process can run, which will greatly affect the service quality of the A process. Therefore, if the A process is a high-priority process and the C process is a low-priority process, then the A process can ignore this rule and directly preempt the C process, thereby ensuring the timely preemption of the high-priority process. Figure 4 The figure shows a schematic diagram of a high-priority process preempting a low-priority process.
[0111] In an optional embodiment of the present application, the task scheduling method is applied to a physical core including a first logical core and a second logical core, and the preset rules further include: no isolation is performed for tasks of non-strict mixed deployment, and low-priority tasks are isolated for strict high-priority tasks.
[0112] The task scheduling method of this embodiment can be applied to a physical core including a first logical core and a second logical core, wherein the first logical core and the second logical core are hyperthreaded to each other.
[0113] In this embodiment, the preset rules may also include: no isolation for non-strict hybrid deployment tasks, and isolation of low-priority tasks for strict high-priority tasks. Among them, non-strict hybrid deployment tasks may include cookie=2 high-priority tasks, cookie=0 for ordinary tasks, and cookie=1 for low-priority tasks. Strict high-priority tasks may include cookie=3 strict high-priority tasks.
[0114] For the hyperthreading interference problem, in order to avoid the interference of offline services on online services, the isolation mechanism of the corescheduling scheduling algorithm is used. Figure 3 The cgroup interface classification diagram makes the following assumptions:
[0115] 1. Assume that cookie=3 is a strictly high-priority process and requires hyperthreading isolation (strict high priority), cookie=2 is a high-priority process, cookie=0 is a normal process, and cookie=1 is a low-priority process.
[0116] 2. Assume that there are four types of tasks on the ready queue: A (cookie=3), B (cookie=2), C (cookie=0), and D (cookie=1).
[0117] 3. Assume that the CPU core is divided into two logical cores CPU0 and CPU1.
[0118] 4. Assume that CPU0 and CPU1 are ready queues, such as Figure 5 shown.
[0119] At this time, for the core scheduling native policy solution, a class A process with cookie=3 and a class B process with cookie=2 cannot run on the same CPU core at the same time. This solution is not suitable for mixed deployment solutions. For example, if a low-priority process (cookie=1) runs on CPU0, then due to the core scheduling native isolation mechanism, CPU1 cannot run even if there is a high-priority process.
[0120] Therefore, this embodiment adds some customized isolation rules to ensure:
[0121] 1) For non-strict hybrid deployment processes (cookie = 0 / 1 / 2), this solution does not isolate even if the cookies are different;
[0122] 2) For strict high-priority processes (cookie=3), low-priority processes (cookie=1) will be isolated, and other types of processes will not be isolated.
[0123] In an optional embodiment of the present application, the scheduling of tasks in the task queue according to the priority and preset rules based on the core scheduling algorithm further includes:
[0124] Based on the core scheduling algorithm, when the priority corresponding to the task currently executed on the first logical core is a strict high priority, the execution of the low-priority task on the second logical core is abandoned.
[0125] In this embodiment, based on the core scheduling algorithm, when the priority corresponding to the task currently executed on the first logical core is a strict high priority, the execution of the low priority task on the second logical core is abandoned, thereby achieving strict isolation of high priority and low priority tasks.
[0126] In an optional embodiment of the present application, the method further includes:
[0127] When the priority corresponding to the task currently executed on the first logical core is a strict high priority and there are only low priority tasks in the task queue corresponding to the second logical core, the preset idle task is executed on the second logical core.
[0128] In this embodiment, when the priority of the task currently executed on the first logical core is a strict high priority, and there are only low priority tasks in the task queue corresponding to the second logical core, the preset idle task is executed on the second logical core, where the preset idle task can be an idle process. That is, if one of the two logical cores of the CPU, CPU0 and CPU1, selects a strict high priority (cookie=3) and the other selects a low priority (cookie=1), the strict high priority (cookie=3) will be used as the cookie value of the entire physical core core to match the appropriate task. In this way, the user can isolate high and low priority processes by configuring the cookie value.
[0129] As an example, take several different types of cookie values, and the matching rules are as follows Figure 6 As shown:
[0130] In practice, if CPU0 starts to select the next process and selects a high-priority process of type A (cookie=3), if CPU1 selects a process of type D (cookie=1), the cookie of the strictly high-priority process (cookie=3) will be used as the cookie of the entire core, and then CPU1 will give up D and look for a process that matches A (cookie=0 / 2 / 3). If it cannot find one, CPU1 will be forced to run an idle process. Two examples of matching are as follows:
[0131] Case 1: There are other processes on CPU1 that can match A, such as Figure 7 .
[0132] Case 2: CPU1 has only low-priority D-type processes, such as Figure 8 .
[0133] At the same time, when CPU1 is forced to run the idle process, this embodiment will also try to pull the cookie matching process from other CPUs to run through load balancing, but load balancing has overhead, so it may not be successful. That is, if CPU1 pulls a matching process, it will schedule the pulled process, and if it cannot pull, it can only run the idle type process.
[0134] Of course, there are more ways to load balance in the Linux kernel than this. This embodiment also adds some cookie value matching rules to other types of load balancing methods for targeted corrections to truly ensure the performance of online services. That is, when trying to pull cookie matching processes from other CPUs to run through load balancing, the above-mentioned custom preset rules will also be followed to pull cookie value matching tasks.
[0135] like Fig. 9The framework structure diagram of the task scheduling method of this embodiment is shown as follows: Fig.10 This is a schematic diagram of the preset rules followed by this embodiment. In order to test the performance of the task scheduling method of this embodiment, by simulating the hybrid deployment of offline services, 8 containers are deployed to run online services and 8 containers to run offline services, and the p99 delay of online services in three scenarios is compared: no hybrid deployment, hybrid deployment without isolation solution, and hybrid deployment with CPU isolation solution:
[0136] 1) Online business runs alone, with extremely low latency, such as Fig.11 .
[0137] 2) When resource isolation is not implemented, CPU tasks are mixed and online tasks will have high latency, such as Fig.12 .
[0138] 3) After resource isolation is achieved, CPU tasks can be mixed to ensure the quality of online services, such as Fig.13 .
[0139] From the test results, the performance of non-mixed running > CPU isolation mixed deployment > non-isolation mixed deployment. The performance of online services under the isolation solution is 3 to 4 times higher than that of the non-isolation solution. That is, the task scheduling method of this embodiment can well guarantee the performance of online services when services are mixed deployed.
[0140] Embodiment 2
[0141] Fig.14 The block diagram of the task scheduling device according to the second embodiment of the present application is schematically shown. The device can be divided into one or more program modules, one or more program modules are stored in a storage medium, and are executed by one or more processors to complete the embodiment of the present application. The program module referred to in the embodiment of the present application refers to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment. Fig.14 As shown, the task scheduling device 1400 may include: a task queue acquisition module 1410, a priority determination module 1420 and a task scheduling module 1430, wherein:
[0142] The task queue acquisition module 1410 is used to acquire a hybrid deployed task queue, wherein the task queue contains at least one task, and each task has a one-to-one corresponding cookie value;
[0143] A priority determination module 1420, configured to determine the priority corresponding to each task according to the cookie value;
[0144] The task scheduling module 1430 is used to schedule the tasks in the task queue according to the priority and preset rules based on the core scheduling scheduling algorithm, wherein the preset rules are used for timely preemption of low-priority tasks by high-priority tasks and prevention of hyperthreading interference.
[0145] In an optional embodiment of the present application, the device further includes:
[0146] A configuration request receiving module, used to receive a configuration request for a task to be executed;
[0147] The cookie value configuration module is used to configure the cookie value corresponding to the task to be executed in response to the configuration request.
[0148] In an optional embodiment of the present application, the cookie value configuration module includes:
[0149] A first configuration submodule is configured to configure the cookie value corresponding to the task to be executed to be a first-class interface value when the configuration request carries the priority corresponding to the task to be executed; or
[0150] The second configuration submodule is used to configure the cookie value corresponding to the task to be executed as a second type of interface value when the priority corresponding to the task to be executed is not carried in the configuration request, and the second type of interface value represents the native logic that supports the core scheduling scheduling algorithm.
[0151] In an optional embodiment of the present application, the preset rule includes a timely preemption rule, and the task scheduling module 1430 includes:
[0152] The first task scheduling submodule is used to schedule the first task to preempt the second task according to the timely preemption rule based on the core scheduling scheduling algorithm, when the priority corresponding to the first task to be executed is high priority and the priority corresponding to the second task being executed is low priority.
[0153] In an optional embodiment of the present application, the task scheduling method is applied to a physical core including a first logical core and a second logical core, and the preset rules further include: no isolation is performed for tasks of non-strict mixed deployment, and low-priority tasks are isolated for strict high-priority tasks.
[0154] In an optional embodiment of the present application, the task scheduling module 1430 further includes:
[0155] The second task scheduling submodule is used to abandon the execution of low-priority tasks on the second logical core based on the core scheduling scheduling algorithm when the priority corresponding to the task currently executed on the first logical core is a strict high priority.
[0156] In an optional embodiment of the present application, the task scheduling module 1430 further includes:
[0157] The third task scheduling submodule is used to execute a preset idle task on the second logical core when the priority corresponding to the task currently executed on the first logical core is a strict high priority and there are only low priority tasks in the task queue corresponding to the second logical core.
[0158] Embodiment 3
[0159] Fig.15 The schematic diagram of the hardware architecture of a computer device 10000 suitable for implementing the task scheduling method according to the third embodiment of the present application is schematically shown. In some embodiments, the computer device 10000 may be a terminal device such as a smart phone, a wearable device, a tablet computer, a personal computer, a vehicle terminal, a game console, a virtual device, a workbench, a digital assistant, a set-top box, a robot, etc. In other embodiments, the computer device 10000 may be a rack server, a blade server, a tower server, or a cabinet server (including an independent server, or a server cluster composed of multiple servers), etc. Fig.15 As shown, the computer device 10000 includes but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can communicate with each other through a system bus. Among them:
[0160] The memory 10010 includes at least one type of computer-readable storage medium, and the readable storage medium includes a flash memory, a hard disk, a multimedia card, a card-type memory (such as an SD or DX memory), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 10010 may be an internal storage module of the computer device 10000, such as a hard disk or a memory of the computer device 10000. In other embodiments, the memory 10010 may also be an external storage device of the computer device 10000, such as a plug-in hard disk equipped on the computer device 10000, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the memory 10010 may also include both the internal storage module of the computer device 10000 and its external storage device. In this embodiment, the memory 10010 is generally used to store the operating system and various application software installed in the computer device 10000, such as the program code of the task scheduling method, etc. In addition, the memory 10010 can also be used to temporarily store various data that have been output or will be output.
[0161] In some embodiments, the processor 10020 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other chips. The processor 10020 is generally used to control the overall operation of the computer device 10000, such as performing control and processing related to data interaction or communication with the computer device 10000. In this embodiment, the processor 10020 is used to run the program code stored in the memory 10010 or process data.
[0162] The network interface 10030 may include a wireless network interface or a wired network interface, and the network interface 10030 is generally used to establish a communication link between the computer device 10000 and other computer devices. For example, the network interface 10030 is used to connect the computer device 10000 to an external terminal through a network, and to establish a data transmission channel and a communication link between the computer device 10000 and the external terminal. The network may be a wireless or wired network such as an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, etc.
[0163] It should be pointed out that Fig.15 Only a computer device having components 10010 - 10030 is shown, but it should be understood that implementing all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.
[0164] In this embodiment, the task scheduling method stored in the memory 10010 can also be divided into one or more program modules and executed by one or more processors (such as processor 10020) to complete the embodiment of the present application.
[0165] Embodiment 4
[0166] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, wherein when the computer program is executed by a processor, the steps of the task scheduling method in the embodiment are implemented.
[0167] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the computer-readable storage medium can be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium can also be an external storage device of a computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the computer-readable storage medium can also include both the internal storage unit of the computer device and its external storage device. In this embodiment, the computer-readable storage medium is generally used to store the operating system and various application software installed on the computer device, such as the program code of the task scheduling method in the embodiment, etc. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or are to be output.
[0168] Embodiment 5
[0169] An embodiment of the present application also provides a computer program product, including a computer program, which implements the method in the above embodiment when executed by a processor.
[0170] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present application can be implemented by general-purpose computer devices, they can be concentrated on a single computer device, or distributed on a network composed of multiple computer devices, optionally, they can be implemented by executable program codes of computer devices, so that they can be stored in a storage device and executed by the computer device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.
[0171] It should be noted that the above are only preferred embodiments of the present application, and the patent protection scope of the present application is not limited thereto. Any equivalent structure or equivalent process transformation made using the contents of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A task scheduling method, characterized in that: The method comprises: Get a hybrid deployment task queue, where the task queue contains at least one task, and each task has a one-to-one corresponding cookie value; Determine the priority of each task according to the cookie value; Based on the core scheduling algorithm, the tasks in the task queue are scheduled according to the priority and preset rules, wherein the preset rules are used for timely preemption of low-priority tasks by high-priority tasks and prevention of hyperthreading interference.
2. The task scheduling method according to claim 1, characterized in that: Before the step of obtaining the hybrid deployment task queue, the method further includes: receiving a configuration request for a task to be performed; In response to the configuration request, a cookie value corresponding to the task to be executed is configured.
3. The task scheduling method according to claim 1, characterized in that: The configuring, in response to the configuration request, a cookie value corresponding to the task to be executed, includes: In the case where the configuration request carries the priority of the task to be executed, the cookie value corresponding to the task to be executed is configured as a first-class interface value; or, When the configuration request does not carry the priority level of the task to be executed, the cookie value corresponding to the task to be executed is configured as a second-class interface value, and the second-class interface value represents the native logic supporting the core scheduling algorithm.
4. The task scheduling method according to claim 1, characterized in that: The preset rules include timely preemption rules, and the core scheduling algorithm is based on which tasks in the task queue are scheduled according to the priorities and the preset rules, including: Based on the core scheduling algorithm, when the priority corresponding to the first task that needs to be executed is high priority and the priority corresponding to the second task being executed is low priority, the first task is scheduled to preempt the second task according to the timely preemption rule.
5. The task scheduling method according to claim 1, characterized in that: The task scheduling method is applied to a physical core including a first logical core and a second logical core, and the preset rules further include: no isolation is performed for tasks of non-strict mixed deployment, and low-priority tasks are isolated for strict high-priority tasks.
6. The task scheduling method according to claim 5, characterized in that: The core scheduling algorithm is based on which the tasks in the task queue are scheduled according to the priority and preset rules, and further includes: Based on the core scheduling algorithm, when the priority corresponding to the task currently executed on the first logical core is a strict high priority, the execution of the low-priority task on the second logical core is abandoned.
7. The task scheduling method according to claim 6, characterized in that: The core scheduling algorithm is based on which the tasks in the task queue are scheduled according to the priority and preset rules, and further includes: When the priority corresponding to the task currently executed on the first logical core is a strict high priority and there are only low priority tasks in the task queue corresponding to the second logical core, the preset idle task is executed on the second logical core.
8. A task scheduling device, characterized in that: The device comprises: A task queue acquisition module is used to acquire a hybrid deployed task queue, wherein the task queue contains at least one task, and each task has a one-to-one corresponding cookie value; A priority determination module, used to determine the priority corresponding to each task according to the cookie value; The task scheduling module is used to schedule the tasks in the task queue according to the priority and preset rules based on the core scheduling scheduling algorithm, wherein the preset rules are used for timely preemption of low-priority tasks by high-priority tasks and prevention of hyperthreading interference.
9. A computer device, characterized in that: include: at least one processor; and a memory communicatively connected to the at least one processor; wherein: The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the task scheduling method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the task scheduling method according to any one of claims 1 to 7 is implemented.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the task scheduling method described in claims 1 to 7 are implemented.
