A method for managing a virtual machine affinity group

By configuring affinity rules and affinity groups for virtual machines, the problem of inflexible virtual machine management in existing technologies is solved, achieving efficient utilization of physical host resources and improved virtual machine network performance.

CN113918278BActive Publication Date: 2026-02-10KYLIN CORP
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111105200.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-22
Publication Date
2026-02-10
Estimated Expiration
2041-09-22

AI Technical Summary

Technical Problem

Existing virtual machine management methods fail to flexibly configure affinity rules, resulting in low physical host resource utilization and poor network performance between virtual machines, and making it impossible to specify the deployment method of virtual machines according to requirements.

Method used

By configuring affinity rules and affinity groups for virtual machines, we can check for conflicts in running virtual machines and redeploy or migrate virtual machines according to the rules. For virtual machines to be started, we can select a suitable host for deployment to ensure that resource requirements are met.

Benefits of technology

It enables flexible configuration of virtual machines according to needs, improves the resource utilization of physical hosts and the network performance between virtual machines, and ensures that virtual machines are deployed on demand.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113918278B_ABST
    Figure CN113918278B_ABST
Patent Text Reader

Abstract

The application discloses a management method of a virtual machine affinity group, which comprises the following steps: configuring an affinity rule and an affinity group for a virtual machine; performing affinity rule checking on a running virtual machine and a virtual machine to be started, and performing virtual machine configuration according to the affinity rule. The method can specify which virtual machines are deployed on one host or are scattered to be deployed on different hosts, can also specify which virtual machines must be deployed on one host or must be scattered to be deployed on different hosts, can flexibly configure the virtual machines according to requirements, and improves the resource utilization of a physical host and the network performance between virtual machines.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of virtual machine configuration technology, and in particular to a method for managing virtual machine affinity groups. Background Technology

[0002] With the rapid development of virtualization and cloud computing technologies, enterprises and individual users can easily build virtualization platforms using multiple physical servers and storage devices, deploy virtual machines within these platforms, and achieve flexible and efficient use of resources to provide users with high-quality services.

[0003] In some virtualization environments, business needs necessitate the deployment of virtual machines (VMs) for different business applications across different physical hosts, either directly or as dispersedly as possible. For example, deploying VMs with different roles for Hadoop requires different physical hosts to improve overall system performance. Similarly, deploying VMs with primary and backup roles for high-availability applications also requires different physical hosts to ensure high availability. Other business requirements sometimes necessitate the deployment of multiple VMs on the same physical host. Current technologies typically manage VMs through load balancing or other rules, centrally or dispersedly deploying VMs across physical hosts based on these rules. However, there is no specific affinity rule configured for each VM, resulting in inflexible VM configuration. This lack of flexibility in specifying which types or groups of VMs should be deployed together or not, leads to low resource utilization of physical hosts and poor network performance between VMs. Summary of the Invention

[0004] This application provides a method for managing virtual machine affinity groups, which can flexibly configure virtual machines according to needs, improve the resource utilization of physical hosts and the network performance between virtual machines.

[0005] In view of this, this application provides a method for managing virtual machine affinity groups, including:

[0006] Configure affinity rules and affinity groups for the virtual machine;

[0007] For running virtual machines, periodically check if there are affinity rule conflicts. If there are affinity rule conflicts, redeploy the virtual machine according to the type of the conflicting affinity rule and the remaining resources of other hosts.

[0008] For a virtual machine to be started, check the affinity rules to which the virtual machine belongs, select the destination host to be deployed according to the affinity rules, and determine whether the remaining resources of the destination host meet the resource requirements of the virtual machine to be started. If they do, start the virtual machine on the destination host; otherwise, select another host that meets the conditions to deploy the virtual machine or do not start it.

[0009] Preferably, the affinity rules include positive affinity rules and negative affinity rules; the positive affinity rules include mandatory positive affinity group rules and non-mandatory positive affinity group rules; the negative affinity rules include mandatory negative affinity group rules and non-mandatory negative affinity group rules; and the affinity groups include positive affinity groups and negative affinity groups.

[0010] Preferably, for a running virtual machine, the step of selecting whether to migrate or shut down the virtual machine based on the type of the conflicting affinity rule and the remaining resources of other hosts includes: selecting the destination host to deploy the problematic virtual machine according to the affinity rule; detecting whether the remaining resources of the destination host meet the resource requirements of the problematic virtual machine; if the resource requirements of the problematic virtual machine are met, further determining whether there are other virtual machines being migrated in the environment; if there are no other virtual machines being migrated in the environment, starting to migrate the problematic virtual machine; if there are other virtual machines being migrated in the environment, not migrating the virtual machine and returning to the waiting detection interval.

[0011] If the resource requirements of the problematic virtual machine are not met, it is further determined whether the violated affinity rule is mandatory. If it is mandatory, the problematic virtual machine is shut down; if it is not mandatory, the process returns to the waiting detection interval.

[0012] Preferably, the steps for selecting another suitable host to deploy the virtual machine or not starting it when the destination host does not meet the requirements include:

[0013] Determine whether the violated affinity rule is non-mandatory. If it is non-mandatory, select other eligible hosts to deploy the virtual machine. If it is mandatory, do not start the virtual machine. The other eligible hosts are those selected based on the remaining affinity rules after removing the non-mandatory affinity rules.

[0014] Preferably, checking for affinity rule conflicts in virtual machines includes:

[0015] Cycle through all affinity groups:

[0016] Find virtual machines that violate the positive affinity rule;

[0017] Find virtual machines that violate the reverse affinity rule.

[0018] Preferably, the method for finding virtual machines that violate the positive affinity rule includes:

[0019] Step 101: Sort according to the positive affinity group ID, with m being the number of positive affinity groups and i being the variable;

[0020] Step 102: Traverse the positive affinity groups from smallest to largest to obtain the unified affinity group k corresponding to each positive affinity group.i ;

[0021] Step 103: Find the uniform affinity group k i The problematic virtual machines include:

[0022] Step 1031: Based on the unified affinity group k i Sort by virtual machine IDs, with x being the number of virtual machines;

[0023] Step 1032: Iterate through the x virtual machines from smallest to largest, with variable s. If the state of the s-th virtual machine is running, query the host where the s-th virtual machine is located.

[0024] Step 1033: Sort the queried hosts and obtain the deployment unified affinity group k. i Host A has the most virtual machines;

[0025] Step 1034: Iterate through the x virtual machines from smallest to largest, with variable t. If the t-th virtual machine is in a running state but not running on host A, then it is a problematic virtual machine.

[0026] Preferably, step 102 includes:

[0027] Step 1021: Iterate through the m positive affinity groups from smallest to largest, with variable i and unified affinity group k. i The list of virtual machines is equal to the list of virtual machines in the positive affinity group i;

[0028] Step 1022: For each uniform affinity group k i Perform the following operations, including: iterating through the mi positive affinity groups whose group ID is greater than that of the positive affinity group i in ascending order, with variable j; and iterating through the uniform affinity group k. i Find the intersection of the list of virtual machines in the unified affinity group j and the list of virtual machines in the positive affinity group j. If the intersection is not empty, then the unified affinity group k is determined. i The value of the virtual machine list is updated to the uniform affinity group k. i The union of the list of virtual machines with the positive affinity group j.

[0029] Preferably, methods for finding virtual machines that violate the reverse affinity rule include:

[0030] Step 201: Sort the reverse affinity groups according to their IDs. The number of reverse affinity groups is n.

[0031] Step 202: Iterate through the n reverse affinity groups from smallest to largest, with variable p. The initial value of the number of virtual machines in reverse affinity group p running on each host is set to 0. The virtual machines in reverse affinity group p are sorted by ID, with the number of virtual machines being y. Iterate through the y virtual machines from smallest to largest, with variable u. If the status of the u-th virtual machine is running, query the host where the u-th virtual machine is located and increment the number of virtual machines in reverse affinity group p running on that host by 1. If the number of virtual machines in reverse affinity group p running on that host is greater than 1, then the u-th virtual machine is the problematic virtual machine.

[0032] Preferably, it further includes:

[0033] When adding an affinity group, a conflict check is performed between the newly added affinity group and the existing affinity group. If a conflict exists, the addition of the affinity group fails, and the reason for the failure is displayed.

[0034] Preferably, when adding an affinity group, the affinity rule conflict detection between the newly added affinity group and the existing affinity group includes the following steps:

[0035] Step 301: Sort according to positive affinity group ID;

[0036] Step 302: Obtain the uniform affinity group k i ;

[0037] Step 303: Apply the uniform affinity group k i Perform a traversal, with variable i, to calculate the uniform affinity group k. i If the intersection of the virtual machine list with the reverse affinity group has more than 1 element, an affinity rule conflict is detected.

[0038] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:

[0039] This invention discloses a virtual machine affinity group management method. This method configures affinity rules and affinity groups for virtual machines; performs affinity rule checks on running virtual machines and virtual machines to be started; and configures virtual machines according to the affinity rules. It can specify which virtual machines should be deployed on a single host or distributed across different hosts, and can also specify which virtual machines must be deployed on a single host or distributed across different hosts. This allows for flexible configuration of virtual machines according to requirements, improving the resource utilization of physical hosts and the network performance between virtual machines. Attached Figure Description

[0040] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0041] Figure 1 This is a diagram showing the deployment changes of virtual machines after executing affinity rules in an embodiment of the present invention;

[0042] Figure 2 This is an operation flowchart for a running virtual machine in an embodiment of the present invention;

[0043] Figure 3 This is a flowchart illustrating the operation of a virtual machine to be started in an embodiment of the present invention;

[0044] Figure 4 This is a flowchart illustrating how to identify virtual machines that violate the positive affinity rule in an embodiment of the present invention;

[0045] Figure 5 This is a flowchart illustrating how to identify virtual machines that violate the reverse affinity rule in an embodiment of the present invention;

[0046] Figure 6 This is a flowchart illustrating the detection process for existing affinity rule conflicts in an embodiment of the present invention.

[0047] Figure 7 This is an example diagram illustrating the process of finding a list of virtual machines with a uniform affinity group in an embodiment of the present invention.

[0048] Figure 8 This is a schematic diagram illustrating an example of detecting conflicts in existing affinity rules in an embodiment of the present invention. Detailed Implementation

[0049] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.

[0050] This invention provides a method for managing virtual machine affinity groups, including:

[0051] Configure affinity rules and affinity groups for the virtual machines. After the rules are configured, the computer will perform automatic deployment of the virtual machines according to the configured rules.

[0052] For running virtual machines, periodically check for affinity rule conflicts. If a conflict is found, redeploy the virtual machine based on the type of the conflicting affinity rule and the remaining resources of other hosts. Here, "other hosts" refers to hosts other than the current host of the problematic virtual machine, selected according to the affinity rules for deployment. The process of checking for "other" hosts and executing affinity rules is detailed below. Figure 1 First, the virtual machines are configured into forward affinity groups and reverse affinity groups. Virtual machines with numbers 1 and 2 in the boxes belong to the forward affinity group, and the virtual machine with number 3 in the box belongs to the reverse affinity group. Before the forward affinity group rules are executed, there are 3 virtual machines on host A, 3 virtual machines on host B, and 3 virtual machines on host C. Forward affinity group 1 includes VM1 and VM2 on host A and VM4 on host B. Forward affinity group 2 includes VM3 on host A and VM5 and VM6 on host B. Reverse affinity group 3 includes VM7, VM8, and VM9 on host C. After the forward affinity group rules are executed, VM4 on host B and VM8 on host C are migrated to host A, and VM3 on host A and VM9 on host C are migrated to host B. The result is that the virtual machines in the forward affinity group 1 are all deployed on host A, the virtual machines in the forward affinity group 2 are all deployed on host B, and the virtual machines in the reverse affinity group 3 are deployed on different hosts.

[0053] For a virtual machine to be started, check the affinity rules to which the virtual machine belongs, select the destination host to be deployed according to the affinity rules, and determine whether the remaining resources of the destination host meet the resource requirements of the virtual machine to be started. If they do, start the virtual machine on the destination host; otherwise, select another host that meets the conditions to deploy the virtual machine or do not start it.

[0054] This embodiment improves the resource utilization of the physical host and the network performance between virtual machines by configuring affinity rules and affinity groups for virtual machines, allowing for flexible configuration of virtual machines according to needs.

[0055] Further, in one embodiment, the affinity rules include positive affinity rules and negative affinity rules. The positive affinity rules include mandatory positive affinity group rules and non-mandatory positive affinity group rules, and the negative affinity rules include mandatory negative affinity group rules and non-mandatory negative affinity group rules. The affinity groups include positive affinity groups and negative affinity groups. Mandatory positive affinity group rules specify which virtual machines must be deployed on a single host. Non-mandatory positive affinity group rules specify which virtual machines should be deployed on a single host as much as possible. Mandatory negative affinity group rules specify which virtual machines must be deployed across different hosts. Non-mandatory negative affinity group rules specify which virtual machines should be deployed across different hosts as much as possible.

[0056] In one embodiment, for a running virtual machine, the step of selecting whether to migrate or shut down the virtual machine based on the type of the conflicting affinity rule and the remaining resources of other hosts includes: selecting the destination host for the problematic virtual machine to be deployed according to the affinity rule; checking whether the remaining resources of the destination host meet the resource requirements of the problematic virtual machine; if the resource requirements of the problematic virtual machine are met, further determining whether there are other virtual machines being migrated in the environment; if there are no other virtual machines being migrated in the environment, starting the migration of the problematic virtual machine; if there are other virtual machines being migrated in the environment, not migrating the virtual machine, and returning to the waiting detection interval; if the resource requirements of the problematic virtual machine are not met, further determining whether the violated affinity rule is mandatory; if it is mandatory, shutting down the problematic virtual machine; if it is not mandatory, returning to the waiting detection interval. Virtual machine affinity group management of virtual machines includes two cases: for running virtual machines and virtual machines to be started. For running virtual machines, which have already been deployed to the host, migration or shutdown operations need to be performed on 0 or more virtual machines according to affinity rules. The operation process is as follows: Figure 2 As shown:

[0057] 1. Wait for the specified interval;

[0058] 2. Check the existing virtual machine distribution for any affinity rule conflicts;

[0059] 3. If it exists, select the problematic virtual machine;

[0060] 4. Select the destination host;

[0061] 5. Determine whether the remaining resources of the destination host meet the resource requirements of the problematic virtual machine. If they do, determine whether there are any other virtual machines being migrated in the environment. If so, migrate the problematic virtual machine and return to step 1. Otherwise, return directly to step 1.

[0062] 6. If the remaining resources of the destination host do not meet the resource requirements of the problematic virtual machine, determine whether the violated affinity rule is mandatory. If it is mandatory, shut down the problematic virtual machine and return to step 1; otherwise, return directly to step 1.

[0063] This embodiment enables running virtual machines to be flexibly configured according to business needs or other requirements. The computer can automatically deploy which running virtual machines must be deployed on one host, which virtual machines should be deployed on one host as much as possible, which virtual machines must be distributed across different hosts, and which virtual machines should be distributed across different hosts as much as possible, thus achieving intelligent deployment of virtual machines and improving the resource utilization of physical hosts and the network performance between virtual machines.

[0064] In an improved embodiment, the step of selecting other eligible hosts to deploy the virtual machine or not starting it when the destination host does not meet the requirements for the virtual machine to be started includes: determining whether the violated affinity rule is non-mandatory; if it is non-mandatory, selecting other eligible hosts to deploy the virtual machine; if it is mandatory, not starting the virtual machine; wherein, the other eligible hosts are other hosts selected according to the remaining affinity rules after removing the violated non-mandatory affinity rules. For the virtual machine to be started, it is deployed to the host during the startup process. It is necessary to determine which host to deploy on or not to start the virtual machine (startup failure) according to the affinity rules. For the operation process of the virtual machine to be started in this embodiment, please refer to [link to relevant documentation]. Figure 3 This includes the following steps:

[0065] 1. Start;

[0066] 2. Check all affinity rules to which the virtual machine belongs, and determine which running virtual machines in the current environment have positive affinity and which have negative affinity;

[0067] 3. Select the destination host according to the affinity rules;

[0068] 4. Determine if the remaining resources on the destination host meet the resource requirements of the virtual machine to be started. If they do, deploy the virtual machine to the destination host and start it successfully.

[0069] 5. If the remaining resources on the destination host do not meet the resource requirements of the virtual machine to be started, determine whether the affinity rule is mandatory. If mandatory, do not start the virtual machine. If not mandatory, select another host that meets the conditions to deploy the virtual machine, and start it successfully.

[0070] This embodiment enables flexible configuration of virtual machines (VMs) according to business or other requirements, and automatically manages the startup of VMs. It allows for the allocation of VMs, determining which running VMs must be deployed on a single host and which should ideally be deployed on a single host. It also allows for automatic deployment, distributing VMs across different hosts to improve physical host resource utilization and inter-VM network performance.

[0071] Furthermore, in one embodiment, checking whether a virtual machine has affinity rule conflicts includes:

[0072] Cycle through all affinity groups:

[0073] Find virtual machines that violate the positive affinity rule;

[0074] Find virtual machines that violate the reverse affinity rule.

[0075] If a virtual machine that violates the affinity rule is found, check if it can be migrated: if it can be migrated (the remaining resources of the destination host meet the resource requirements of the problematic virtual machine and there are no other virtual machines being migrated in the environment), then return the ID of the virtual machine to be migrated and migrate the problematic virtual machine.

[0076] Specifically, see Figure 4 Methods for finding virtual machines that violate the positive affinity rule include:

[0077] Methods for finding virtual machines that violate the positive affinity rule include:

[0078] Step 101: Sort according to the positive affinity group ID. The number of positive affinity groups is m, and the variable is i. The affinity group ID is one of the attributes of the affinity group, similar to the virtual machine ID. When adding, an ID will be assigned. For example, the first added affinity group has an ID of 0, and the second added affinity group has an ID of 1.

[0079] Step 102: Traverse the positive affinity groups from smallest to largest to obtain the unified affinity group k corresponding to each positive affinity group. i ;

[0080] Step 103: Find the uniform affinity group k i The problematic virtual machines include:

[0081] Step 1031: Based on the unified affinity group k i Sort by virtual machine IDs, with x being the number of virtual machines;

[0082] Step 1032: Iterate through the x virtual machines from smallest to largest, with variable s. If the state of the s-th virtual machine is running, query the host where the s-th virtual machine is located.

[0083] Step 1033: Sort the queried hosts and obtain the deployment unified affinity group k. i Host A has the most virtual machines;

[0084] Step 1034: Iterate through the x virtual machines from smallest to largest, with variable t. If the t-th virtual machine is in a running state but not running on host A, then it is a problematic virtual machine.

[0085] Furthermore, step 102 includes:

[0086] Step 1021: Iterate through the m positive affinity groups from smallest to largest, with variable i and unified affinity group k. i The list of virtual machines is equal to the list of virtual machines in the positive affinity group i;

[0087] Step 1022: For each uniform affinity group k iPerform the following operations, including: iterating through the mi positive affinity groups whose group ID is greater than that of the positive affinity group i in ascending order, with variable j; and iterating through the uniform affinity group k. i Find the intersection of the list of virtual machines in the unified affinity group j and the list of virtual machines in the positive affinity group j. If the intersection is not empty, then the unified affinity group k is determined. i The value of the virtual machine list is updated to the uniform affinity group k. i The union of the list of virtual machines with the positive affinity group j.

[0088] This embodiment sets up a program to traverse affinity groups, and adopts a method of first finding a unified affinity group and then finding the problematic host in the positive affinity group based on the unified affinity group. This can avoid conflicts in the currently set positive affinity groups, which could lead to inaccurate detection.

[0089] Further, see Figure 5 Methods for finding virtual machines that violate the reverse affinity rule include:

[0090] Step 201: Sort the reverse affinity groups according to their IDs. The number of reverse affinity groups is n.

[0091] Step 202: Iterate through the n reverse affinity groups from smallest to largest, with variable p. The initial value of the number of virtual machines in reverse affinity group p running on each host is set to 0. The virtual machines in reverse affinity group p are sorted by ID, with the number of virtual machines being y. Iterate through the y virtual machines from smallest to largest, with variable u. If the status of the u-th virtual machine is running, query the host where the u-th virtual machine is located and increment the number of virtual machines in reverse affinity group p running on that host by 1. If the number of virtual machines in reverse affinity group p running on that host is greater than 1, then the u-th virtual machine is the problematic virtual machine.

[0092] Using an automated computer traversal method, fewer calculations are required, and virtual machines that violate the reverse affinity rule can be found accurately and quickly.

[0093] In a further embodiment, the virtual machine affinity group management method further includes:

[0094] When adding an affinity group, a conflict check is performed between the newly added affinity group and existing affinity groups. If a conflict exists, adding the affinity group fails, and the reason for the failure is displayed. After receiving the exception notification, the affinity rules are reconfigured to prevent conflicting affinity rules from affecting virtual machine deployment when adding new rules.

[0095] Specifically, see Figure 6 When adding an affinity group, the affinity rule conflict detection between the newly added affinity group and the existing affinity group includes the following steps:

[0096] Step 301: Sort according to the positive affinity group ID, the number of positive affinity groups is m;

[0097] Step 302: Obtain the list of virtual machines with uniform affinity groups: Iterate through the m positive affinity groups from smallest to largest (variable i):

[0098] (1) Unified affinity group k i The list of virtual machines is equal to the list of virtual machines in the positive affinity group i.

[0099] (2) Iterate through the mi positive affinity groups whose group ID is greater than that of the positive affinity group i in ascending order (the variable is j):

[0100] 3) Unified affinity group k i Find the intersection of the list of virtual machines in the positive affinity group j and the list of virtual machines in the positive affinity group j.

[0101] 4) If the intersection is not empty, then the unified affinity set k is... i The list of virtual machines equals the unified affinity group k i The union of the list of virtual machines with the positive affinity group j;

[0102] Step 303: Find the intersection of the virtual machine lists of the unified affinity group and the reverse affinity group. If the number of elements in the intersection is greater than 1, an affinity rule conflict is detected.

[0103] To facilitate understanding of the management method execution process in the above embodiments, specific examples are now provided for illustration.

[0104] Example 1

[0105] Please provide a list of virtual machines with a unified affinity group, such as... Figure 7 As shown:

[0106] There are two positive affinity groups. The list of virtual machines in positive affinity group 1 is {VM1,VM2}, and the list of virtual machines in positive affinity group 2 is {VM2,VM3}.

[0107] The first step is to unify the list of virtual machines in the affinity group so that the list of virtual machines in the positive affinity group 1 is {VM1,VM2}.

[0108] The second step is to find the intersection of the virtual machine list {VM1,VM2} of the unified affinity group and the virtual machine list {VM2,VM3} of the positive affinity group 2. Their intersection is not empty, and the virtual machine list of the unified affinity group is equal to their union {VM1,VM2,VM3}.

[0109] Example 2

[0110] Existing affinity rule conflict detection, such as Figure 8 As shown:

[0111] The first and second steps are the same as those in Example 1.

[0112] The third step is to find the intersection of the list of virtual machines in the unified affinity group {VM1,VM2,VM3} and the list of virtual machines in the reverse affinity group 3 {VM1,VM3}. The intersection is {VM1,VM3}. If the number of elements in the intersection is greater than 1, an exception is thrown: Affinity rule conflict detected.

[0113] Example 3

[0114] Forward affinity group, forced, the remaining resources of the destination host meet the resource requirements of the virtual machine to be migrated.

[0115] There are two hosts: host A runs two virtual machines (VMs), and host B runs one VM. A new positive affinity group is created, enforced, to include the two VMs on host A and the one VM on host B. The remaining resources on host A are sufficient to meet the resource requirements of the VM running on host B.

[0116] Wait for the specified interval to observe the migration of virtual machines from host B to host A.

[0117] Example 4

[0118] Positive affinity group, forced, the remaining resources of the destination host do not meet the resource requirements of the virtual machine to be migrated.

[0119] There are two hosts: host A runs two virtual machines (VMs), and host B runs one VM. A new positive affinity group is created, enforced, to include the two VMs on host A and the one VM on host B. The remaining resources on host A are insufficient to meet the resource requirements of the VM running on host B.

[0120] Wait for the specified interval and check if the virtual machine on host B has been shut down.

[0121] Example 5

[0122] Positive affinity group, non-mandatory, the remaining resources of the destination host do not meet the resource requirements of the virtual machine to be migrated.

[0123] There are two hosts: host A runs two virtual machines (VMs), and host B runs one VM. A positive affinity group (not mandatory) is added, containing the two VMs from host A and the one VM from host B. The remaining resources on host A are insufficient to meet the resource requirements of the VM running on host B.

[0124] After waiting for the specified interval, the virtual machine on host B is still running and has not been migrated.

[0125] Example 6

[0126] Forward affinity group, forced, the remaining resources of the destination host meet the resource requirements of the virtual machine to be started.

[0127] There are two hosts. Host A runs one virtual machine, and there is one virtual machine that is shut down (not deployed to any host). Add a positive affinity group (forced) that includes the virtual machine on host A and the virtual machine to be started. The remaining resources on host A meet the resource requirements of the virtual machine to be started.

[0128] Start the virtual machine, wait for the specified interval, check the virtual machine status. Startup was successful, and the virtual machine is deployed on host A.

[0129] Example 7

[0130] Positive affinity group, forced, the remaining resources on the destination host do not meet the resource requirements of the virtual machine to be started.

[0131] There are two hosts. Host A runs one virtual machine and has one virtual machine that is shut down (not deployed to any host). A positive affinity group is added, enforced, to include the virtual machine on host A and the virtual machine to be started. The remaining resources on host A are insufficient to meet the resource requirements of the virtual machine to be started. The remaining resources on host B meet the resource requirements of the virtual machine to be started.

[0132] Start the virtual machine, wait for the specified interval, and check the virtual machine status. Startup failed and it remains in a shut-down state.

[0133] Example 8

[0134] Positive affinity group, non-mandatory, the remaining resources of the destination host do not meet the resource requirements of the virtual machine to be started.

[0135] There are two hosts. Host A runs one virtual machine and has one virtual machine that is shut down (not deployed to any host). Add a positive affinity group (not mandatory) containing the virtual machine on host A and the virtual machine to be started. The remaining resources on host A are insufficient to meet the resource requirements of the virtual machine to be started. The remaining resources on host B meet the resource requirements of the virtual machine to be started.

[0136] Start the virtual machine, wait for the specified interval, check the virtual machine status. If the startup is successful, deploy it to host B.

[0137] Example 9

[0138] Anti-affinity group, forced, the remaining resources of the destination host meet the resource requirements of the virtual machine to be migrated.

[0139] There are two hosts. Host A runs two virtual machines. A reverse affinity group is added, enforced, to include the two virtual machines on host A. The remaining resources on host B are sufficient to meet the resource requirements of the virtual machines running on host A.

[0140] Wait at the specified interval to see which virtual machine on host A has the larger ID number migrates to host B.

[0141] Example 10

[0142] Anti-affinity group, forced, the remaining resources of the destination host do not meet the resource requirements of the virtual machine to be migrated.

[0143] There are two hosts. Host A runs two virtual machines. A reverse affinity group is added, enforced, to include the two virtual machines on host A. The remaining resources on host B are insufficient to meet the resource requirements of the virtual machines running on host A.

[0144] Wait for the specified interval and check if any virtual machines on host A have migrated, and if the virtual machine with the larger ID number has been shut down.

[0145] Example 11

[0146] Anti-affinity group, non-mandatory, where the remaining resources on the destination host do not meet the resource requirements of the virtual machine to be migrated.

[0147] There are two hosts. Host A runs two virtual machines. Add a reverse affinity group (not mandatory) to include the two virtual machines from host A. The remaining resources on host B are insufficient to meet the resource requirements of the virtual machines running on host A.

[0148] Wait a specified interval and check the status of the two virtual machines on host A. They should be running and not yet migrated to host B.

[0149] Example 12

[0150] Anti-affinity group, forced, the remaining resources on the destination host meet the resource requirements of the virtual machine to be started.

[0151] There are two hosts. Host A runs one virtual machine and has one virtual machine that is shut down (not deployed to any host). Add a reverse affinity group, enforced, containing the virtual machine on host A and the virtual machine to be started. The remaining resources on host B are sufficient to meet the resource requirements of the virtual machine to be started.

[0152] Start the virtual machine, wait for the specified interval, check the virtual machine status. Startup was successful, and it was deployed on host B.

[0153] Example 13

[0154] Anti-affinity group, forced, the remaining resources of the destination host do not meet the resource requirements of the virtual machine to be started.

[0155] There are two hosts. Host A runs one virtual machine and has one virtual machine that is shut down (not deployed to any host). Add a reverse affinity group, enforced, including the virtual machine on host A and the virtual machine to be started. The remaining resources on host B are insufficient to meet the resource requirements of the virtual machine to be started. The remaining resources on host A meet the resource requirements of the virtual machine to be started.

[0156] Start the virtual machine, wait for the specified interval, and check the virtual machine status. Startup failed and it remains in a shut-down state.

[0157] Example 14

[0158] Anti-affinity group, non-mandatory, where the remaining resources on the destination host do not meet the resource requirements of the virtual machine to be started.

[0159] There are two hosts. Host A runs one virtual machine and has one virtual machine that is shut down (not deployed to any host). Add a reverse affinity group, enforced, including the virtual machine on host A and the virtual machine to be started. The remaining resources on host B are insufficient to meet the resource requirements of the virtual machine to be started. The remaining resources on host A meet the resource requirements of the virtual machine to be started.

[0160] Start the virtual machine, wait for the specified interval, check the virtual machine status. Startup was successful, and it was deployed on host A.

[0161] This application provides a method for managing virtual machine affinity groups. This involves configuring affinity rules and affinity groups for virtual machines; performing affinity rule checks on running virtual machines and virtual machines to be started; and configuring virtual machines according to the affinity rules. It allows specifying which virtual machines should be deployed on a single host or distributed across different hosts, or which virtual machines must be deployed on a single host or distributed across different hosts. This flexible configuration of virtual machines according to requirements improves the resource utilization of physical hosts and the network performance between virtual machines.

[0162] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A method for managing virtual machine affinity groups, characterized in that, include: Configure affinity rules and affinity groups for the virtual machine; For running virtual machines, periodically check if there are affinity rule conflicts. If there are affinity rule conflicts, decide whether to migrate or shut down the virtual machine based on the type of the conflicting affinity rule and the remaining resources of other hosts. For a virtual machine to be started, check the affinity rules to which the virtual machine belongs, select the destination host to be deployed according to the affinity rules, and determine whether the remaining resources of the destination host meet the resource requirements of the virtual machine to be started. If they do, start the virtual machine on the destination host; otherwise, select other hosts that meet the conditions to deploy the virtual machine or do not start it. Checking for affinity rule conflicts in virtual machines includes: Cycle through all affinity groups: Find virtual machines that violate the positive affinity rule; Find virtual machines that violate the reverse affinity rule; Methods for finding virtual machines that violate the positive affinity rule include: Step 101: Sort according to the positive affinity group ID, with m being the number of positive affinity groups and i being the variable; Step 102: Traverse the positive affinity groups from smallest to largest to obtain the unified affinity group k corresponding to each positive affinity group. i ; Step 102 includes: Step 1021: Iterate through the m positive affinity groups from smallest to largest, with variable i and unified affinity group k. i The list of virtual machines is equal to the list of virtual machines in the positive affinity group i; Step 1022: For each uniform affinity group k i Perform the following operations, including: iterating through the mi positive affinity groups whose group ID is greater than that of the positive affinity group i in ascending order, with variable j; and iterating through the uniform affinity group k. i Find the intersection of the list of virtual machines in the unified affinity group j and the list of virtual machines in the positive affinity group j. If the intersection is not empty, then the unified affinity group k is determined. i The value of the virtual machine list is updated to the uniform affinity group k. i The union of the list of virtual machines with the positive affinity group j; Step 103: Find the uniform affinity group k i The problematic virtual machines include: Step 1031: Based on the unified affinity group k i Sort by virtual machine IDs, with x being the number of virtual machines; Step 1032: Iterate through the x virtual machines from smallest to largest, with variable s. If the state of the s-th virtual machine is running, query the host where the s-th virtual machine is located. Step 1033: Sort the queried hosts and obtain the deployment unified affinity group k. i Host A has the most virtual machines; Step 1034: Iterate through the x virtual machines from smallest to largest, with variable t. If the t-th virtual machine is in a running state but not running on host A, then it is a problematic virtual machine.

2. The method for managing virtual machine affinity groups according to claim 1, characterized in that, The affinity rules include positive affinity rules and negative affinity rules. The positive affinity rules include mandatory positive affinity group rules and non-mandatory positive affinity group rules. The negative affinity rules include mandatory negative affinity group rules and non-mandatory negative affinity group rules. The affinity groups include positive affinity groups and negative affinity groups.

3. The method for managing virtual machine affinity groups according to claim 2, characterized in that, For a running virtual machine, the step of selecting whether to migrate or shut down the virtual machine based on the type of the conflicting affinity rule and the remaining resources of other hosts includes: selecting the destination host to deploy the problematic virtual machine according to the affinity rule; checking whether the remaining resources of the destination host meet the resource requirements of the problematic virtual machine; if the resource requirements of the problematic virtual machine are met, further determining whether there are other virtual machines being migrated in the environment; if there are no other virtual machines being migrated in the environment, starting to migrate the problematic virtual machine; if there are other virtual machines being migrated in the environment, not migrating the virtual machine and returning to the waiting detection interval. If the resource requirements of the problematic virtual machine are not met, it is further determined whether the violated affinity rule is mandatory. If it is mandatory, the problematic virtual machine is shut down; if it is not mandatory, the process returns to the waiting detection interval.

4. The method for managing virtual machine affinity groups according to claim 2, characterized in that, When a virtual machine is to be started, if the destination host does not meet the requirements, the steps to select another suitable host to deploy the virtual machine or not start it include: Determine whether the violated affinity rule is non-mandatory. If it is non-mandatory, select other eligible hosts to deploy the virtual machine. If it is mandatory, do not start the virtual machine. The other eligible hosts are those selected based on the remaining affinity rules after removing the non-mandatory affinity rules.

5. The method for managing virtual machine affinity groups according to claim 1, characterized in that, Methods for finding virtual machines that violate the reverse affinity rule include: Step 201: Sort the reverse affinity groups according to their IDs. The number of reverse affinity groups is n. Step 202: Iterate through the n reverse affinity groups from smallest to largest, with variable p. The initial value of the number of virtual machines in reverse affinity group p running on each host is set to 0. The virtual machines in reverse affinity group p are sorted by ID, with the number of virtual machines being y. Iterate through the y virtual machines from smallest to largest, with variable u. If the status of the u-th virtual machine is running, query the host where the u-th virtual machine is located and increment the number of virtual machines in reverse affinity group p running on that host by 1. If the number of virtual machines in reverse affinity group p running on that host is greater than 1, then the u-th virtual machine is the problematic virtual machine.

6. The method for managing virtual machine affinity groups according to claim 2, characterized in that, Also includes: When adding an affinity group, a conflict check is performed between the newly added affinity group and the existing affinity group. If a conflict exists, the addition of the affinity group fails, and the reason for the failure is displayed.

7. The method for managing virtual machine affinity groups according to claim 6, characterized in that, When adding an affinity group, the affinity rule conflict detection between the newly added affinity group and the existing affinity group includes the following steps: Step 301: Sort according to positive affinity group ID; Step 302: Obtain the uniform affinity group k i ; Step 303: Apply the uniform affinity group k i Perform a traversal, with variable i, to calculate the uniform affinity group k. i If the intersection of the virtual machine list with the reverse affinity group has more than 1 element, an affinity rule conflict is detected.

Citation Information

Patent Citations

  • Virtual machine load balancing method and computer readable storage medium

    CN107885579A

  • A method and apparatus for monitoring conflict of affinity rules based on load balancing

    CN109189556A

  • Automatic creation of affinity-type rules for resources in distributed computer systems

    US20160182403A1