Method and device for allocating virtual machine resources by host machine, equipment and medium
By automatically judging and managing the resource capacity and migration conditions of the host, the problems of low virtual machine migration efficiency and low resource utilization when the host is down in the cloud platform are solved, and efficient resource utilization and cost reduction are achieved.
Patent Information
- Application Number
- CN202411473711.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-22
- Publication Date
- 2024-12-31
AI Technical Summary
In a cloud platform environment, all virtual machines need to be migrated when the host machine goes down, resulting in low inspection efficiency and more than 20% of CPU resources need to be reserved, resulting in low resource utilization and high cost.
By obtaining the number of allocated and remaining logical cores corresponding to the physical core of each host, the resource capacity and migration conditions are automatically judged, ensuring that the virtual machine can be migrated smoothly when it is down, and avoiding the reservation of a large number of CPU resources.
It improves the stability of the cloud platform environment and resource utilization efficiency, reduces costs, and ensures the normal operation of the business.
Smart Images

Figure CN119225908A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of host machine resource allocation, and in particular to a method, device, equipment and medium for allocating resources from a host machine to a virtual machine. Background Art
[0002] At present, most host machines in cloud platform environments usually adopt NUMA architecture, that is, each host machine includes two physical cores, each physical core can be allocated a certain number of logical cores; a virtual machine can only run on one host machine at a time, and the CPU resources allocated to the virtual machines on the same host machine must be within the allowed range of the host machine; when a host machine in the cloud platform goes down, all virtual machines on the host machine must be migrated to other host machines to ensure that business operations are not affected; therefore, it is necessary to check every day whether any host machine goes down to ensure that all virtual machines on it can migrate normally, and the inspection efficiency is low; in addition, when a host machine goes down, in order to ensure that the virtual machines on the downed host machine can be smoothly allocated to other host machines, more than 20% of the CPU resources will be reserved on each host machine, resulting in low CPU resource utilization on the host machine and high cost of the CPU resource solution. Summary of the invention
[0003] In view of the above technical problems, the technical solution adopted by the present invention is: According to a first aspect of the present application, a method for allocating resources from a host machine to a virtual machine is provided, the method comprising the following steps: S100, obtaining the number of allocated logical cores and the number of remaining logical cores corresponding to each physical core on each host machine, so as to obtain a logical core array list S=(S1, S2, ..., S i , …, S n ), i=1, 2, …, n; where S i is the logical core array corresponding to the i-th host, n is the number of hosts; S i =(S i _b1,S i _b2,S i _c1, S i _c2); S i _b1 and S i _b2 are the number of allocated logical cores corresponding to the first physical core and the number of allocated logical cores corresponding to the second physical core on the i-th host; S i _c1 and S i _c2 is the number of remaining logical cores corresponding to the first physical core and the number of remaining logical cores corresponding to the second physical core on the i-th host; S200, obtaining a first preset value Q=1; S300, judge SQ _b1+S Q _ Is b2 less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2); S400, if S Q _b1+S Q _b2 is less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2), it is determined that the Qth host machine meets the preset resource capacity judgment condition, and the process proceeds to S500; otherwise, it is determined that the Qth host machine does not meet the preset resource capacity judgment condition; S500, if Q<n, obtain Q=Q+1 and enter S300; otherwise, enter S600; S600, if each host machine meets the preset resource capacity judgment condition, then enter S700; S700, if any host machine crashes and each virtual machine on the crashed host machine meets the preset migration conditions, it is determined that the current resource allocation of each host machine is reasonable; otherwise, the current resource allocation of each host machine is adjusted.
[0004] Furthermore, step S700 includes the following steps: S710, obtaining the number of logical cores occupied by each virtual machine running on the target host, so as to obtain a list of the number of logical cores occupied by the virtual machines corresponding to the target host B = (B1, B2, ..., B j , …, B m ), j = 1, 2, …, m; where B j is the number of logical cores occupied by the jth virtual machine running on the target virtual machine, and m is the number of virtual machines running on the target host; B r ≥B r+1 ; r = 1, 2, ..., m-1; the target host is any host; S720, obtaining the number of remaining logical cores corresponding to each host except the target host, to obtain a list of remaining logical cores D = (D1, D2, ..., D e , …, D n-1 ), e=1, 2, ..., n-1; where D e is the number of remaining logical cores corresponding to the e-th host except the target host; S730: Determine, based on B and D, whether each virtual machine on the target host machine satisfies a preset migration condition.
[0005] Further, step S730 includes the following steps: S731, obtaining a second preset value K=1 and an intermediate logical core number list T; S732, obtain T=D; S733, traverse T, find the items in T that are greater than or equal to B K The remaining logical core number of is determined as the intermediate remaining logical core number, so as to obtain the Kth intermediate remaining logical core number list L K =(L K,1 , L K,2 , …, L K,g , …, L K,f(K) ), g = 1, 2, …, f (K); where L K,g For B K The corresponding g-th intermediate remaining logical core number, f(K) is B K The corresponding number of remaining logical cores in the middle; S734, if f(K)=0, it is determined that each virtual machine on the target host machine does not meet the preset migration condition, and the current process is exited; otherwise, the process proceeds to S735; S735, according to L K , determine B K The corresponding target number of remaining logical cores H K =MIN(L K ); where MIN() is the preset minimum value function; S736, replace the H in T K Updated to H K +B1 to get B K Corresponding update remaining logical core count list GB K , and obtain T=GB K ; Enter S737; S737, if K<m, obtain K=K+1; enter S733; otherwise, determine whether each virtual machine on the target host machine meets the preset migration condition.
[0006] According to another aspect of the present application, there is also provided a device for allocating resources from a host machine to a virtual machine, characterized in that the device comprises: The logical core number acquisition module is used to obtain the number of allocated logical cores and the number of remaining logical cores corresponding to each physical core on each host machine, so as to obtain a logical core array list S = (S1, S2, ..., S i , …, S n ), i=1, 2, …, n; where S iis the logical core array corresponding to the i-th host, n is the number of hosts; S i =(S i _b1,S i _b2,S i _c1, S i _c2); S i _b1 and S i _b2 are the number of allocated logical cores corresponding to the first physical core and the number of allocated logical cores corresponding to the second physical core on the i-th host; S i _c1 and S i _c2 is the number of remaining logical cores corresponding to the first physical core and the number of remaining logical cores corresponding to the second physical core on the i-th host; A first preset value acquisition module, used to acquire a first preset value Q=1; The first judgment module is used to judge S Q _b1+S Q _ Is b2 less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2); The second judgment module is used to determine if S Q _b1+S Q _b2 is less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2), it is determined that the Qth host machine meets the preset resource capacity judgment condition; otherwise, it is determined that the Qth host machine meets the preset resource capacity judgment condition; The third judgment module is used to obtain Q=Q+1 if Q<n; The fourth determination module is used to determine whether each host machine meets the preset resource capacity determination condition; The migration condition judgment module is used to determine whether the resource allocation of each current host machine is reasonable if each virtual machine on the host machine that has crashed satisfies the preset migration conditions when any host machine crashes; otherwise, the resource allocation of each current host machine is adjusted.
[0007] According to another aspect of the present application, a non-transitory computer-readable storage medium is also provided, in which at least one instruction or at least one program is stored, and the at least one instruction or at least one program is loaded and executed by a processor to implement the above-mentioned host machine to virtual machine resource allocation method.
[0008] According to another aspect of the present application, an electronic device is provided, including a processor and the above-mentioned non-transitory computer-readable storage medium.
[0009] The present invention has at least the following beneficial effects: The host machine to virtual machine resource allocation method of the present invention obtains the number of allocated logical cores and the number of remaining logical cores corresponding to each physical core on each host machine to obtain a logical core array list; each host machine is automatically checked according to the logical core array list to ensure that when any host machine is down and unavailable, there are sufficient resources to migrate the virtual machine resources on it, thereby improving the stability of the cloud platform environment and ensuring the normal operation of the business; at the same time, the present invention does not need to manually reserve a large amount of CPU resources, thereby improving resource utilization efficiency and reducing costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0011] Figure 1 A flowchart of a method for allocating resources from a host machine to a virtual machine provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0012] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0013] It should be noted that, based on the present disclosure, those skilled in the art should understand that an aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects described herein can be used to implement a device and / or practice a method. In addition, other structures and / or functionalities other than one or more of the aspects described herein can be used to implement this device and / or practice this method.
[0014] The following will refer to Figure 1 The flowchart of the method for allocating resources from a host machine to a virtual machine is shown, and a method for allocating resources from a host machine to a virtual machine is introduced.
[0015] The method for allocating resources from a host machine to a virtual machine may include the following steps: S100, obtaining the number of allocated logical cores and the number of remaining logical cores corresponding to each physical core on each host machine, so as to obtain a logical core array list S=(S1, S2, ..., S i , …, S n ), i=1, 2, …, n; where S i is the logical core array corresponding to the i-th host, n is the number of hosts; S i =(S i _b1,S i _b2,S i _c1, S i _c2); S i _b1 and S i _b2 are the number of allocated logical cores corresponding to the first physical core and the number of allocated logical cores corresponding to the second physical core on the i-th host; S i _c1 and S i _c2 is the number of remaining logical cores corresponding to the first physical core and the number of remaining logical cores corresponding to the second physical core on the i-th host.
[0016] In this embodiment, it should be noted that the host machine in the cloud platform environment adopts a NUMA architecture, each host machine has 2 physical cores, and each physical core can be allocated to respond to a certain number of logical cores; a virtual machine can only run on one of the host machines at the same time, and the CPU resources allocated to the virtual machines on the same host machine, that is, the number of logical cores must be within the allowed range of the host machine; when a host machine in the cloud platform crashes, all virtual machines on the host machine must be migrated to other host machines to avoid affecting business operations.
[0017] According to the operating parameters of each host machine, the number of allocated logical cores corresponding to each host machine can be obtained, that is, the number of logical cores used by the virtual machine; the total number of logical cores of each host machine is known. When the number of allocated logical cores is obtained, the total number of logical cores is subtracted from the number of allocated logical cores to obtain the remaining number of logical cores.
[0018] S200, obtaining a first preset value Q=1.
[0019] S300, judge S Q _b1+S Q _ Is b2 less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2).
[0020] In this embodiment, if the Qth host machine crashes, then to ensure that the virtual machines on the Qth host machine can be allocated to other hosts when the Qth host machine crashes, the first condition is that S Q _b1+S Q _b2 is less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2); if S Q _b1+S Q _b2 is greater than ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2), when the Qth host machine goes down, the virtual machines on it cannot be allocated to other hosts, and there is no need to make further judgments. It can be directly determined that the current resource allocation plan is unreasonable.
[0021] S400, if S Q _b1+S Q _b2 is less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2), it is determined that the Qth host machine meets the preset resource capacity judgment condition, and the process proceeds to S500; otherwise, it is determined that the Qth host machine does not meet the preset resource capacity judgment condition.
[0022] S500, if Q<n, obtain Q=Q+1 and enter S300; otherwise, enter S600.
[0023] S600: If each host machine meets the preset resource capacity judgment condition, enter S700.
[0024] In this embodiment, through the above-mentioned loop steps, it is possible to determine whether each virtual machine running on any downtime host can be allocated to other hosts. If any host does not meet the preset resource capacity judgment condition, it is determined that there is a risk in the resource capacity configuration of the cloud platform, and the system will remind the administrator to expand the host resource capacity.
[0025] S700, if any host machine crashes and each virtual machine on the crashed host machine meets the preset migration conditions, it is determined that the current resource allocation of each host machine is reasonable; otherwise, the current resource allocation of each host machine is adjusted.
[0026] In this embodiment, after determining whether there is a risk in the resource capacity configuration of the host machine, it is necessary to further determine whether the CPU resource allocation on each host machine is reasonable. Specifically, step S700 may include the following steps: S710, obtaining the number of logical cores occupied by each virtual machine running on the target host, so as to obtain a list of the number of logical cores occupied by the virtual machines corresponding to the target host B = (B1, B2, ..., B j , …, B m ), j = 1, 2, …, m; where B j is the number of logical cores occupied by the jth virtual machine running on the target virtual machine, and m is the number of virtual machines running on the target host; B r ≥B r+1 ; r=1, 2, …, m-1; the target host is any host.
[0027] In this embodiment, the number of virtual machines running on the target host machine and the number of logical cores of the target host machine occupied by each virtual machine can be obtained.
[0028] S720, obtaining the number of remaining logical cores corresponding to each host except the target host, to obtain a list of remaining logical cores D = (D1, D2, ..., D e , …, D n-1 ), e=1, 2, ..., n-1; where D e is the number of remaining logical cores corresponding to the e-th host except the target host.
[0029] In this embodiment, the remaining number of logical cores of other host machines except the target host machine can also be obtained, thereby obtaining D.
[0030] S730: Determine, based on B and D, whether each virtual machine on the target host machine satisfies a preset migration condition.
[0031] Further, step S730 includes the following steps: S731, obtain a second preset value K=1 and an intermediate logic core number list T.
[0032] S732, obtain T=D.
[0033] S733, traverse T, find the items in T that are greater than or equal to B K The remaining logical core number of is determined as the intermediate remaining logical core number, so as to obtain the Kth intermediate remaining logical core number list LK =(L K,1 , L K,2 , …, L K,g , …, L K,f(K) ), g = 1, 2, …, f (K); where L K,g For B K The corresponding g-th intermediate remaining logical core number, f(K) is B K The corresponding number of remaining logical cores in the middle; S734, if f(K)=0, it is determined that each virtual machine on the target host machine does not meet the preset migration condition, and the current process is exited; otherwise, enter S735.
[0034] S735, according to L K , determine B K The corresponding target number of remaining logical cores H K =MIN(L K ); where MIN() is the preset minimum value function.
[0035] S736, replace the H in T K Updated to H K +B1 to get B K Corresponding update remaining logical core count list GB K , and obtain T=GB K ; Enter S737.
[0036] S737, if K<m, obtain K=K+1; enter S733; otherwise, determine whether each virtual machine on the target host machine meets the preset migration condition.
[0037] In this embodiment, if a host machine crashes, the above steps can be used to determine whether all virtual machines on the crashed host machine can be migrated to other host machines; the virtual machine with the largest number of logical cores is preferentially migrated to the host machine that can meet the migration requirements and has the smallest remaining logical cores, that is, the virtual machine with the largest number of logical cores is found from all the virtual machines on the crashed host machine, and it is migrated to other remaining host machines that can meet its resource allocation requirements at the smallest level, and the next virtual machine with the largest required number of logical cores is found in turn for migration until all migrations are completed.
[0038] In the above steps, if any virtual machine cannot be migrated to another host machine, it is determined that the current resource allocation scheme is unreasonable, and the resource capacity of the corresponding host machine can be expanded according to the number of logical cores required by the virtual machine that cannot be migrated.
[0039] The host machine of this embodiment allocates resources to virtual machines by obtaining the number of allocated logical cores and the number of remaining logical cores corresponding to each physical core on each host machine to obtain a logical core array list; each host machine is automatically checked according to the logical core array list to ensure that when any host machine is down and unavailable, there are sufficient resources to migrate the virtual machine resources on it, thereby improving the stability of the cloud platform environment and ensuring the normal operation of the business; at the same time, the present invention does not need to manually reserve a large amount of CPU resources, thereby improving resource utilization efficiency and reducing costs.
[0040] In an exemplary embodiment, a device for allocating resources from a host machine to a virtual machine is provided, the device comprising: The logical core number acquisition module is used to obtain the number of allocated logical cores and the number of remaining logical cores corresponding to each physical core on each host machine, so as to obtain a logical core array list S = (S1, S2, ..., S i , …, S n ), i=1, 2, …, n; where S i is the logical core array corresponding to the i-th host, n is the number of hosts; S i =(S i _b1,S i _b2,S i _c1, S i _c2); S i _b1 and S i _b2 are the number of allocated logical cores corresponding to the first physical core and the number of allocated logical cores corresponding to the second physical core on the i-th host; S i _c1 and S i _c2 is the number of remaining logical cores corresponding to the first physical core and the number of remaining logical cores corresponding to the second physical core on the i-th host.
[0041] The first preset value acquisition module is used to obtain a first preset value Q=1.
[0042] The first judgment module is used to judge S Q _b1+S Q _ Is b2 less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2).
[0043] The second judgment module is used to determine if S Q _b1+S Q _b2 is less than or equal to ∑ n i=1 (S i _c1+Si _c2)-(S i _c1+S i _c2), it is determined that the Qth host machine meets the preset resource capacity judgment condition; otherwise, it is determined that the Qth host machine meets the preset resource capacity judgment condition.
[0044] The third judgment module is used to obtain Q=Q+1 if Q<n.
[0045] The fourth determination module is used to determine whether each host machine meets a preset resource capacity determination condition.
[0046] The migration condition judgment module is used to determine whether the resource allocation of each current host machine is reasonable if each virtual machine on the host machine that has crashed satisfies the preset migration conditions when any host machine crashes; otherwise, the resource allocation of each current host machine is adjusted.
[0047] In addition, although the steps of the method in the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all the steps shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps, etc.
[0048] An embodiment of the present invention also provides a non-transitory computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to implementing a method in a method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the method provided in the above embodiment.
[0049] The program product may adopt any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0050] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0051] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0052] Program code for performing the operations of the present application may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).
[0053] An embodiment of the present invention further provides an electronic device, comprising a processor and the aforementioned non-transitory computer-readable storage medium.
[0054] The electronic device is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0055] The electronic device is presented in the form of a general-purpose computing device. The components of the electronic device may include, but are not limited to: the at least one processor mentioned above, the at least one memory mentioned above, and a bus connecting different system components (including the memory and the processor).
[0056] The memory stores program codes, which can be executed by the processor, so that the processor executes the steps in various embodiments described in this specification.
[0057] The memory may include readable media in the form of volatile memory, such as random access memory (RAM) and / or cache memory, and may further include read only memory (ROM).
[0058] The memory may also include a program / utility having a set (at least one) of program modules, such program modules including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include an implementation of a network environment.
[0059] The bus may represent one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures.
[0060] The electronic device may also communicate with one or more external devices (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may communicate with one or more devices that enable a user to interact with the electronic device, and / or may communicate with any device (e.g., routers, modems, etc.) that enables the electronic device to communicate with one or more other computing devices. Such communication may be performed through an input / output (I / O) interface. Furthermore, the electronic device may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) through a network adapter. The network adapter communicates with other modules of the electronic device through a bus. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0061] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0062] An embodiment of the present invention further provides a computer program product, which includes program code. When the program product is run on an electronic device, the program code is used to enable the electronic device to execute the steps of the method according to various exemplary embodiments of the present invention described above in this specification.
[0063] Although some specific embodiments of the present invention have been described in detail by way of example, it should be understood by those skilled in the art that the above examples are only for illustration, not for limiting the scope of the present invention. It should also be understood by those skilled in the art that various modifications may be made to the embodiments without departing from the scope and spirit of the present invention.
Claims
1. A method for allocating resources from a host machine to a virtual machine, characterized in that: The method comprises the following steps: S100, obtaining the number of allocated logical cores and the number of remaining logical cores corresponding to each physical core on each host machine, so as to obtain a logical core array list S=(S1, S2, ..., S i , …, S n ), i=1, 2, …, n; where S i is the logical core array corresponding to the i-th host, n is the number of hosts; S i =(S i _b1,S i _b2,S i _c1, S i _c2); S i _b1 and S i _b2 are the number of allocated logical cores corresponding to the first physical core and the number of allocated logical cores corresponding to the second physical core on the i-th host; S i _c1 and S i _c2 is the number of remaining logical cores corresponding to the first physical core and the number of remaining logical cores corresponding to the second physical core on the i-th host; S200, obtaining a first preset value Q=1; S300, judge S Q _b1+S Q _ Is b2 less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2); S400, if S Q _b1+S Q _b2 is less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2), it is determined that the Qth host machine meets the preset resource capacity judgment condition, and the process proceeds to S500; otherwise, it is determined that the Qth host machine does not meet the preset resource capacity judgment condition; S500, if Q<n, obtain Q=Q+1 and enter S300; otherwise, enter S600; S600, if each host machine meets the preset resource capacity judgment condition, then enter S700; S700, if any host machine crashes and each virtual machine on the crashed host machine meets the preset migration conditions, it is determined that the current resource allocation of each host machine is reasonable; otherwise, the current resource allocation of each host machine is adjusted.
2. The method for allocating resources from a host machine to a virtual machine according to claim 1, characterized in that: Step S700 includes the following steps: S710, obtaining the number of logical cores occupied by each virtual machine running on the target host, so as to obtain a list of the number of logical cores occupied by the virtual machines corresponding to the target host B = (B1, B2, ..., B j , …, B m ), j = 1, 2, …, m; where B j is the number of logical cores occupied by the jth virtual machine running on the target virtual machine, and m is the number of virtual machines running on the target host; B r ≥B r+1 ; r = 1, 2, ..., m-1; the target host is any host; S720, obtaining the number of remaining logical cores corresponding to each host except the target host, to obtain a list of remaining logical cores D = (D1, D2, ..., D e , …, D n-1 ), e=1, 2, ..., n-1; where D e is the number of remaining logical cores corresponding to the e-th host except the target host; S730: Determine, based on B and D, whether each virtual machine on the target host machine satisfies a preset migration condition.
3. The method for allocating resources from a host machine to a virtual machine according to claim 2, characterized in that: Step S730 includes the following steps: S731, obtaining a second preset value K=1 and an intermediate logical core number list T; S732, obtain T=D; S733, traverse T, find the items in T that are greater than or equal to B K The remaining logical core number of is determined as the intermediate remaining logical core number, so as to obtain the Kth intermediate remaining logical core number list L K =(L K,1 , L K,2 , …, L K,g , …, L K,f(K) ), g = 1, 2, …, f (K); where L K,g For B K The corresponding g-th intermediate remaining logical core number, f(K) is B K The corresponding number of remaining logical cores in the middle; S734, if f(K)=0, it is determined that each virtual machine on the target host machine does not meet the preset migration condition, and the current process is exited; otherwise, the process proceeds to S735; S735, according to L K , determine B K The corresponding target number of remaining logical cores H K =MIN(L K ); where MIN() is the preset minimum value function; S736, replace the H in T K Updated to H K +B1 to get B K Corresponding update remaining logical core count list GB K , and obtain T=GB K ; Enter S737; S737, if K<m, obtain K=K+1; enter S733; otherwise, determine whether each virtual machine on the target host machine meets the preset migration condition.
4. A device for allocating resources from a host machine to a virtual machine, characterized in that: The device comprises: The logical core number acquisition module is used to obtain the number of allocated logical cores and the number of remaining logical cores corresponding to each physical core on each host machine, so as to obtain a logical core array list S = (S1, S2, ..., S i , …, S n ), i=1, 2, …, n; where S i is the logical core array corresponding to the i-th host, n is the number of hosts; S i =(S i _b1,S i _b2,S i _c1, S i _c2); S i _b1 and S i _b2 are the number of allocated logical cores corresponding to the first physical core and the number of allocated logical cores corresponding to the second physical core on the i-th host; S i _c1 and S i _c2 is the number of remaining logical cores corresponding to the first physical core and the number of remaining logical cores corresponding to the second physical core on the i-th host; A first preset value acquisition module, used to acquire a first preset value Q=1; The first judgment module is used to judge S Q _b1+S Q _ Is b2 less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2); The second judgment module is used if S Q _b1+S Q _b2 is less than or equal to ∑ n i=1 (S i _c1+S i _c2)-(S i _c1+S i _c2), it is determined that the Qth host machine meets the preset resource capacity judgment condition; otherwise, it is determined that the Qth host machine meets the preset resource capacity judgment condition; The third judgment module is used to obtain Q=Q+1 if Q<n; The fourth determination module is used to determine whether each host machine meets the preset resource capacity determination condition; The migration condition judgment module is used to determine whether the resource allocation of each current host machine is reasonable if each virtual machine on the host machine that has crashed satisfies the preset migration conditions when any host machine crashes; otherwise, the resource allocation of each current host machine is adjusted.
5. A non-transitory computer-readable storage medium, wherein at least one instruction or at least one program is stored in the storage medium, characterized in that: The at least one instruction or the at least one program is loaded and executed by the processor to implement the method for allocating resources from a host machine to a virtual machine as described in any one of claims 1 to 4.
6. An electronic device, characterized in that: Includes a processor and the non-transitory computer-readable storage medium of claim 5.
Citation Information
Cited By
Processor scheduling method and device, electronic equipment and storage medium
CN120508363A