Method and device for setting virtual machine computing resource limit

By monitoring virtual machine life cycle events and setting the CPU and memory limits of the virtual machine, the virtual machine resource preemption problem is solved, and the stability and performance of the host and virtual machine are improved.

CN119127398APending Publication Date: 2024-12-13NEW H3C CLOUD TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411215219.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

In cloud computing, when the host's CPU and Memory resources are tight, preemption may occur between virtual machines, resulting in a decline in virtual machine performance and affecting business stability. It is necessary to reasonably set up and schedule the virtual machine computing resources to ensure stable operation. .

Method used

By monitoring virtual machine lifecycle events, obtaining computing resource information for the host and virtual machine, determining the target CPU share and memory soft limits for each virtual machine process, setting corresponding CPU and memory limits to automatically adjust resource allocation.

Benefits of technology

It realizes automatic perception of changes in the available computing resources of the host, improves the performance of virtual machines and the stability of the host, and ensures the normal operation of important business virtual machines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127398A_ABST
    Figure CN119127398A_ABST
Patent Text Reader

Abstract

The invention provides a method and a device for setting a computing resource limit of a virtual machine. The method comprises the steps that when a virtual machine life cycle operation event is monitored, host machine computing resource information and virtual machine computing resource information of a host machine are acquired; determining a target CPU share of each virtual machine process according to the host machine computing resource information and the virtual machine computing resource information; setting a CPU limit of each virtual machine process according to the target CPU share; and / or according to the host machine computing resource information and the virtual machine computing resource information, determining the memory soft limitation of each virtual machine process; and setting the memory limit of each virtual machine process according to the memory soft limit.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of cloud computing technology, and in particular to a method and device for setting a virtual machine computing resource limit. Background Art

[0002] The core work of cloud computing virtualization technology is to effectively manage the three major resources of computing, storage, and network, and allocate them to virtual machines so that virtual machines can run efficiently and provide services to the outside world. The most important computing resources of virtual machines include CPU (central processing unit) and Memory. Multiple virtual machines run on the same host at the same time, so they share the CPU and Memory resources on the host. When the CPU and Memory resources on the host are tight, there will be preemption between virtual machines. At this time, the performance of the virtual machine will drop rapidly, and in serious cases, it will affect the business inside the virtual machine. Therefore, it is necessary to reasonably set and schedule the computing resources available to the virtual machine to ensure the reliable operation of the virtual machines of important businesses and the stability of the host, which has become an urgent problem to be solved. Summary of the invention

[0003] To overcome the problems existing in the related art, this specification provides a method and device for setting a virtual machine computing resource limit.

[0004] According to a first aspect of an embodiment of the present specification, a method for setting a virtual machine computing resource limit is provided, which is applied to a host machine, wherein at least one virtual machine is running in the host machine, and the method comprises: when a virtual machine lifecycle operation event is monitored, obtaining host computing resource information and virtual machine computing resource information of the host machine; determining a target CPU share for each virtual machine process based on the host computing resource information and the virtual machine computing resource information; setting a CPU limit for each virtual machine process based on the target CPU share; and / or determining a memory soft limit for each virtual machine process based on the host computing resource information and the virtual machine computing resource information; and setting a memory limit for each virtual machine process based on the memory soft limit.

[0005] According to a second aspect of an embodiment of the present specification, there is provided a device for setting a virtual machine computing resource limit, which is applied to a host machine, wherein at least one virtual machine is running in the host machine, and the device comprises: an acquisition module, which is used to acquire host computing resource information and virtual machine computing resource information of the host machine when a virtual machine life cycle operation event is monitored; a CPU share determination module, which is used to determine a target CPU share of each virtual machine process based on the host computing resource information and the virtual machine computing resource information; a CPU limit module, which is used to set a CPU limit of each virtual machine process based on the target CPU share; and / or a memory soft limit determination module, which is used to determine a memory soft limit of each virtual machine process based on the host computing resource information and the virtual machine computing resource information; a memory limit module, which is used to set a memory limit of each virtual machine process based on the memory soft limit.

[0006] According to a third aspect of an embodiment of this specification, there is provided a device for setting a virtual machine computing resource limit, including:

[0007] processor;

[0008] a memory for storing processor-executable instructions;

[0009] The processor is configured to: when a virtual machine lifecycle operation event is monitored, obtain host computing resource information and virtual machine computing resource information of the host machine; determine the target CPU share of each virtual machine process based on the host computing resource information and the virtual machine computing resource information; set the CPU limit of each virtual machine process based on the target CPU share; and / or determine the memory soft limit of each virtual machine process based on the host computing resource information and the virtual machine computing resource information; set the memory limit of each virtual machine process based on the memory soft limit.

[0010] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:

[0011] In the embodiments of this specification, the available computing resources of the host machine can be automatically sensed to facilitate allocation to the virtual machine. The available computing resources of the virtual machine can be automatically calculated to facilitate setting resource limits. The computing resource limits of all running virtual machines are automatically set to improve the stability of the host machine and the performance of the virtual machine, and ensure the normal operation of important business virtual machines.

[0012] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present specification. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the specification and, together with the description, serve to explain the principles of the specification.

[0014] Figure 1 The present specification is a flowchart of a method for setting a virtual machine computing resource quota according to an exemplary embodiment.

[0015] Figure 2A It is a schematic diagram of the architecture of the vmagent program shown in this specification according to an exemplary embodiment.

[0016] Figure 2B It is a schematic diagram of a heartbeat connection according to an exemplary embodiment of the present specification.

[0017] Figure 3 The present specification is a flowchart of a method for setting a virtual machine computing resource quota according to another exemplary embodiment.

[0018] Figure 4 The present specification is a flowchart of another method for setting a virtual machine computing resource quota according to an exemplary embodiment.

[0019] Figure 5 It is a hardware structure diagram of the computer device where the device for calculating resource limits of the virtual machine in the embodiment of this specification is located.

[0020] Figure 6 The present specification is a block diagram of a device for calculating resource limits of a virtual machine according to an exemplary embodiment. DETAILED DESCRIPTION

[0021] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.

[0022] The terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit this specification. The singular forms "a", "the" and "the" used in this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0023] It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0024] Next, the embodiments of this specification are described in detail.

[0025] The following is a detailed description of the method for setting a virtual machine computing resource limit provided in the embodiments of this specification. Figure 1 As shown, Figure 1 This is a flowchart of a method for setting a virtual machine computing resource limit according to an exemplary embodiment of this specification. The method can be applied to a host machine in which at least one virtual machine is running. The method for setting a virtual machine computing resource limit provided in the embodiment of this specification may include the operations shown below.

[0026] In operation 110, when a virtual machine lifecycle operation event is monitored, host computing resource information and virtual machine computing resource information of the host are obtained.

[0027] According to an embodiment of the present specification, the host computing resource information includes the host's CPU frequency resource information and memory resource information, etc. The virtual machine computing resource information may include, for example, the virtual machine's CPU resource reservation ratio, the number of virtual machine CPUs, the CPU priority, the number of large page memories, and the memory reservation, etc.

[0028] In operation 120 , a target CPU share for each virtual machine process is determined based on the host machine computing resource information and the virtual machine computing resource information.

[0029] According to an embodiment of the present specification, if the CPU resource reservation ratio of at least one virtual machine is 0, then for each virtual machine, a preset CPU share corresponding to the CPU priority of the virtual machine is determined as the target CPU share of the virtual machine. If the CPU resource reservation ratio of at least one virtual machine is not 0, then for each virtual machine, the target CPU share of the virtual machine is determined based on the CPU resource reservation ratio of the virtual machine, the number of CPUs of the virtual machine, the CPU priority, and the CPU resource information of the host machine.

[0030] In operation 130 , a CPU limit of each virtual machine process is set according to the target CPU share.

[0031] It should be noted that if there is no need to set the CPU limit of the virtual machine process, operations 120 to 130 may be omitted.

[0032] In operation 140 , a memory soft limit of each virtual machine process is determined based on the host machine computing resource information and the virtual machine computing resource information.

[0033] According to an embodiment of the present specification, if the number of huge page memory is 0, the virtual machine memory resource reservation, memory priority, and memory resource information of the host machine are used to determine the virtual machine process memory soft limit. If the number of huge page memory is not 0, the virtual machine process memory soft limit is determined based on the host machine memory resource information.

[0034] In step 150, a memory quota for each virtual machine process is set according to the memory soft limit.

[0035] It should be noted that if there is no need to set the memory limit of the virtual machine process, operations 140 to 150 may be omitted.

[0036] According to the method for setting the virtual machine computing resource limit in the embodiment of this specification, the available computing resources of the host machine can be automatically sensed and conveniently allocated to the virtual machine. The available computing resources of the virtual machine can be automatically calculated to facilitate setting the resource limit. The computing resource limit of all running virtual machines is automatically set to improve the stability of the host machine and the performance of the virtual machine, and ensure the normal operation of important business virtual machines.

[0037] According to an embodiment of this specification, the host computing resource information may include, for example:

[0038] HostCpuFrequenceTotal: the total frequency of all CPU logical cores of the host;

[0039] VmCpuPrioritySum: the sum of CPU priorities of all running virtual machines;

[0040] VmCpuGuranteeSum: the sum of CPU reserved frequencies of all running virtual machines;

[0041] HostMemoryTotal: total memory of the host;

[0042] VmMemoryPrioritySum: the sum of the memory priority weights of all running virtual machines;

[0043] VmMemoryGuranteeSum: the sum of memory reservations of all running virtual machines;

[0044] HostHugepageTotal: The host's huge page memory size.

[0045] According to an embodiment of this specification, virtual machine computing resource information may include, for example:

[0046] VmCpus: number of CPUs in the virtual machine;

[0047] VmCpuGurantee: virtual machine CPU resource reservation size, unit MHz;

[0048] VmCpuCgroupShares: virtual machine process cgroup cpu shares value, used to control the CPU ratio of the process;

[0049] VmCpuPriority: virtual machine CPU priority, the value can include 1, 2, 4, for example, indicating low priority, medium priority, and high priority respectively;

[0050] VmMemoryGurantee: The percentage of virtual machine memory resources reserved. The value can be 0-100.

[0051] VmMemoryCurrentSize: The current configuration size of the virtual machine Memory;

[0052] VmMemoryHugepages: number of virtual machine memory large pages;

[0053] VmMemoryPriority: virtual machine memory priority. The value can be 1, 2, or 4, which represent low, medium, and high priorities, respectively. The corresponding weight values ​​can be 0.6, 0.8, or 1.0, respectively.

[0054] VmMemoryCgroupSoftlimit: The virtual machine process cgroup memory softlimit value is used to control the maximum memory allocation value of the process.

[0055] Based on this, if the VmCpuGurantee of a virtual machine under the host is not 0, the target CPU share VmCpuCgroupShares of all virtual machines can be calculated according to the following formula:

[0056] VmCpuCgroupShare

[0057] =VmCpuGurantee*VmCpus+(HostCpuFrequenceTota

[0058] -VmCpuGuranteeSum)*VmCpuPriority / VmCpuPrioritySum

[0059] If the VmMemoryGurantee of all virtual machines under the host is 0, the VmCpuCgroupShares of all virtual machines can be calculated according to the following formula:

[0060] VmCpuCgroupShares = cpusjares value corresponding to VmCpuPriority

[0061] Exemplarily, in this embodiment, when VmCpuPriority is low, the corresponding cpu shares value may be 256, when VmCpuPriority is medium, the corresponding cpu shares value may be 512, and when VmCpuPriorit is high, the corresponding cpu shares value may be 1024.

[0062] In addition, if the number of huge page memory of the virtual machine is 0, the virtual machine's memory soft limit VmMemoryCgroupSoftlimit can be calculated according to the following formula:

[0063] VmMemoryCgroupSoftlimit

[0064] =(HostMemoryTotal-HostHugepageTotal

[0065] —VmMemoryGuranteeSum)*VmMemoryCurrentSize

[0066] *VmMemoryPriority / VmMemoryPrioritySum

[0067] +VmMemoryCurrentSize*VmMemoryGurantee / 100

[0068] If the number of huge page memory of the virtual machine is 0, it means that the huge page memory function is enabled in the virtual machine, and the free memory amount VmMemoryCurrentSize of the host machine can be used as the soft memory limit of the virtual machine process. That is, the virtual machine can use any memory within the range of VmMemoryCurrentSize without restriction.

[0069] Optionally, for example, the host computing resource information can be stored in the global variable HostComputeInfo. For example, the virtual machine computing resource information can be stored in the global variable VmComputeInfo. When resource limits are required, HostComputeInfo and VmComputeInfo can be read and used to calculate VmCpuCgroupShares and / or

[0070] VmMemoryCgroupSoftlimit.

[0071] Optionally, a virtual machine agent and virtualization management software may be running in the host machine. Based on this, the virtual machine agent may establish a connection pool, which includes at least one connection for connecting to the virtualization management software. When setting the CPU limit of each virtual machine process according to the target CPU share, the virtual machine agent obtains a connection from the connection pool. Then, the virtual machine agent sends a CPU limit setting request to the virtualization management software through the connection obtained from the connection pool.

[0072] When setting the memory limit of each virtual machine process according to the memory soft limit, the virtual machine agent can obtain a connection from the connection pool, and then send a memory limit setting request to the virtualization management software through the connection obtained from the connection pool.

[0073] The virtualization management software may be disconnected due to abnormalities, restarts, and other factors. In order to ensure that the virtual machine agent is connected to the virtualization management software normally, the virtual machine agent can also periodically send heartbeat signals to the virtualization management software through the connection obtained from the connection pool. If the virtual machine agent does not receive a response to the heartbeat signal sent by the virtualization management software after the keep-alive period, it cleans up the connection pool and virtual life cycle operation events, and sends a reconnection request to the virtualization management software at a predetermined time interval. Among them, the keep-alive period and the predetermined time interval can be set according to actual needs. When the virtualization management software program resumes normal operation, the virtual machine agent will successfully reconnect to the virtualization management software, and then re-establish the heartbeat connection, re-establish the connection pool, update the host computing resource information, update the virtual machine computing resource information, and register the virtual machine life cycle operation event.

[0074] Exemplarily, in this embodiment, the virtual machine agent program may be, for example, vmagent, and the virtualization management software may be, for example, Libvirt.

[0075] Libvirt is a software specifically used to manage virtualization hypervisors such as KVM, VMware, and LXC. It supports management operations of virtual machine lifecycle (virtual machine startup, migration, snapshot, etc.), storage lifecycle, network lifecycle, and other virtualization modules. It provides some interfaces for setting virtual machine process cgroup. Cgroup is a technology for controlling process resources on Linux. A virtual machine is just a process for the host machine. Therefore, Libvirt can set limits on virtual machine computing resources through cgroup.

[0076] Libvirt can only manage the computing resources of a single virtual machine, but multiple virtual machines on the host machine share computing resources (CPU, Memory). When one of the virtual machines is shut down, started up, or CPU hot-added due to lifecycle management operations, the amount of computing resources available to other running virtual machines on the host machine will change. Libvirt cannot perceive the changes in the available computing resources of the host machine, and cannot adjust the available computing resources of the running virtual machines, nor can it automatically reset the computing resource limits of these running virtual machines. In this way, the remaining running virtual machines will be affected in performance due to the preemption of computing resources, and cannot reasonably use the computing resources on the host machine.

[0077] The following combination Figure 2A and Figure 2B The vmagent program of the embodiment of this specification is described.

[0078] Figure 2A It is a schematic diagram of the architecture of the vmagent program shown in this specification according to an exemplary embodiment.

[0079] like Figure 2A As shown, the vmagent program may include, for example, a heartbeat reconnection module, a connection pool, a task distribution module, a virtual machine hash table, etc. The vmagent program may be used to manage available computing resources of the host machine, manage available computing resources of the virtual machine, set virtual machine resource limits, and the like.

[0080] In this embodiment, the heartbeat connection module can be used to implement the heartbeat connection. Figure 2B It is a schematic diagram of a heartbeat connection according to an exemplary embodiment of the present specification.

[0081] like Figure 2BAs shown, the Libvirt program may be disconnected due to abnormalities, restarts, and other factors, and vmagent needs to obtain virtual machine computing resource information and life cycle operations through the Libvirt program to automatically set the virtual machine computing resource limit. Therefore, it is necessary to ensure that vmagent and the Libvirt program are connected normally. The connection of the Libvirt program supports a keep-alive mechanism. When establishing a connection, vmagent sets a keep-alive period and registers a callback function after the connection is disconnected, which is called a heartbeat connection. When the Libvirt program is abnormal and the connection is disconnected, the heartbeat connection module of vmagent will clean up the connection used for heartbeat, clean up the connection in the connection pool, and clean up the virtual machine life cycle operation events, and try to connect to the Libvirt program every n seconds, where n is a positive number, such as 1. When the Libvirt program resumes normal operation, the heartbeat connection module of vmagent will reconnect to Libvirt successfully, and then re-establish the heartbeat connection, re-establish the connection pool, update the host computing resource information, update the virtual machine computing resource information, and register the virtual machine life cycle operation events.

[0082] Obtaining host computing resource information, obtaining virtual machine computing resource information, and setting virtual machine computing resource limits need to be implemented through the Libvirt API interface. vmagent calls the Libvirt API interface, which is a remote procedure call. Therefore, a connection that carries the API interface needs to be established between vmagent and Libvirt. When there are multiple tasks that need to be processed by vmagent at the same time, you can directly take a connection from the connection pool; after the task processing is completed, put the connection back into the connection pool. In this way, the connection pool connection can be reused, saving the time of establishing and releasing connections, which is more efficient; at the same time, it can also prevent vmagent from failing to set virtual machine computing resource limits due to short-term task accumulation, thereby improving stability. When vmagent is started, a certain number of connections are initially created. When vmagent is busy, the connections may be used up. At this time, some connections can be temporarily expanded; when vmagent is idle, the expanded connections are recycled to restore the initial number of connections.

[0083] According to the embodiments of this specification, in order to realize the automatic setting of virtual machine computing resource limits, it is necessary to process virtual machine life cycle operation type tasks and set virtual machine computing resource limit type tasks. The task distribution module needs to create a thread pool. When there is a virtual machine life cycle operation on the Libvirt side, vmagent will receive a life cycle operation event message, and the message body contains the virtual machine name, virtual machine UUID, event type, and detailed cause of the event. Then vmagent generates virtual machine life cycle operation type tasks and / or set virtual machine computing resource limit type tasks, and distributes the tasks to an idle thread in the thread pool (hereinafter referred to as a working thread).

[0084] According to the embodiments of the present specification, in order to correctly execute the task, it is necessary to record the key information of the task and pass it to the corresponding work thread. The key information of the task includes: JobType (task type), JobEventType (virtual machine life cycle event type in the task), JobEventDetail (detailed cause of the virtual machine life cycle event in the task), VmName (virtual machine name), and VmUUID (virtual machine UUID).

[0085] Exemplarily, in this embodiment, the virtual machine lifecycle operation type tasks may include, for example, detailed reasons for the following events: virtual machine startup, virtual machine shutdown, virtual machine migration, virtual machine snapshot, virtual machine snapshot restore, virtual machine hibernation, virtual machine hibernation recovery, virtual machine CPU resource change, virtual machine memory resource change.

[0086] Exemplarily, in this embodiment, a task of setting a virtual machine computing resource limit type may include, for example, the following detailed reasons for the event: setting a virtual machine CPU resource limit, setting a virtual machine Memory resource limit.

[0087] According to the embodiments of this specification, the virtual machine computing resource limit is set for the virtual machines in the running state (referred to as the running state) on the host machine. There may be many virtual machines in the running state for a period of time, so it is necessary to save the computing resource information of all running virtual machines. Exemplarily, in this embodiment, a virtual machine hash table (referred to as the hash table) can be used, with the virtual machine UUID as the key of the hash table and the virtual machine computing resource information as the value of the hash table.

[0088] When a virtual machine lifecycle operation causes the virtual machine to change from a shutdown state to a running state, the virtual machine is added to the hash table; when a virtual machine lifecycle operation causes the virtual machine computing resources to change, the value of the virtual machine computing resources in the hash table is updated; when a virtual machine lifecycle operation causes the virtual machine to change from a running state to a shutdown state, the virtual machine is deleted from the hash table.

[0089] When setting the computing resource limits of all virtual machines on the host machine, all virtual machines can be traversed from the hash table, and the computing resource limits of the virtual machines can be set one by one.

[0090] According to the embodiment of the present specification, when the vmagent program is started, the configuration file / proc / cpuinfo can be read from the host machine to set HostCpuFrequenceTotal, and the configuration file / proc / meminfo can be read from the host machine to set HostMemoryTotal and HostHugepageTotal. When the virtual machine running state changes, the virtual machine CPU priority changes, the virtual machine memory priority changes, the virtual machine hot adds CPU, and the virtual machine hot adds memory, VmCpuPrioritySum, VmCpuGuranteeSum, VmMemoryPrioritySum, and VmMemoryGuranteeSum are updated.

[0091] When a virtual machine is created, the information of VmCpus, VmCpuGurantee, VmCpuPriority, VmMemoryGurantee, VmMemoryCurrentSize, VmMemoryHugepages, and VmMemoryPriority are determined, and users can adjust these values ​​later if needed. After receiving the virtual machine lifecycle operation, vmagent saves the virtual machine computing resource information to VmComputeInfo.

[0092] like Figure 3 FIG. 1 is a flowchart of a method for setting a virtual machine computing resource limit according to another exemplary embodiment. Based on the above-mentioned embodiment, this embodiment describes a process of setting a CPU limit, including the following steps:

[0093] When there is a VM lifecycle operation on the Libvirt side, vmagent will receive an event message of the lifecycle operation task, which may include, for example, the VM name, VM UUID (Universally Unique Identifier), event type, and detailed cause of the event. vmagent updates HostComputeInfo, and if the VM hash table is not empty, updates VmComputeInfo of all VMs, and then distributes tasks of setting VM computing resource limits.

[0094] For virtual machine computing resource quota type tasks, first traverse all virtual machines and calculate VmCpuCgroupShares. If the VmCpuGurantee of a virtual machine under the host is not 0, the VmCpuCgroupShares of all virtual machines can be calculated according to the following formula:

[0095] VmCpuCgroupShares

[0096] =VmCpuGurantee*VmCpus+(HostCpuFrequenceTotal

[0097] —VmCpuGuranteeSum)*VmCpuPriority / VmCpuPrioritySum

[0098] If the VmCpuGurantee of all virtual machines under the host is 0, the VmCpuCgroupShares of all virtual machines can be calculated according to the following formula:

[0099] VmCpuCgroupShares = cpushares value corresponding to VmCpuPriority

[0100] Exemplarily, in this embodiment, when VmCpuPriority is low, the corresponding cpu shares value may be 256, when VmCpuPriority is medium, the corresponding cpu shares value may be 512, and when VmCpuPriorit is high, the corresponding cpu shares value may be 1024.

[0101] Then, you can traverse all virtual machines and call the Libvirt API to set the virtual machine process cgroupcpu.shares (CPU ratio) value.

[0102] like Figure 4 FIG. 1 is a flowchart of a method for setting a virtual machine computing resource quota according to another exemplary embodiment. Based on the above-mentioned embodiment, this embodiment describes a process of setting a memory quota, including the following steps:

[0103] When there is a VM lifecycle operation on the Libvirt side, vmagent receives the event message of the lifecycle operation task. vmagent updates HostComputeInfo and, if the VM hash table is not empty, updates VmComputeInfo of all VMs, and then distributes the task of setting VM computing resource limit. The detailed reason of the event is setting VM Memory resource limit.

[0104] For tasks of setting the virtual machine memory resource limit type, first traverse all virtual machines and calculate VmMemoryCgroupSoftlimit. If VmMemoryHugepages is 0, calculate VmMemoryCgroupSoftlimit according to the following formula:

[0105] VmMemoryCgroupSoftlimi

[0106] =(HostMemoryTotal-HostHugepageTota

[0107] -VmMemoryGuranteeSum)*VmMemoryCurrentSiz

[0108] *VmMemoryPriority / VmMemoryPrioritySu

[0109] +VmMemoryCurrentSize*VmMemoryGurantee / 100

[0110] Then, you can traverse all virtual machines and call the Libvirt API to set the virtual machine process cgroupmemory.soft_limit_in_bytes value.

[0111] If VmMemoryHugepages is not 0, it means that the large page memory function is enabled for the virtual machine, and the VmMemoryCurrentSize configured for the virtual machine can be used without restriction.

[0112] Corresponding to the embodiments of the aforementioned method, this specification also provides embodiments of an apparatus for setting a virtual machine computing resource limit and a terminal to which it is applied.

[0113] The embodiments of the apparatus for setting the computing resource limit of a virtual machine in this specification can be applied to computer devices, such as servers or terminal devices. The apparatus embodiments can be implemented by software, or by hardware, or by a combination of software and hardware. Taking software implementation as an example, as a logically sensed apparatus, the processor in which the apparatus is located reads the corresponding computer program instructions in the non-volatile memory into the memory and runs the instructions. From the hardware level, if Figure 5 As shown, it is a hardware structure diagram of a computer device where the device for setting the virtual machine computing resource limit in the embodiment of this specification is located, except Figure 5In addition to the processor 510, memory 530, network interface 520, and non-volatile memory 540 shown, the server or electronic device where the device 531 is located in the embodiment may also include other hardware according to the actual function of the computer device, which will not be described in detail.

[0114] like Figure 6 As shown, Figure 6 This is a block diagram of a device for setting a virtual machine computing resource limit according to an exemplary embodiment of the present specification, the device comprising:

[0115] The acquisition module 610 is used to acquire the host computing resource information and the virtual machine computing resource information of the host machine when a virtual machine life cycle operation event is monitored;

[0116] A CPU share determination module 620, configured to determine a target CPU share for each virtual machine process based on host machine computing resource information and virtual machine computing resource information;

[0117] A CPU quota module 630 is used to set a CPU quota for each virtual machine process according to a target CPU share; and / or

[0118] A memory soft limit determination module 640 is used to determine the memory soft limit of each virtual machine process according to the host computing resource information and the virtual machine computing resource information;

[0119] The memory quota module 650 is used to set the memory quota of each virtual machine process according to the memory soft limit.

[0120] Optionally, the host computing resource information includes CPU resource information of the host, and the virtual machine computing resource information includes a CPU resource reservation ratio of the virtual machine, a number of CPUs of the virtual machine, and a CPU priority; the CPU share determination module may include:

[0121] A first determination submodule is used to determine, for each virtual machine, a preset CPU share corresponding to the CPU priority of the virtual machine as a target CPU share of the virtual machine if the CPU resource reservation ratio of at least one virtual machine is 0;

[0122] The second determination submodule is used to determine the target CPU share of each virtual machine based on the CPU resource reservation ratio of the virtual machine, the number of CPUs of the virtual machine, the CPU priority, and the CPU resource information of the host machine if the CPU resource reservation ratio of at least one virtual machine is not 0.

[0123] Optionally, the host computing resource information includes the host memory resource information, and the virtual machine computing resource information includes the number of large page memories and the memory reservation of the virtual machine; the memory soft limit determination module may include:

[0124] The third determination submodule is used to determine the soft limit of the memory of the virtual machine process based on the memory resource reservation amount, memory priority, and memory resource information of the host machine if the number of large page memory is 0;

[0125] The fourth determination submodule is used to determine the memory soft limit of the virtual machine process according to the memory resource information of the host machine if the large page memory quantity is not 0.

[0126] Optionally, a virtual machine agent program and virtualization management software are running in the host machine, and the device may further include:

[0127] The establishing module is used to establish a connection pool, wherein the connection pool includes at least one connection for connecting to the virtualization management software.

[0128] CPU quota modules can include:

[0129] A first connection acquisition submodule is used for the virtual machine agent to acquire a connection from a connection pool;

[0130] The first sending submodule is used for the virtual machine agent to send a CPU limit setting request to the virtualization management software through a connection obtained from the connection pool.

[0131] Memory quota modules can include:

[0132] The second connection acquisition submodule is used for the virtual machine agent to acquire a connection from the connection pool;

[0133] The second sending submodule is used for the virtual machine agent to send a memory limit setting request to the virtualization management software through a connection obtained from the connection pool.

[0134] Optionally, the device may further include:

[0135] A third connection acquisition module is used for the virtual machine agent to periodically send a heartbeat signal to the virtualization management software through a connection obtained from the connection pool;

[0136] The cleaning module is used to clean up the connection pool and virtual life cycle operation events if the virtual machine agent program does not receive a response to the heartbeat signal sent by the virtualization management software after the keep-alive period, and send a reconnection request to the virtualization management software at a predetermined time interval.

[0137] According to the device for setting the virtual machine computing resource limit in the embodiment of the present specification, the available computing resources of the host machine can be automatically sensed and conveniently allocated to the virtual machine. The available computing resources of the virtual machine can be automatically calculated to facilitate setting the resource limit. The computing resource limit of all running virtual machines is automatically set to improve the stability of the host machine and the performance of the virtual machine, and ensure the normal operation of important business virtual machines.

[0138] Accordingly, the present specification also provides a device for setting a virtual machine computing resource limit, the device comprising a processor; a memory for storing processor executable instructions; wherein the processor is configured to: when a virtual machine lifecycle operation event is monitored, obtain host computing resource information and virtual machine computing resource information of the host machine; determine the target CPU share of each virtual machine process based on the host computing resource information and the virtual machine computing resource information; set the CPU limit of each virtual machine process based on the target CPU share; and / or determine the memory soft limit of each virtual machine process based on the host computing resource information and the virtual machine computing resource information; set the memory limit of each virtual machine process based on the memory soft limit.

[0139] The implementation process of the functions and effects of each module in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, which will not be repeated here.

[0140] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. A person of ordinary skill in the art can understand and implement it without paying creative labor.

[0141] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0142] Those skilled in the art will readily appreciate other embodiments of the specification after considering the specification and practicing the invention claimed herein. The specification is intended to cover any variations, uses or adaptations of the specification that follow the general principles of the specification and include common knowledge or customary techniques in the art that are not claimed in the specification. The specification and examples are to be considered exemplary only, and the true scope and spirit of the specification are indicated by the following claims.

[0143] It should be understood that the present description is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present description is limited only by the appended claims.

[0144] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.

Claims

1. A method for setting a virtual machine computing resource limit, applied to a host machine, wherein at least one virtual machine is running on the host machine, characterized in that: The method comprises: When a virtual machine lifecycle operation event is detected, host computing resource information and virtual machine computing resource information of the host are obtained; Determine a target CPU share for each virtual machine process based on the host computing resource information and the virtual machine computing resource information; set a CPU limit for each virtual machine process based on the target CPU share; and / or The memory soft limit of each virtual machine process is determined according to the host computing resource information and the virtual machine computing resource information; and the memory quota of each virtual machine process is set according to the memory soft limit.

2. The method according to claim 1, characterized in that The host computing resource information includes CPU resource information of the host, and the virtual machine computing resource information includes the CPU resource reservation ratio of the virtual machine, the number of virtual machine CPUs, and the CPU priority; determining the CPU acquisition ratio of each virtual machine process according to the host computing resource information and the virtual machine computing resource information includes: If the CPU resource reservation ratio of the at least one virtual machine is 0, then for each virtual machine, a preset CPU share corresponding to the CPU priority of the virtual machine is determined as the target CPU share of the virtual machine; If the CPU resource reservation ratio of at least one virtual machine is not 0, for each virtual machine, the target CPU share of the virtual machine is determined according to the CPU resource reservation ratio of the virtual machine, the number of CPUs of the virtual machine, the CPU priority, and the CPU resource information of the host machine.

3. The method according to claim 1, characterized in that The host computing resource information includes the memory resource information of the host, and the virtual machine computing resource information includes the large page memory quantity and memory reservation amount of the virtual machine; The determining the memory soft limit of the virtual machine process according to the host computing resource information and the virtual machine computing resource information includes: If the large page memory quantity is 0, the virtual machine memory resource reservation, memory priority, and the host machine memory resource information are used to determine the virtual machine process memory soft limit; If the large page memory quantity is not 0, the memory soft limit of the virtual machine process is determined according to the memory resource information of the host machine.

4. The method according to any one of claims 1 to 3, characterized in that The host machine runs a virtual machine agent program and virtualization management software, and the method further includes: Establishing a connection pool, wherein the connection pool includes at least one connection for connecting to the virtualization management software; The step of setting a CPU limit for each virtual machine process according to the target CPU share includes: The virtual machine agent obtains a connection from the connection pool; The virtual machine agent sends a CPU limit setting request to the virtualization management software through a connection obtained from a connection pool; The step of setting the memory quota of each virtual machine process according to the memory soft limit includes: The virtual machine agent obtains a connection from the connection pool; The virtual machine agent sends a memory quota setting request to the virtualization management software through a connection obtained from a connection pool.

5. The method according to claim 4, characterized in that The method further comprises: The virtual machine agent program periodically sends a heartbeat signal to the virtualization management software through a connection obtained from a connection pool; If the virtual machine agent program does not receive a response to the heartbeat signal sent by the virtualization management software after the keep-alive period, the connection pool and virtual life cycle operation events are cleared, and a reconnection request is sent to the virtualization management software at a predetermined time interval.

6. A device for setting a virtual machine computing resource limit, applied to a host machine, wherein at least one virtual machine is running on the host machine, characterized in that: The device comprises: An acquisition module, used to acquire host computing resource information and virtual machine computing resource information of a host machine when a virtual machine life cycle operation event is detected; A CPU share determination module, used to determine the target CPU share of each virtual machine process according to the host computing resource information and the virtual machine computing resource information; a CPU quota module, used to set the CPU quota of each virtual machine process according to the target CPU share; and / or A memory soft limit determination module is used to determine the memory soft limit of each virtual machine process based on the host computing resource information and the virtual machine computing resource information; a memory quota module is used to set the memory quota of each virtual machine process based on the memory soft limit.

7. The device according to claim 6, characterized in that The host computing resource information includes the CPU resource information of the host, and the virtual machine computing resource information includes the CPU resource reservation ratio of the virtual machine, the number of virtual machine CPUs and the CPU priority; the CPU share determination module includes: A first determination submodule is used to determine, for each virtual machine, a preset CPU share corresponding to the CPU priority of the virtual machine as a target CPU share of the virtual machine if the CPU resource reservation ratio of the at least one virtual machine is 0; The second determination submodule is used to determine the target CPU share of each virtual machine based on the CPU resource reservation ratio of the virtual machine, the number of CPUs of the virtual machine, the CPU priority, and the CPU resource information of the host machine if the CPU resource reservation ratio of at least one virtual machine is not 0.

8. The device according to claim 6, characterized in that The host computing resource information includes the memory resource information of the host, and the virtual machine computing resource information includes the large page memory quantity and memory reservation amount of the virtual machine; The memory soft limit determination module comprises: A third determination submodule is used to determine the soft limit of the virtual machine process memory if the large page memory quantity is 0, the virtual machine memory resource reservation amount, memory priority, and the host machine memory resource information; The fourth determination submodule is used to determine the memory soft limit of the virtual machine process according to the memory resource information of the host machine if the large page memory quantity is not 0.

9. The device according to any one of claims 6 to 8, characterized in that The host machine runs a virtual machine agent program and virtualization management software, and the device also includes: An establishing module, used to establish a connection pool, wherein the connection pool includes at least one connection for connecting to the virtualization management software; The CPU quota module includes: A first connection acquisition submodule is used for the virtual machine agent to acquire a connection from a connection pool; A first sending submodule, configured for the virtual machine agent to send a CPU limit setting request to the virtualization management software through a connection obtained from a connection pool; The memory quota module includes: The second connection acquisition submodule is used for the virtual machine agent to acquire a connection from the connection pool; The second sending submodule is used for the virtual machine agent program to send a memory limit setting request to the virtualization management software through a connection obtained from a connection pool.

10. The device according to claim 9, characterized in that The device also includes: A third connection acquisition module, configured for the virtual machine agent to periodically send a heartbeat signal to the virtualization management software through a connection acquired from a connection pool; A cleaning module is used to clean up the connection pool and virtual life cycle operation events if the virtual machine agent program does not receive a response to the heartbeat signal sent by the virtualization management software after a keep-alive period, and send a reconnection request to the virtualization management software at a predetermined time interval.

Citation Information

Cited By

  • Tracking connection number control method and device of virtual machine, equipment and medium

    CN120929194A