Detailed Description
When a physical device is virtualized, various resources in the physical device need to be allocated to the created virtual device. In the prior art, two resource allocation methods are generally used: fixed allocation and on-demand allocation. However, both allocation methods cannot dynamically adjust the resource allocation amount of each virtual device.
In view of this, an embodiment of the present invention describes a method for allocating device resources in a virtualized scenario, where the method may include the following steps:
a device resource allocation method under a virtualization scene is applied to a virtual device management apparatus, the virtual device management apparatus is configured on a physical device, and the virtual device management apparatus creates a plurality of virtual devices in the physical device, the method includes:
receiving a resource application sent by a target virtual device, wherein the resource application carries the quantity of resource requirements;
judging whether the resource demand quantity is larger than the idle resource quantity of the physical equipment or not;
if the resource demand quantity is not greater than the idle resource quantity of the physical equipment, allocating the idle resources in the physical equipment to target virtual equipment;
and if the resource demand quantity is greater than the idle resource quantity of the physical equipment, controlling other virtual equipment to release resources to the physical equipment, and allocating the idle resources in the physical equipment to the target virtual equipment according to the release result.
Before resource allocation, the following data needs to be configured in advance:
the maximum number of virtual devices supported by the physical device is configured in advance, and is recorded as COUNTvs, and the number of virtual devices actually created by the device cannot be greater than the value.
And respectively appointing a standard resource value for each virtual device, recording the standard resource value of the virtual device x as EXPx, and enabling the sum of the standard resource values appointed for all the virtual devices to be not more than the total value of the type of resources in the physical device.
In the process of resource allocation, various resource usage conditions need to be recorded, and the recorded data includes, but is not limited to, the following:
the idle resource value: in the physical equipment, only one resource of each type of the idle resource value is used as the global idle resource of the equipment, when the virtual equipment applies for the resource, the idle resource value is reduced, and when the virtual equipment releases the resource, the idle resource value is increased;
system resource value: the system resource value is increased when the virtual equipment applies for the resource, and the system resource value is decreased when the virtual equipment releases the resource;
peak value of system resources: the system resource values are multiple in the physical equipment, one in each virtual equipment and used for recording the highest value of the resource usage amount of the virtual equipment, when the virtual equipment applies for resources, the system resource values are compared with the system resource peak values, and if the system resource values are larger than the system resource peak values, the system resource peak values are modified to be the latest system resource values;
mean system resource value: the system resource values are multiple in the physical device, one in each virtual device, the system resource values are obtained through periodic sampling, and average value calculation is carried out through a preset algorithm and used for roughly estimating the average resource use value of the virtual devices.
In order to make those skilled in the art better understand the technical solution of the present invention, the technical solution in the embodiments of the present invention will be described in detail below with reference to the drawings in the embodiments of the present invention.
Before resource allocation begins, several virtual devices have been created in a physical device, please refer to fig. 3, which is a flowchart of creating virtual devices in a virtualization scenario according to an embodiment of the present invention, and the flowchart may include the following basic steps:
s301, initiating a virtual device creation request, and configuring a standard resource value for a device to be created;
s302, judging whether the number of the existing virtual devices is not less than a preset maximum value or not;
if the number of the existing virtual devices is less than the preconfigured maximum number of COUNTvs, executing step S303; and if the number of the existing virtual devices is not less than the preconfigured maximum number COUNTvs, ending the creating flow of the virtual devices.
S303, judging whether the sum of the standard resource values of all the virtual devices is larger than the total value of the physical devices;
the sum of the standard resource values also includes a standard resource value configured for the virtual device to be created currently, and if the sum of the standard resource values configured for all the virtual devices is not greater than the total value of the type of resource in the physical device, step S304 is executed; if the sum of the standard resource values configured by all the virtual devices is greater than the total value of the resources in the physical device, step S305 is executed.
S304, creating a virtual device.
S305, outputting the current resource use condition;
when the new virtual device cannot be created due to insufficient configurable standard resource values, the resource usage conditions of the physical device and each virtual device need to be output for the user to refer and adjust.
The types of data that can be output include, but are not limited to: the maximum resource quantity of the physical equipment, the standard resource value configured by each virtual equipment, the maximum value of the resource quantity used by each virtual equipment, and the average value of the resource quantity used by each virtual equipment.
After completion of step S304 or step S305, the virtual device creation flow is ended.
Referring to fig. 4, a flowchart of a device resource allocation method in a virtualized scenario according to an embodiment of the present invention is shown, which includes the following basic steps:
s401, receiving a resource application sent by a target virtual device;
receiving a resource application sent by target virtual equipment, wherein the resource application carries the quantity of resources which the target virtual equipment wants to apply;
s402, judging whether the quantity of the resource demand is larger than the quantity of the idle resources;
the free resources are the resources remaining in the physical device that can be used to allocate to the virtual device. It should be noted that there are many kinds of resources that can be allocated to the virtual device by the physical device, and for example, the session table, the routing table, the ARP table, and the like are allocable resources. Here, the idle resource refers to the same type of resource as the virtual device resource application.
After receiving the resource application, checking whether the resource demand quantity is greater than the idle resource quantity, that is, checking whether the idle resource in the physical device can meet the demand quantity of the resource application.
If the resource demand quantity is not greater than the idle resource quantity, executing step S403;
if the resource demand amount is greater than the free resource amount, step S404 is executed.
And S403, allocating the free resources in the physical device to the target virtual device.
S404, controlling other virtual devices to release resources to the physical device, and allocating idle resources in the physical device to the target virtual device according to a release result;
if the resource demand quantity is greater than the idle resource quantity, it is indicated that the idle resources in the physical device cannot meet the resource demand of the target virtual device, and at this time, the resource allocation proportion in each virtual device needs to be dynamically adjusted.
In the actual application process, before triggering the resource release, a condition check is usually required, for example:
a) and checking the target virtual equipment, if the number of the resources currently used by the target virtual equipment does not reach the threshold value, controlling the number of the resources of other virtual equipment to release the resources to the physical equipment, and then allocating the resources to the target virtual equipment by the physical equipment.
b) And checking other virtual devices, if the number of resources currently used by some virtual devices exceeds a threshold value, controlling the virtual devices to release the resources to the physical device, and allocating the resources to the target virtual device by the physical device.
c) And checking the target virtual equipment and other virtual equipment, and if the number of resources currently used by the target virtual equipment does not reach a threshold value and the number of resources currently used by some virtual equipment exceeds the threshold value, controlling the virtual equipment to release resources to the physical equipment, and then allocating the resources to the target virtual equipment by the physical equipment.
Further, the resource allocation may also adopt various schemes, such as:
a) the method comprises the steps of firstly allocating the idle resources in the physical equipment to the target virtual equipment to meet a part of resource requirements of the target virtual equipment, then carrying out condition check, and if the resource can be released, releasing the resources from other virtual equipment to the physical equipment to make the idle resources in the physical equipment capable of complementing the rest part of resource requirements.
b) And firstly, carrying out condition check, if the resource can be released, releasing the resources from other virtual equipment to the physical equipment to enable the number of the idle resources in the physical equipment to be larger than the number of the resources of the target virtual equipment, and then allocating enough idle resources to the virtual equipment.
Referring to fig. 5, another flowchart of a device resource allocation method in a virtualized scenario according to an embodiment of the present invention is shown, where the method includes the following basic steps:
s501, receiving the resource application sent by the target virtual device, which is the same as described in S401.
S502, judging whether the resource demand quantity is larger than the idle resource quantity, and the same as the S402. (ii) a
If the resource demand quantity is greater than the idle resource quantity, executing step S503;
if the resource demand amount is not greater than the free resource amount, step S504 is performed.
S503, sending the resource shortage alarm log, and then executingstep 505;
generally, an out-of-resource alarm log is generated when:
a) the maximum resource capacity of the physical device has not met the current application environment;
b) resource type attacks occur, resulting in excessive resource consumption.
S504, allocating the free resources in the physical device to the target virtual device, and then executingstep 508;
s505, judging whether the current resource usage amount of the target equipment is smaller than a standard resource value;
the standard resource value may be understood as the amount of resources that a virtual device may unconditionally obtain.
When the virtual device applies for resources, the resource value currently used by the virtual device does not reach the standard resource value, and then the resource application of the virtual device can be met no matter the idle resource value in the physical device is insufficient, that is, other virtual devices are controlled to release resources to the physical device, and the physical device allocates the resources to the virtual device. There may be two further processing modes: a) under the condition that the resource demand of the application is not sufficiently distributed, the currently used resource value of the virtual equipment reaches the standard resource value, and at the moment, the control of the resource quantity of other virtual equipment is stopped to release resources to the physical equipment; b) whether the resource value currently used by the virtual equipment reaches the standard resource value or not, the resource demand of the application is met, and then the control of the resource quantity of other virtual equipment is stopped to release the resources to the physical equipment.
When the virtual device applies for resources, the resource value currently used by the virtual device has already reached the standard resource value, and then the resource application of the virtual device is satisfied only when the idle resource value in the physical device is sufficient.
If the current resource usage amount of the target device is smaller than its standard resource value, go to step S506;
if the current resource usage amount of the target device is not less than its standard resource value, step S508 is performed.
S506, selecting the virtual equipment with the largest ratio of the number of the currently used resources to the standard resource value from other virtual equipment;
and S507, controlling the selected virtual equipment to release resources to the physical equipment, and distributing idle resources in the physical equipment to the target virtual equipment according to a release result, which is the same as the S404.
And S508, finishing distribution.
It can be understood that, when creating virtual devices, the number of virtual devices created in this embodiment is not higher than the maximum value configured in advance, and when creating virtual devices, a standard resource value is respectively specified for each virtual device, and the sum of the standard resource values specified for all virtual devices is not greater than the total value of the resource types corresponding to the standard resource value in the physical device.
Referring to fig. 6, a device resource allocation apparatus in a virtualized scenario according to an embodiment of the present invention is shown. The method comprises the following steps: aresource application module 601, aresource judgment module 602, aresource allocation module 603, and aresource preemption module 604.
Aresource application module 601, configured to receive a resource application sent by a target virtual device, where the resource application carries a resource demand amount;
aresource determining module 602, configured to determine whether the required amount of resources is greater than an idle amount of resources of the physical device;
aresource allocation module 603, configured to allocate, when the resource demand amount is not greater than the idle resource amount of the physical device, an idle resource in the physical device to a target virtual device;
theresource preemption module 604 is configured to, when the resource demand amount is greater than the idle resource amount of the physical device, control other virtual devices to release resources to the physical device, and allocate idle resources in the physical device to a target virtual device according to a release result.
In this embodiment, theresource preemption module 604 is specifically configured to:
when the resource demand quantity is larger than the idle resource quantity of the physical equipment, judging whether the current resource quantity used by the target virtual equipment is smaller than a standard resource value;
and if the number of the resources currently used by the target virtual equipment is less than the standard resource value, controlling other virtual equipment to release the resources to the physical equipment.
In this embodiment, theresource preemption module 604 is further specifically configured to:
and when the resource demand quantity is larger than the idle resource quantity of the physical equipment, selecting the virtual equipment meeting the standard according to a preset algorithm, and releasing the resources from the selected virtual equipment to the physical equipment.
In this embodiment, theresource preemption module 604 is further specifically configured to:
when the resource demand quantity is larger than the idle resource quantity of the physical equipment, calculating the ratio of the resource quantity currently used by other virtual equipment to the standard resource value of the equipment, selecting the virtual equipment with the maximum ratio, and releasing resources from the selected virtual equipment to the physical equipment;
when the virtual equipment management device creates the virtual equipment, the virtual equipment management device respectively appoints a standard resource value for each virtual equipment, and the sum of the standard resource values appointed for all the virtual equipment is not more than the total value of the type of resources in the physical equipment.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the apparatus embodiment, since it is substantially similar to the method embodiment, it is relatively simple to describe, and reference may be made to some descriptions of the method embodiment for relevant points. The above-described embodiments of the apparatus are merely illustrative, wherein the modules described as separate parts may or may not be physically separate, and the parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.