Task scheduling method of virtual machine and host machine
By setting up information channels between the host and the virtual machine, and adjusting resource allocation using load characteristics and task priorities, the problems of long execution time of virtual machine tasks, low resource utilization and inability to run critical tasks are solved, and more efficient resource utilization and priority processing of critical tasks are achieved.
Patent Information
- Application Number
- CN202411813701.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-10
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2044-12-10
AI Technical Summary
In existing virtual machine technology, virtual machine tasks have a long execution time, low resource utilization, and cannot effectively protect critical tasks in virtual machines, resulting in critical tasks being unable to run first.
By setting up an information channel between the host and the virtual machine, the host's task scheduler writes the load characteristics of the physical computing resources to the channel, and the virtual machine's task scheduler reads this information to decide whether to allocate virtual computing resources and adjusts resource allocation according to task priority.
Reduces execution time of virtual machine tasks, increases the utilization of compute resources, and ensures that critical tasks in virtual machines are prioritized.
Smart Images

Figure CN119690671A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of computer virtualization technology, and in particular, to a task scheduling method for a virtual machine and a host machine. Background Art
[0002] A virtual machine (VM) is a computer system simulated by software, which creates a virtual computing environment based on a physical computer (host machine). The virtual environment simulates an independent computer, for example, it can configure virtual resources such as an operating system, CPU, memory, hard disk, and can perform various data processing tasks, such as running applications. In existing virtual machine technology solutions, task scheduling on the host machine where the virtual machine is located and task scheduling within the virtual machine are usually executed by the task scheduler of the host machine and the task scheduler of the virtual machine, respectively. However, this solution often has problems such as long virtual machine task execution time, low resource utilization, and failure to protect key tasks in the virtual machine. Summary of the invention
[0003] The embodiments in this specification are intended to provide a task scheduling method for a virtual machine, which can reduce the execution time of virtual machine tasks, improve the utilization rate of computing resources, and protect key tasks in the virtual machine so that they are given priority over ordinary tasks, thereby solving the shortcomings of the existing technology.
[0004] According to a first aspect, a task scheduling method for a virtual machine is provided, wherein a host machine of the virtual machine is configured with a first caller corresponding to the host machine and a second scheduler corresponding to the virtual machine, the method comprising:
[0005] In response to a task change event on the host machine, the first caller writes the load characteristics of the physical computing resources on the host machine into a preset information channel;
[0006] The second caller reads the load characteristics from the information channel, and determines whether to allocate virtual computing resources to the first task on the virtual machine according to the load characteristics.
[0007] In a possible implementation, the method further includes:
[0008] In response to the task change event in the virtual machine, the second caller writes the second task on the virtual machine and a first tag indicating a task priority corresponding to the second task on the virtual machine into the information channel;
[0009] The first caller reads the first task and the first tag from the information channel, and determines, based on the first tag, whether to allocate physical computing resources to a third task corresponding to the second task on the host machine.
[0010] In a possible implementation, the load characteristics include: a usage rate of each physical processor included in the host machine;
[0011] Determining whether to allocate virtual computing resources to the first task on the virtual machine according to the load characteristics includes:
[0012] According to the usage rate of each physical processor core, it is determined whether there is an idle physical processor core on the host machine, and if there is an idle physical processor core on the host machine, an idle virtual processor core is allocated to the first task.
[0013] In a possible implementation manner, the load feature further includes: a task priority of each task on the host machine, the task priority on the host machine includes a first level and a second level, the first level takes precedence over the second level;
[0014] The method further comprises:
[0015] If there is no idle physical processor core on the host machine, determining whether there is a physical processor core on the host machine for running the second-level task according to the task priority of each task on the host machine;
[0016] If there are physical processor cores for running the second level tasks, an idle virtual processor core is allocated to the first task.
[0017] In a possible implementation manner, the task priority on the virtual machine includes a first virtual level and a second virtual level, and the first virtual level takes precedence over the second virtual level;
[0018] Allocating an idle virtual processor core to the first task includes: setting a task priority of the first task to a first virtual level, and allocating an idle virtual processor core to the first task.
[0019] In a possible implementation manner, the task priority on the virtual machine includes a first virtual level and a second virtual level, and the first virtual level takes precedence over the second virtual level;
[0020] Determining, according to the first mark, whether to allocate physical computing resources to a third task corresponding to the second task on the host machine includes:
[0021] If the first mark indicates that the task priority of the second task in the virtual machine is the first virtual level, the task weight corresponding to the third task is set to a preset first weight; if the first mark indicates that the task priority of the second task in the virtual machine is the second virtual level, the task weight corresponding to the third task is set to a preset second weight, the value of the first weight is greater than the value of the second weight, and the value of the task weight is positively correlated to the probability of allocating a physical processor core to the third task.
[0022] In a possible implementation, the value of the task weight is positively correlated with the probability of allocating a physical processor core to the third task, including:
[0023] Determine whether there is a target physical processor core for running the second-level task in the host machine. If the target physical processor core exists, sort the second-level tasks according to the task weights of the second-level tasks in the host machine, and determine the order of allocating physical processor cores to the second-level tasks based on the sorting results.
[0024] In a possible implementation, the preset information channel includes a preset memory area or memory object for access by the first scheduler and the second scheduler.
[0025] In a possible implementation, the preset information channel includes a preset shared file system between the host machine and the virtual machine.
[0026] In one possible implementation, the change events on the host machine include one or more of task start, task termination, task pause, task recovery, task priority change, and task resource change on the host machine; the change events on the virtual machine include one or more of task start, task termination, task pause, task recovery, task priority change, and task resource change within the virtual machine.
[0027] In a possible implementation, the second scheduler includes a Go runtime scheduler, and the virtual computing resources include an abstract processor in a Go runtime environment.
[0028] According to a second aspect, a host machine is provided, wherein a first caller corresponding to the host machine and a second scheduler corresponding to a virtual machine on the host machine are configured on the host machine, wherein:
[0029] The first caller is configured to, in response to a task change event on the host machine, write the load characteristics of the physical computing resources on the host machine into a preset information channel;
[0030] The second caller is configured to read the load characteristics from the information channel, and determine whether to allocate virtual computing resources to the first task on the virtual machine according to the load characteristics.
[0031] In a possible implementation manner, the second caller is further configured to, in response to a task change event in the virtual machine, write the second task on the virtual machine and a first tag indicating a task priority corresponding to the second task on the virtual machine into the information channel;
[0032] The first caller is further configured to read the first task and the first tag from the information channel, and determine whether to allocate physical computing resources to a third task corresponding to the second task on the host machine according to the first tag.
[0033] According to a third aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed in a computer, the computer is caused to execute the method described in the first aspect.
[0034] According to a fourth aspect, a computing device is provided, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in the first aspect is implemented.
[0035] By utilizing one or more of the methods, host machines, computing devices, and storage media in the above aspects, the execution time of virtual machine tasks can be reduced, the utilization rate of computing resources can be improved, and critical tasks in the virtual machine can be protected so that they are given priority over ordinary tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0037] Figure 1 A schematic diagram showing a virtual machine task scheduling;
[0038] Figure 2 A schematic diagram showing a method for scheduling tasks of a virtual machine according to an embodiment of the present specification;
[0039] Figure 3 A flowchart showing a method for scheduling tasks of a virtual machine according to another embodiment of the present specification;
[0040] Figure 4A schematic diagram showing a method for a virtual machine scheduler to determine allocation of virtual processor cores according to an embodiment of the present specification;
[0041] Figure 5 A schematic diagram showing a host machine task scheduling;
[0042] Figure 6 A flowchart showing a method for scheduling tasks of a virtual machine according to another embodiment of the present specification;
[0043] Figure 7 A schematic diagram showing a method for a host scheduler to determine allocation of physical processor cores according to an embodiment of this specification;
[0044] Figure 8 A structural diagram of a host machine according to an embodiment of the present specification is shown. DETAILED DESCRIPTION
[0045] The solution provided in this invention book will be described below in conjunction with the accompanying drawings.
[0046] As mentioned above, a virtual machine (VM) is a computer system simulated by software, which creates a virtual computing environment based on a physical computer (host). The virtual environment simulates an independent computer, for example, it can configure virtual resources such as an operating system, CPU, memory, and hard disk, and can perform data processing tasks such as running applications. In existing virtual machine technical solutions, task scheduling on the host machine where the virtual machine is located and task scheduling within the virtual machine are usually performed by the task scheduler of the host machine (or simply the host scheduler) and the task scheduler of the virtual machine (or simply the virtual machine scheduler), respectively.
[0047] According to this solution, the virtual machine scheduler usually does not know the status of the tasks run by the host scheduler. As a result, the virtual machine scheduler cannot determine how to allocate its virtual resources according to the actual load of the physical computing resources on the host. This leads to the problem that the virtual machine's task execution time is long and the utilization rate of computing resources is low. For example, Figure 1 A schematic diagram of virtual machine task scheduling is shown. Figure 1The virtual machine shown is configured with, for example, 4 virtual processor cores (vCPUs, also referred to as virtual cores in this specification for ease of description), 2 of which have been used to run tasks Task1 and Task2. At this time, there are still tasks Task3 and Task4 to be run in the virtual machine. Since the virtual machine scheduler T1 determines that there are still 2 idle virtual machine cores based on the utilization status of the virtual resources of this virtual machine, it allocates idle vCPUs to Task3 and Task4 respectively for running these two tasks. However, the tasks assigned to the virtual cores are essentially run by the physical processor cores (pCPUs, also referred to as physical cores in this specification for ease of description) of the host machine. For example, the host machine is configured with 4 physical cores. If at this time, the 4 physical cores are already busy, they are used to run different tasks (such as local tasks TaskA and TaskB of the host machine, and tasks Task1 and Task2 of the virtual machine), that is, there are no idle physical cores on the host machine. Therefore, although the task scheduler T1 allocates virtual cores to Task3 and Task4, these two tasks actually do not have idle physical cores for running. Since these virtual machine tasks that are assigned virtual cores are not actually executed, the response time and total execution time of these virtual machine tasks are increased.
[0048] In order to solve the above technical problems, an embodiment of the present specification provides a task scheduling method for a virtual machine. Figure 2 A schematic diagram showing a method for scheduling tasks of a virtual machine according to an embodiment of the present specification is shown. Figure 2 As shown, when the task status on the host machine changes (e.g., new task start, task termination, task suspension, task resumption, etc.), the host machine task scheduler writes the load characteristics of the physical computing resources on the host machine (e.g., physical core usage) into the shared information channel with the task scheduler on the virtual machine. The virtual scheduler is used to read the load characteristics of the physical computing resources on the host machine from the shared information channel, and determine whether to allocate virtual resources to the virtual tasks on the virtual machine based on these load characteristics.
[0049] The advantages of this method are: on the one hand, it enables the virtual machine scheduler to obtain the actual load information of the physical computing resources on the host machine, so that it can determine how to allocate virtual resources to virtual tasks based on the actual load of the physical computing resources on the host machine, thereby reducing the execution time of tasks on the virtual machine and improving the utilization rate of physical computing resources for tasks on the virtual machine. On the other hand, it reduces the probability of allocating virtual computing resources to tasks on the virtual machine without receiving support from physical computing resources, that is, reduces the probability of invalid scheduling of virtual computing resources. Since allocating virtual resources to tasks itself also consumes computing resources, it can further reduce the waste of computing resources caused by invalid scheduling of virtual computing.
[0050] Figure 3 A flowchart of a method for scheduling tasks of a virtual machine according to an embodiment of the present specification is shown. A host machine of the virtual machine is configured with a first caller corresponding to the host machine and a second scheduler corresponding to the virtual machine. Figure 3 As shown, the method comprises at least the following steps:
[0051] Step S301, in response to a task change event on the host machine, the first caller writes the load characteristics of the physical computing resources on the host machine into a preset information channel;
[0052] Step S303: the second caller reads the load characteristics from the information channel, and determines whether to allocate virtual computing resources to the first task on the virtual machine according to the load characteristics.
[0053] First, in step S301, in response to a task change event on the host machine, the first caller writes the load characteristics of the physical computing resources on the host machine into a preset information channel.
[0054] The host machine is usually a computer with physical resources (such as CPU, memory, disk space, network interface, etc.) for running containers. In different embodiments, the host machine can be a physical computer or a logical computer allocated with physical resources. In this step, after the task change event of the host machine, the first caller can write the load characteristics of the physical computing resources on the host machine into a preset information channel. In different embodiments, the task change event of the host machine may be different. In one embodiment, the change event on the host machine includes one or more of task start, task termination, task suspension, task recovery, task priority change, and task resource change on the host machine.
[0055] The first caller (i.e., the host scheduler) is a software system for managing and allocating computing resources of the host to coordinate the execution of multiple tasks. In one embodiment, the host scheduler can run based on the host kernel (HostKernel). Load characteristics are information used to represent the load status of physical computing resources on the host. Physical computing resources are physical resources used to perform computing tasks on the host. In one embodiment, they can include processor cores, memory, disks, network bandwidth, etc. In different specific embodiments, the types and quantities of physical resources used to perform computing tasks on the host may be different, and this specification does not limit this. In different embodiments, the load characteristics of the preset information channel written by the first scheduler may also be different. In one embodiment, the load characteristics may include information on the load status of each physical processor core included on the host, such as the utilization rate of the physical processor core (CPU Core Utilization). In other embodiments, the load characteristics may also include information on the load status of memory and disk, etc.
[0056] The preset information channel is an information channel that can be accessed by both the first scheduler and the second caller. In different embodiments, it can be different specific information channels for transmitting information. In one embodiment, the preset information channel can be a preset memory area or memory object that can be accessed by both the first scheduler and the second scheduler. In another embodiment, the preset information channel can also be a preset shared file system between the host machine and the virtual machine.
[0057] After the host machine writes the load characteristics of the physical computing resources into the preset information channel, in step S303, the second scheduler (virtual machine scheduler) can determine how to allocate virtual computing resources to the tasks on the virtual machine according to the load information. The virtual machine scheduler is a software module used to allocate computing resources inside the virtual machine to ensure the execution of tasks in the virtual machine. In different embodiments, the specific type of the virtual machine can be different. In one embodiment, for example, it can be a system virtual machine (System Virtual Machine) for simulating a complete computer system. In addition to the system virtual machine, in another embodiment, for example, it can also be a program virtual machine (Program Virtual Machine) for running programs written in a specific programming language. In different embodiments, according to different types of virtual machines, the scheduler corresponding to the virtual machine can also be different. In one embodiment, the virtual machine scheduler can be integrated in virtual machine management software, such as a virtual machine monitor (VMM, Virtual Machine Monitor). In another embodiment, the virtual machine scheduler may be, for example, a runtime scheduler of a specific programming language (e.g., the Go language), the virtual machine may be a runtime virtual computing environment of the programming language (e.g., the Go runtime environment), and the virtual computing resources may include an abstract processor (P) in the runtime virtual computing environment.
[0058] In different embodiments, the specific manner in which the second caller determines how to allocate virtual computing resources to tasks on the virtual machine may also be different according to different load characteristics. For example, in the above-mentioned embodiment of writing the utilization rate of the physical processor core, the second caller may determine whether there are idle physical processor cores on the host machine according to the utilization rate of each physical processor core, and if there are idle physical processor cores on the host machine, allocate idle virtual processor cores to the first task. In different embodiments, the specific manner of determining whether there are idle physical processor cores on the host machine may be different. In one embodiment, for example, whether there are physical processor cores on the host machine whose utilization rate is lower than a predetermined threshold (for example, a first threshold) may be used to determine whether there are idle physical processor cores on the host machine. In different specific embodiments, the specific value of the first threshold may be different. In a specific embodiment, it may be, for example, 10%.
[0059] Figure 4 A schematic diagram showing a method for a virtual machine scheduler to determine allocation of virtual processor cores according to an embodiment of this specification. Figure 4As shown, for example, the host machine is configured with multiple physical cores, such as pCPU1, pCPU2, pCPU3, pCPU4... The host machine scheduler T1 can write the usage rate of each physical core into the shared memory between the virtual machine scheduler T1 and the host machine scheduler T2, for example, the usage rate of pCPU1 is 90%, the usage rate of pCPU2 is 80%, the usage rate of pCPU3 is 79%, and the usage rate of pCPU4 is 5%. There are 4 virtual cores configured on the virtual machine, and there are idle virtual cores at this time. The virtual machine scheduler T1 can read the usage rate of each physical core on the host machine, determine whether there are idle physical cores on the host machine, and determine whether to allocate idle virtual cores to, for example, virtual task Task3. Since the usage rate of pCPU4 is 5% lower than the predetermined threshold value of 10%, it can be determined that there is an idle physical core pCUP4 on the host machine, and the idle virtual core at this time can be allocated to Task3.
[0060] In some scenarios, although all the physical cores on the current host are busy, since there are physical cores for running low-priority (second-level) tasks, the response time of the new low-priority task being executed is low. Therefore, in this scenario, the virtual machine scheduler can also allocate idle virtual cores to the virtual machine task, and the time for the task to be actually processed by the physical core is also short. Therefore, in another embodiment, the load characteristics written to the information channel by the first scheduler can also include: the task priority of each task on the host, the task priority on the host includes the first level and the second level, and the first level takes precedence over the second level. Furthermore, if the second scheduler determines that there are no idle physical processor cores on the host, it can also determine whether there are physical processor cores for running second-level tasks on the host according to the task priorities of each task on the host; if there are physical processor cores for running second-level tasks, the idle virtual processor cores are allocated to the first task. In one embodiment, for example, the number of first-level tasks on the host can be determined according to the task priorities of each task on the host. Furthermore, according to whether the number of first-level tasks on the host machine is less than the total number of physical cores on the host machine, it is determined whether there is a physical processor core on the host machine for running the second-level tasks. For example, in one example, the host machine is configured with 4 physical cores pCPU1, pCPU2, pCPU3, and pCPU4. For example, the utilization rate of pCPU1 is 90%, the utilization rate of pCPU2 is 80%, the utilization rate of pCPU3 is 79%, and the utilization rate of pCPU4 is 60%. The host machine currently has 4 tasks, of which 3 have a high priority (first level) and 1 has a low priority (second level). The virtual machine scheduler T1 can determine that there are no idle physical cores on the host machine based on the utilization rate of each physical core on the host machine. Furthermore, according to the fact that the number of high-priority tasks on the host machine (3) is less than the total number of physical cores on the host machine (4), it is determined that there are physical processor cores on the host machine for running the second-level tasks, and the idle virtual cores at this time can be allocated to Task3.
[0061] In order to further increase the time that the virtual machine tasks assigned with virtual cores are actually processed by the physical cores, in one embodiment, the task priority on the virtual machine may include a first virtual level and a second virtual level, and the first virtual level takes precedence over the second virtual level. Furthermore, the virtual machine scheduler may set the task priority of the first task to the first virtual level (i.e., the high priority on the virtual machine) and allocate an idle virtual core to the first task. Although, usually, both high and low priority tasks on the virtual machine are converted into low priority tasks on the host machine on the host machine. However, by assigning a high priority on the virtual machine to the virtual machine task, the probability of the high priority task on the virtual machine being executed preferentially among the low priority tasks on the host machine can be increased. For the specific method of increasing the probability of the high priority task on the virtual machine on the host machine being executed preferentially among the low priority tasks on the host machine, please refer to the description of step S403 for details, which will not be repeated here.
[0062] In addition, according to the existing virtual machine technology solutions, the host scheduler is also unaware of the virtual machine scheduler's priority arrangement for tasks on the virtual machine, which means that the host scheduler often cannot prioritize the allocation of physical computing resources to high-priority tasks on the virtual machine, which in turn leads to the problem of being unable to protect critical tasks in the virtual machine. Figure 4 A schematic diagram of host machine task scheduling is shown. Figure 4The virtual machine shown is configured with, for example, 4 virtual cores, and the virtual machine scheduler uses these virtual cores to execute Task1, Task2, Task3, and Task4, respectively. Among them, for example, the task priorities of Task1 and Task3 on the virtual machine are, for example, high priority (v1), and the task priorities of Task2 and Task4 on the virtual machine are, for example, low priority (v2). The host machine is equipped with 4 physical cores, 2 of which are allocated to execute high priority (p1) tasks TaskA and TaskB on the host machine. Since the host machine does not know the task priority on the virtual machine, and usually for the host machine, the corresponding priorities of each task on the virtual machine on the host machine are the same, for example, all are low priority (p2). Therefore, the host machine scheduler does not allocate physical cores to each task of the virtual machine according to the order of task priority on the virtual machine. Therefore, the host machine, for example, uses the other 2 physical cores to run Task1 and Task2. The task priority of Task3 on the virtual machine is high, and the task priority of Task2 on the virtual machine is low, which means that for the virtual machine scheduler, Task3 is often a more urgent critical task, and Task2 is often a less urgent ordinary task. Obviously, the virtual machine scheduler hopes that Task3 will be run before Task2. In this case, the critical tasks of the virtual machine cannot be actually executed first, which increases the probability of bringing insecurity to the system or application on the virtual machine or causing losses to the user.
[0063] To solve this problem, when the task status on the virtual machine changes (such as new task start, task termination, task suspension, task resumption, etc.), the virtual machine scheduler can also write the priority of each task on the virtual machine into the shared information channel with the task scheduler on the host machine. The host machine scheduler reads the priority of each task on the virtual machine from the shared information channel and determines how to allocate physical computing resources to each task on the virtual machine based on the priority of each task on the virtual machine.
[0064] Figure 6 A flowchart of a method for scheduling tasks of a virtual machine according to another embodiment of the present specification is shown. Figure 6 In the illustrated embodiment, after a task change event on the virtual machine, in step S405, the second caller may respond to the task change event in the virtual machine by writing the second task on the virtual machine and a first tag indicating the task priority corresponding to the second task on the virtual machine into a preset information channel. In different embodiments, the change event on the virtual machine may also be different. In one embodiment, the change event on the virtual machine may include one or more of task start, task termination, task suspension, task resumption, task priority change, and task resource change in the virtual machine.
[0065] As described above, the preset information channel is an information channel that can be accessed by both the first scheduler and the second caller. In different embodiments, it can be different specific information channels for transmitting information, as described in the description of step S401, which will not be repeated here.
[0066] Thereafter, in step S407, the first caller may read the first task and the first tag from the information channel, and determine whether to allocate physical computing resources to the third task corresponding to the second task on the host machine according to the first tag.
[0067] In different embodiments, the specific manner of determining whether to allocate physical computing resources to the third task corresponding to the second task on the host machine may be different. In one embodiment, the task priority on the virtual machine includes a first virtual level and a second virtual level, and the first virtual level takes precedence over the second virtual level. Furthermore, if the first mark indicates that the task priority of the second task in the virtual machine is the first virtual level, the task weight corresponding to the third task may be set to a preset first weight, and if the first mark indicates that the task priority of the second task in the virtual machine is the second virtual level, the task weight corresponding to the third task may be set to a preset second weight, and the value of the first weight is greater than the value of the second weight, and the value of the task weight is positively correlated to the probability of allocating a physical processor core to the third task. Because in some scenarios, there are usually other low-priority tasks on the host machine. For example, in one example, the host machine may also have low-priority tasks of the host system itself. In another example, there are other virtual machines in the host machine, for example, other than the virtual machine corresponding to the first caller, and then the host machine may also have low-priority tasks corresponding to virtual tasks on other virtual machines on the host machine. Therefore, the host scheduler may assign weights to each low-priority task on the host machine, and determine the order of allocating physical cores to each low-priority task according to the weight. Therefore, in a specific embodiment, the host scheduler can determine whether there is a target physical processor core for running the second-level task in the host machine. If the target physical processor core exists, the second-level tasks in the host machine are sorted according to the task weights of the second-level tasks, and the order of allocating physical processor cores to the second-level tasks is determined according to the sorting results.
[0068] Figure 7 A schematic diagram showing a method for a host scheduler to determine allocation of physical processor cores according to an embodiment of this specification. Figure 7As shown, for example, 4 virtual cores are configured on the virtual machine, which are respectively allocated to 4 tasks on the virtual machine, such as Task1, Task2, Task3 and Task4, wherein Task1 and Task3 have a high priority (v1) on the virtual machine, and Task2 and Task4 have a low priority (v2) on the virtual machine. The virtual machine scheduler can write the identifiers of Task1, Task2, Task3 and Task4 and their respective corresponding priorities on the virtual machine into shared memory, for example. For example, 4 physical cores are configured on the host machine, 2 of which have been used to run high-priority (p1) tasks on the host machine. The host machine scheduler T1 can assign a first weight to Task1 and Task3 with high priority on the virtual machine, and assign a second weight to Task2 and Task4 with low priority on the virtual machine, according to the identifiers of Task1, Task2, Task3 and Task4 in the shared memory and their respective corresponding priorities on the virtual machine. And sort each low-priority task according to the weight. Task1 and Task3 are assigned higher weights, so they get the first order after sorting. Therefore, idle physical cores can be allocated to Task1 and Task3 respectively. In this way, the probability of high-priority tasks being executed first in the virtual machine can be significantly improved, so that key tasks in the virtual machine can be executed first, and the probability of security problems or losses to the system or application or users caused by key tasks not being executed first can be reduced.
[0069] It should be noted that, in this embodiment, steps S301 to S303 and steps S305 to S307 are not limited to being performed sequentially. In one embodiment, steps S301 to S303 may be performed before steps S305 to S307. In one embodiment, steps S305 to S307 may be performed before steps S301 to S303. In another embodiment, steps S301 to S303 and steps S305 to S307 may be performed in parallel.
[0070] In addition, as described above, in some scenarios, a host machine may be configured with multiple virtual machines. Therefore, in one embodiment, if a host machine is configured with multiple virtual machines, the virtual scheduler of each of the multiple virtual machines may write the priority information of the task of the virtual machine into the shared information channel between the virtual machine scheduler and the host scheduler according to the task change event in each virtual machine, so that the host scheduler can determine how to allocate physical resources to the task of the virtual machine. The specific implementation method is similar to steps S305 to S307, and reference may be made to the description of steps S305 to S307. And read the physical resource load information written by the host scheduler into the shared information channel, and determine how to allocate virtual resources to the task of the virtual machine accordingly. The specific implementation method is similar to steps S301 to S303, and reference may be made to the description of steps S301 to S303.
[0071] The above describes a method for scheduling tasks of a virtual machine provided by an embodiment of the present specification. Another embodiment of the present specification also provides a host machine. Figure 8 FIG. 2 shows a structural diagram of a host machine according to an embodiment of this specification. Figure 8 As shown, the host machine 800 may be configured with a first caller corresponding to the host machine and a second scheduler corresponding to the virtual machine on the host machine, wherein:
[0072] The first caller 81 is configured to write the load characteristics of the physical computing resources on the host machine into a preset information channel in response to a task change event on the host machine;
[0073] The second caller 82 is configured to read the load characteristics from the information channel, and determine whether to allocate virtual computing resources to the first task on the virtual machine according to the load characteristics.
[0074] In one embodiment, the second scheduler 81 is further configured to, in response to a task change event in the virtual machine, write the second task on the virtual machine and a first tag indicating a task priority corresponding to the second task on the virtual machine into the information channel;
[0075] The first caller 82 is further configured to read the first task and the first tag from the information channel, and determine whether to allocate physical computing resources to a third task corresponding to the second task on the host machine according to the first tag.
[0076] On another aspect, the present specification provides a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute any one of the above methods.
[0077] On another aspect, the present specification provides a computing device, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, any one of the above methods is implemented.
[0078] It should be understood that the descriptions such as “first” and “second” in this article are only used to distinguish similar concepts for the sake of simplicity of description and do not have any other limiting effect.
[0079] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the present invention can be implemented by hardware, software, firmware or any combination thereof. When implemented by software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.
[0080] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solution of the present invention should be included in the scope of protection of the present invention.
Claims
1. A task scheduling method for a virtual machine, wherein a host machine of the virtual machine is configured with a first caller corresponding to the host machine and a second scheduler corresponding to the virtual machine, the method comprising: In response to a task change event on the host machine, the first caller writes the load characteristics of the physical computing resources on the host machine into a preset information channel; The second caller reads the load characteristics from the information channel, and determines whether to allocate virtual computing resources to the first task on the virtual machine according to the load characteristics.
2. The method according to claim 1, further comprising: In response to the task change event in the virtual machine, the second caller writes the second task on the virtual machine and a first tag indicating a task priority corresponding to the second task on the virtual machine into the information channel; The first caller reads the first task and the first tag from the information channel, and determines, based on the first tag, whether to allocate physical computing resources to a third task corresponding to the second task on the host machine.
3. The method according to claim 1, wherein: The load characteristics include: the usage rate of each physical processor included in the host machine; Determining whether to allocate virtual computing resources to the first task on the virtual machine according to the load characteristics includes: According to the usage rate of each physical processor core, it is determined whether there is an idle physical processor core on the host machine, and if there is an idle physical processor core on the host machine, an idle virtual processor core is allocated to the first task.
4. The method according to claim 3, wherein: The load characteristics further include: task priorities of each task on the host machine, the task priorities on the host machine including a first level and a second level, the first level taking precedence over the second level; The method further comprises: If there is no idle physical processor core on the host machine, determining whether there is a physical processor core on the host machine for running the second-level task according to the task priority of each task on the host machine; If there are physical processor cores for running the second level tasks, an idle virtual processor core is allocated to the first task.
5. The method according to claim 4, wherein: The task priority on the virtual machine includes a first virtual level and a second virtual level, the first virtual level taking precedence over the second virtual level; Allocating an idle virtual processor core to the first task includes: setting a task priority of the first task to a first virtual level, and allocating an idle virtual processor core to the first task.
6. The method according to claim 2, wherein: The task priority on the virtual machine includes a first virtual level and a second virtual level, the first virtual level taking precedence over the second virtual level; Determining, according to the first mark, whether to allocate physical computing resources to a third task corresponding to the second task on the host machine includes: If the first mark indicates that the task priority of the second task in the virtual machine is the first virtual level, the task weight corresponding to the third task is set to a preset first weight; if the first mark indicates that the task priority of the second task in the virtual machine is the second virtual level, the task weight corresponding to the third task is set to a preset second weight, the value of the first weight is greater than the value of the second weight, and the value of the task weight is positively correlated to the probability of allocating a physical processor core to the third task.
7. The method according to claim 6, wherein: The value of the task weight is positively correlated to the probability of allocating a physical processor core to the third task, including: Determine whether there is a target physical processor core for running the second-level task in the host machine. If the target physical processor core exists, sort the second-level tasks according to the task weights of the second-level tasks in the host machine, and determine the order of allocating physical processor cores to the second-level tasks based on the sorting results.
8. The method according to claim 1, wherein: The preset information channel includes a preset memory area or memory object for access by the first scheduler and the second scheduler.
9. The method according to claim 1, wherein: The preset information channel includes a preset shared file system between the host machine and the virtual machine.
10. The method according to claim 2, wherein: The change events on the host machine include one or more of task start, task termination, task pause, task recovery, task priority change, and task resource change on the host machine; the change events on the virtual machine include one or more of task start, task termination, task pause, task recovery, task priority change, and task resource change within the virtual machine.
11. The method according to claim 1, wherein: The second scheduler includes a Go runtime scheduler, and the virtual computing resources include an abstract processor in a Go runtime environment.
12. A host machine, wherein a first caller corresponding to the host machine and a second scheduler corresponding to a virtual machine on the host machine are configured on the host machine, wherein: The first caller is configured to, in response to a task change event on the host machine, write the load characteristics of the physical computing resources on the host machine into a preset information channel; The second caller is configured to read the load characteristics from the information channel, and determine whether to allocate virtual computing resources to the first task on the virtual machine according to the load characteristics.
13. The host machine according to claim 12, wherein: The second caller is further configured to, in response to a task change event in the virtual machine, write a second task on the virtual machine and a first tag indicating a task priority corresponding to the second task on the virtual machine into the information channel; The first caller is further configured to read the first task and the first tag from the information channel, and determine whether to allocate physical computing resources to a third task corresponding to the second task on the host machine according to the first tag.
14. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute the method according to any one of claims 1 to 11.
15. A computing device, comprising a memory and a processor, wherein the memory stores executable codes, and when the processor executes the executable codes, the method according to any one of claims 1 to 11 is implemented.
Citation Information
Patent Citations
Virtual machine resource scheduling method and device
CN114253663A
Resource scheduling method and device and storage medium
CN114691279A
Host machine resource scheduling method and device, electronic equipment and storage medium
CN115878329A
Resource scheduling method and device for cloud platform virtual machine
CN116048714A
Task scheduling method and device, electronic equipment, storage medium and program product
CN118227289A