Disclosure of Invention
The invention aims to provide a method for adjusting the CPU core number of a virtual machine, which is used for dynamically optimizing the processing performance of the virtual machine with multiple core numbers, does not need to increase the cost, does not need to be manually changed, and has higher adjustment efficiency. In addition, the invention also provides a device, equipment and medium for adjusting the CPU core number of the virtual machine corresponding to the method.
In order to solve the above technical problems, the present invention provides a method for adjusting the CPU core number of a virtual machine, including:
acquiring reference data for representing the resource consumption of a CPU of a physical machine;
judging whether the reference data meets the preset core number adjusting condition or not;
and if so, controlling the target virtual machine to adjust the CPU core number according to the adjustment mode corresponding to the type of the reference data.
Preferably, the acquiring the reference data for characterizing the resource consumption of the CPU of the physical machine includes:
acquiring the scheduling delay of each virtual machine;
the judging whether the reference data meets the preset core number adjusting condition comprises the following steps:
Judging whether the scheduling delay is larger than a preset upper threshold limit and/or smaller than a preset lower threshold limit;
if yes, determining that the reference data meets the core number adjustment condition;
the controlling the target virtual machine to adjust the CPU core number according to the adjustment mode corresponding to the type of the reference data comprises the following steps:
the number of CPU cores of the virtual machine controlling the scheduling delay to be larger than the upper threshold limit is reduced and/or the number of CPU cores of the virtual machine controlling the scheduling delay to be smaller than the lower threshold limit is increased.
Preferably, before the step of obtaining the scheduling delay of each virtual machine, the method further comprises:
acquiring the load rate of a CPU of the physical machine;
judging whether the load rate is higher than a preset load rate set value or not;
if yes, the step of obtaining the scheduling delay of each virtual machine is entered.
Preferably, the acquiring the reference data for characterizing the resource consumption of the CPU of the physical machine includes:
acquiring the scheduling delay of each virtual machine;
the judging whether the reference data meets the preset core number adjusting condition comprises the following steps:
judging whether the scheduling delay is larger than a preset upper threshold limit and/or smaller than a preset lower threshold limit;
If yes, determining that the reference data meets the core number adjustment condition;
the controlling the target virtual machine to adjust the CPU core number according to the adjustment mode corresponding to the type of the reference data comprises the following steps:
the priority of each virtual machine is obtained and compared with a preset priority set value;
the number of CPU cores of the virtual machines which control the scheduling delay to be larger than the upper threshold limit and the priority to be lower than the priority set value is reduced, and/or the number of CPU cores of the virtual machines which control the scheduling delay to be smaller than the lower threshold limit and the priority to be higher than the priority set value is increased.
Preferably, the obtaining the scheduling delay of each virtual machine includes:
and obtaining the average scheduling delay of each virtual machine.
Preferably, the acquiring the reference data for characterizing the resource consumption of the CPU of the physical machine includes:
acquiring the load rate of a CPU of the physical machine;
the judging whether the reference data meets the preset core number adjusting condition comprises the following steps:
judging whether the load rate is larger than a preset load rate upper limit or smaller than a preset load rate lower limit;
if yes, determining that the reference data meets the core number adjustment condition;
The controlling the target virtual machine to adjust the CPU core number according to the adjustment mode corresponding to the type of the reference data comprises the following steps:
and if the load rate is smaller than the load rate lower limit, controlling the CPU core number of all the virtual machines to be increased.
Preferably, the acquiring the reference data for characterizing the resource consumption of the CPU of the physical machine includes:
acquiring the load rate of a CPU of the physical machine;
the judging whether the reference data meets the preset core number adjusting condition comprises the following steps:
judging whether the load rate is larger than a preset load rate upper limit or smaller than a preset load rate lower limit;
if yes, determining that the reference data meets the core number adjustment condition;
the controlling the target virtual machine to adjust the CPU core number according to the adjustment mode corresponding to the type of the reference data comprises the following steps:
the priority of each virtual machine is obtained and compared with a preset priority set value;
and if the load rate is smaller than the load rate lower limit, the CPU core number of the virtual machine with the control priority higher than the priority set value is increased.
In order to solve the above technical problem, the present invention further provides an apparatus for adjusting the CPU core number of a virtual machine, including:
the first acquisition module is used for acquiring reference data used for representing the resource consumption of the CPU of the physical machine;
the second judging module is used for judging whether the reference data meets the preset core number adjusting condition or not;
and the control module is used for controlling the target virtual machine to adjust the CPU core number according to the adjustment mode corresponding to the type of the reference data when the judging result of the second judging module is yes.
In order to solve the technical problem, the invention also provides a device for adjusting the CPU core number of the virtual machine, which comprises a memory for storing a computer program;
and the processor is used for realizing the step of the method for adjusting the CPU core number of the virtual machine when executing the computer program.
In order to solve the above technical problem, the present invention further provides a computer readable storage medium, where a computer program is stored, and the computer program when executed by a processor implements the steps of the method for adjusting the CPU core number of the virtual machine.
The method for adjusting the CPU core number of the virtual machine provided by the invention is to acquire the reference data used for representing the CPU resource consumption of the current physical machine and judge whether the reference data meets the preset core number adjusting condition to adjust the CPU core number of the target virtual machine. Therefore, the method can dynamically adjust the CPU core number of the target virtual machine according to whether the reference data accords with the core number adjustment condition or not, and can take the peak-valley characteristic of the load into consideration, so that the CPU resource of the physical machine is maximally utilized, the overall experience is improved, and compared with the prior art, the method is suitable for a large-scale desktop cloud environment, has higher adjustment efficiency and does not need to increase additional hardware resources.
In addition, the device, the equipment and the medium for adjusting the CPU core number of the virtual machine provided by the invention correspond to the method and have the same effects.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by a person of ordinary skill in the art without making any inventive effort are within the scope of the present invention.
The invention provides a method, a device, equipment and a medium for adjusting the CPU core number of a virtual machine.
In order to better understand the aspects of the present invention, the present invention will be described in further detail with reference to the accompanying drawings and detailed description.
The type of the server mentioned in the present invention is not limited, and the number of virtual machines installed on the server, and the number of cores of the CPU in each virtual machine are not limited. In order to distinguish different CPUs, the invention is divided into a CPU of a physical machine and a CPU of a virtual machine.
Fig. 1 is a flowchart of a method for adjusting the CPU core number of a virtual machine according to an embodiment of the present invention. As shown in fig. 1, the method includes:
s1: reference data for characterizing the resource consumption of the CPU of the physical machine is acquired, and the process advances to S2.
The type of the reference data in this embodiment is not limited, and may be, for example, a scheduling delay of the CPU of the virtual machine (refer to a time consumed by a CPU thread of the virtual machine to transition from a ready state to an operating state) or a load factor of the CPU of the physical machine, as long as the resource consumption degree of the CPU of the physical machine can be reflected. It will be appreciated that if the scheduling delay is greater, the time consumed for the CPU of the virtual machine to transition from the ready state to the running state is longer, the resources of the CPU of the corresponding physical machine may be more intense, and thus, the resource consumption degree of the CPU of the physical machine may be measured by the parameter of the scheduling delay. Similarly, if the load rate of the CPU of the physical machine is higher, the resources of the CPU of the corresponding physical machine may be more intense, and therefore, the resource consumption degree of the CPU of the physical machine may be measured by the parameter of the load rate of the CPU of the physical machine.
In addition, the reference data acquisition mode needs to be determined according to the type of the reference data, and may be acquired in real time or acquired at intervals of a predetermined time. It can be understood that if the acquisition is performed in real time, on one hand, frequent occupation of CPU resources of the physical machine is caused, and on the other hand, frequent adjustment of the core number of the CPU of the virtual machine is caused, which is not beneficial to running stability of the virtual machine. Therefore, as a preferred embodiment, the acquisition is typically performed at predetermined intervals in this step.
S2: and judging whether the reference data meets the preset core number adjusting condition, and if so, entering S3.
The core number adjustment condition can be set according to the CPU parameters of each physical machine and can be dynamically modified, which is not described in detail in this embodiment. The adjustment manners in the condition of adjusting the core number are different according to the types of the reference data, for example, the types of the reference data mentioned above may be scheduling delay of the virtual machine or load rate of the CPU of the physical machine, and the corresponding adjustment manners are specifically described below.
S3: and controlling the target virtual machine to adjust the CPU core number according to the adjustment mode corresponding to the type of the reference data.
The target virtual machine mentioned in this embodiment may be all virtual machines running on the physical machine, or may be part of virtual machines, or may be determined by the type of the reference data, which is not described in detail in this embodiment. In addition, the virtual machines mentioned in the invention are all multi-core numbers, and the core number is at least 2. The adjustment method mentioned here may be to increase the number of CPU cores of the target virtual machine or to decrease the number of CPU cores of the target virtual machine. It should be noted that, since the type of the reference data is not limited, for the virtual machines, all virtual machines may be adjusted, or some virtual machines may be adjusted, and all virtual machines may be adjusted in the same adjustment manner, or may be adjusted in different adjustment manners, for example, the adjustment manner may be to increase the number of CPU cores or decrease the number of CPU cores. If the CPU core number is increased, the specific operation is to scan all application processes of the target virtual machine and modify the CPU affinity of the processes so as to achieve the purpose of increasing the core number. If the CPU core number is reduced, the specific operation is to scan all application processes of the current target virtual machine and modify the CPU affinity of the processes so as to achieve the purpose of reducing the core number. In a specific implementation, the adjustment may be implemented by 0 and 1, for example, 0 indicates a decrease in the number of CPU cores and 1 indicates an increase in the number of CPU cores.
The method for adjusting the number of CPU cores of the virtual machine provided by the embodiment is to acquire reference data for representing the CPU resource consumption of the current physical machine, and judge whether the reference data meets the preset condition for adjusting the number of cores to adjust the number of CPU cores of the target virtual machine. Therefore, the method can dynamically adjust the CPU core number of the target virtual machine according to whether the reference data accords with the core number adjustment condition or not, and can take the peak-valley characteristic of the load into consideration, so that the CPU resource of the physical machine is maximally utilized, the overall experience is improved, and compared with the prior art, the method is suitable for a large-scale desktop cloud environment, has higher adjustment efficiency and does not need to increase additional hardware resources.
Fig. 2 is a flowchart of a method for adjusting the number of CPU cores of a virtual machine by scheduling delay according to an embodiment of the present invention. As shown in fig. 2, in the above embodiment, the reference data in S1 includes the scheduling delay of each virtual machine, the preset condition of adjusting the number of cores in S2 is specifically that the scheduling delay is greater than the preset upper threshold limit or the scheduling delay is less than the preset lower threshold limit, and the adjustment in S3 is specifically that the number of CPU cores of the virtual machine whose scheduling delay is greater than the upper threshold limit is reduced and the number of CPU cores of the virtual machine whose scheduling delay is less than the lower threshold limit is increased.
On this basis, the steps mentioned in fig. 1 include:
s11: acquiring the scheduling delay of each virtual machine;
s21: and judging whether the scheduling delay is greater than a preset upper threshold limit and/or less than a preset lower threshold limit, and if so, proceeding to S31.
And S21, if the judgment result is yes, the reference data is stated to meet the condition of adjusting the core number.
S31: the number of CPU cores controlling the virtual machines with scheduling delays greater than the upper threshold limit decreases and/or the number of CPU cores controlling the virtual machines with scheduling delays less than the lower threshold limit increases.
It is apparent that in this embodiment, the target virtual machine is a virtual machine whose scheduling delay is greater than the upper threshold limit or less than the lower threshold limit. It may be understood that there are multiple virtual machines on a physical machine, where each virtual machine is multi-core, for example, one virtual machine is 4-core, i.e. there are 4 CPUs of the virtual machines, then each CPU of the virtual machine has its own corresponding scheduling delay, and any one of the 4 scheduling delays may be used as the scheduling delay of the virtual machine. It is apparent that the scheduling delays of the CPUs of the respective virtual machines may be the same or different even though they are the same virtual machine. Therefore, as a preferred embodiment, the scheduling delay of each virtual machine is an average value of the scheduling delays of the CPUs of the running virtual machines included in the scheduling delay, that is, the average scheduling delay of the virtual machines is specifically obtained in S1. In order to make the scheme more clear to those skilled in the art, a specific method for acquiring the average scheduling delay of each virtual machine is specifically described.
a. Acquiring a Process Identifier (PID) of a virtual machine running on a current physical machine;
b. obtaining the PID of the thread of the CPU of the virtual machine contained in the virtual machine through the PID of the virtual machine;
c. the average scheduling delay generated by the threads of all CPUs of each virtual machine in each scheduling event is collected in a specified time interval.
The scheduling event refers to a context switch event generated by a thread of a CPU of the virtual machine. Scheduling delay refers to the time consumed by a thread of a CPU of a virtual machine to transition from a ready state to a run state.
It will be appreciated that the specified time interval may be fixed or may be dynamically variable according to a parameter, for example, the specified time interval may be smaller near the peak valley and larger away from the peak valley in consideration of the peak valley characteristic of the load. The size of the specified time interval is not limited in this embodiment, and only the frequency of adjusting the number of cores of the virtual machine is affected. Table 1 is a table of comparison of average scheduling delays for each virtual machine.
TABLE 1
Since the reference data is the scheduling delay of each virtual machine and the scheduling delay of each virtual machine is different, the adjustment mode corresponding to each virtual machine may be different and needs to be determined according to the scheduling delay, the upper threshold limit and the lower threshold limit. The upper threshold is used for representing the CPU resource shortage of the virtual machine, if the upper threshold exceeds the CPU resource shortage, the core number needs to be reduced, and the lower threshold is used for representing the CPU resource shortage of the virtual machine, if the lower threshold is lower than the CPU resource shortage, the core number can be increased. In this embodiment, the virtual machines greater than the upper threshold limit or the virtual machines less than the lower threshold limit need to be adjusted, and the virtual machines not greater than the upper threshold limit or the virtual machines not less than the lower threshold limit need not to be adjusted.
In order to ensure the running stability of the virtual machine, in a specific implementation, when the average scheduling delays of the continuous predetermined times are all greater than the upper threshold limit or all less than the lower threshold limit, the number of CPU cores of the control target virtual machine may be reduced or increased, and the predetermined times may be 3 times. In addition, in this embodiment, the number of the reduced CPU cores and the number of the increased CPU cores are not limited, for example, the number of the reduced CPU cores may be reduced by half at a time, and of course, neither the reduction nor the increase affects the normal operation of the virtual machine, for example, only one CPU is currently running in one virtual machine, and therefore, the number of the reduced CPU cores cannot be reduced any more, which is well known to those skilled in the art, and the description of this embodiment is omitted.
In this embodiment, the scheduling delay of the virtual machine is used as the reference data, and since the scheduling delay of the virtual machine can accurately reflect the real running condition of the virtual machine, the accuracy of adjustment can be ensured by adjusting the number of CPU cores of the virtual machine through the parameter, thereby further improving the resource utilization rate of the CPU of the physical machine.
As shown in fig. 2, on the basis of the above embodiment, the present embodiment further includes, before S11:
s41: the load factor of the CPU of the physical machine is acquired, and the process advances to S42.
S42: and judging whether the load rate is higher than a preset load rate set value, and if so, entering S11.
In specific implementation, the load rate of the CPU of the physical machine directly affects the resource consumption of the CPU of the physical machine, and the higher the load rate, the higher the scheduling delay of the corresponding virtual machine, which is a positive correlation relationship. It can be understood that, the higher the load rate, the greater the CPU resource consumption of the physical machine, the higher the probability that the scheduling delay is greater than the upper threshold limit, and the lower the probability that the scheduling delay is less than the lower threshold limit, so when the load rate is higher than the load rate set value, the more the CPU core number of the virtual machine decreases, and the less the increase.
Note that, the load factor set value may be set according to the CPU performance of the physical machine, and the embodiment is not limited. In one embodiment, if the load factor is not higher than the load factor set value, the subsequent judgment is not needed, that is, the current resource consumption degree of the CPU is considered to not influence the performance of the virtual machine, and the CPU core number of the virtual machine is not needed to be adjusted.
In the implementation, before judging the scheduling delay, judging the load rate, and adjusting the CPU core number of the virtual machine only when two parameters meet corresponding conditions, so that the adjustment rationality can be ensured.
Fig. 3 is a flowchart of another method for adjusting the CPU core number of a virtual machine by scheduling delay according to an embodiment of the present invention. As shown in fig. 3, in order to prevent the performance degradation caused by the reduction of the number of cores of the CPU of the virtual machine with a high priority level, the present embodiment adds consideration to the priority level when adjusting the number of cores of the CPU of the virtual machine.
The reference data in S1 includes a scheduling delay of each virtual machine, the preset condition of adjusting the number of cores in S2 is that the scheduling delay is greater than a preset upper threshold limit or the scheduling delay is less than a preset lower threshold limit, and the adjustment in S3 is that the number of CPU cores of the virtual machines with the scheduling delay greater than the upper threshold limit and the priority lower than the priority set value is reduced, and/or the number of CPU cores of the virtual machines with the scheduling delay less than the lower threshold limit and the priority higher than the priority set value is increased.
On this basis, the steps mentioned in fig. 1 include:
s11: acquiring the scheduling delay of each virtual machine;
s21: judging whether the scheduling delay is greater than a preset upper threshold limit and/or less than a preset lower threshold limit; if so, S32 is entered.
S32: and acquiring the priority of each virtual machine and comparing the priority with a preset priority set value.
S33: the number of CPU cores of the virtual machine controlling the scheduling delay to be greater than the upper threshold limit and the priority to be lower than the priority set value is reduced, and/or the number of CPU cores of the virtual machine controlling the scheduling delay to be less than the lower threshold limit and the priority to be higher than the priority set value is increased.
It should be noted that, the priority setting value in this embodiment may be determined according to actual situations, and the priority of each virtual machine is not fixed and may be modified. In this embodiment, the priority is added, so that the priority of the virtual machine with higher priority can be increased, and the priority of the virtual machine with lower priority can be reduced, thereby maximizing the utilization of the resources of the CPU of the physical machine.
Fig. 4 is a flowchart of a method for adjusting the number of CPU cores of a virtual machine according to an embodiment of the present invention. As shown in fig. 4, in the above embodiment, the reference data is a scheduling delay of each virtual machine, in this embodiment, the reference data in S1 includes a CPU load rate of a physical machine, the preset condition of adjusting the number of cores in S2 is specifically that the load rate of the CPU of the physical machine is greater than an upper load rate limit or less than a lower load rate limit, the adjustment mode in S3 is specifically that the load rate is greater than the upper load rate limit, the number of CPU cores of all virtual machines is reduced, the load rate is less than the lower load rate limit, and the number of CPU cores of all virtual machines is increased.
On this basis, the steps mentioned in fig. 1 include:
s51: and acquiring the load rate of the CPU of the physical machine.
S52: judging whether the load rate is larger than a preset load rate upper limit or smaller than a preset load rate lower limit; if so, S53 is entered.
S53: if the load factor is greater than the upper load factor limit, the number of CPU cores controlling all virtual machines is reduced, and if the load factor is less than the lower load factor limit, the number of CPU cores controlling all virtual machines is increased.
In a specific implementation, the load rate of the CPU of the physical machine directly affects the resource consumption of the CPU of the physical machine, unlike the scheduling delay mentioned above as the reference data, in this embodiment, the same adjustment manner is the same for each virtual machine in the same adjustment, that is, either all virtual machines reduce the number of CPU cores, or all virtual machines increase the number of CPU cores. It is apparent that in this embodiment, all virtual machines are target virtual machines.
In order to ensure the running stability of the virtual machine, in a specific implementation, when the load rates of the continuous predetermined times are all greater than the upper limit of the load rate or all less than the lower limit of the load rate, the number of CPU cores of the control target virtual machine may be reduced or increased, and the predetermined times may be 3 times. In addition, in this embodiment, the number of the reduced CPU cores and the number of the increased CPU cores are not limited, for example, the number of the reduced CPU cores may be reduced by half at a time, and of course, neither the reduction nor the increase affects the normal operation of the virtual machine, which is not described in detail in this embodiment.
In this embodiment, the load rate of the CPU of the physical machine is used as the reference data, and since the load rate of the CPU of the physical machine can accurately reflect the resource consumption condition of the CPU of the physical machine, the accuracy of adjustment can be ensured by adjusting the number of CPU cores of the virtual machine through the parameter, thereby further improving the resource utilization rate of the CPU of the physical machine.
Fig. 5 is a flowchart of a method for adjusting the number of CPU cores of a virtual machine according to an embodiment of the present invention. As shown in fig. 5, in order to prevent the performance degradation caused by the reduction of the number of cores of the CPU of the virtual machine with a high priority level, the present embodiment adds consideration to the priority level when adjusting the number of cores of the CPU of the virtual machine.
In this embodiment, the reference data in S1 includes the CPU load rate of the physical machine, the preset condition for adjusting the number of cores in S2 is specifically that the load rate of the CPU of the physical machine is greater than the upper load rate limit or less than the lower load rate limit, and the adjustment mode in S3 is specifically that if the load rate is greater than the upper load rate limit, the number of CPU cores of the virtual machine with a priority lower than the priority set value is reduced, and if the load rate is less than the lower load rate limit, the number of CPU cores of the virtual machine with a priority higher than the priority set value is increased.
On this basis, the steps mentioned in fig. 1 include:
s51: acquiring the load rate of a CPU of a physical machine;
s52: judging whether the load rate is greater than a preset load rate upper limit or less than a preset load rate lower limit, if so, entering S54;
s54: acquiring the priority of each virtual machine and comparing the priority with a preset priority set value;
s55: if the load factor is greater than the load factor upper limit, the CPU core number of the virtual machine with the control priority lower than the priority set value is reduced, and if the load factor is less than the load factor lower limit, the CPU core number of the virtual machine with the control priority higher than the priority set value is increased.
It should be noted that, the priority setting value in this embodiment may be determined according to actual situations, and the priority of each virtual machine is not fixed and may be modified. In this embodiment, the priority is added, so that the priority of the virtual machine with higher priority can be increased, and the priority of the virtual machine with lower priority can be reduced, thereby maximizing the utilization of the resources of the CPU of the physical machine.
In the above embodiments, the method for adjusting the number of CPU cores of the virtual machine is described in detail, and the present invention further provides embodiments corresponding to the device and the equipment for adjusting the number of CPU cores of the virtual machine. One based on the angle of the functional module and the other based on the angle of the hardware structure.
Fig. 6 is a block diagram of a device for adjusting the number of CPU cores of a virtual machine according to an embodiment of the present invention. As shown in fig. 6, the apparatus includes:
a first acquisition module 10 for acquiring reference data for characterizing the resource consumption of the CPU of the physical machine;
a first judging module 11, configured to judge whether the reference data meets a preset core number adjustment condition;
and the control module 12 is used for controlling the target virtual machine to adjust the CPU core number according to the adjustment mode corresponding to the type of the reference data when the judgment result of the first judgment module is yes.
Since the embodiments of the apparatus portion and the embodiments of the method portion correspond to each other, the embodiments of the apparatus portion are referred to the description of the embodiments of the method portion, and are not repeated herein.
According to the CPU core number adjusting device for the virtual machine, the first obtaining module obtains the reference data used for representing the CPU resource consumption of the current physical machine, and the first judging module judges whether the reference data meets the preset core number adjusting condition or not, so that the control module adjusts the CPU core number of the target virtual machine according to the result of the first judging module. Therefore, the device can dynamically adjust the CPU core number of the target virtual machine according to whether the reference data accords with the core number adjustment condition or not, and can take the peak-valley characteristic of the load into consideration, so that the CPU resource of the physical machine is utilized to the maximum extent, the overall experience is improved, and in addition, compared with the prior art, the device is suitable for a large-scale desktop cloud environment, the adjustment efficiency is higher, and additional hardware resources are not required to be added.
In a specific embodiment, the first obtaining module 10 is specifically configured to obtain a scheduling delay of each virtual machine;
a first judging module 11, configured to specifically judge whether the scheduling delay is greater than a preset upper threshold limit and/or less than a preset lower threshold limit; if yes, determining that the reference data meets the core number adjustment condition, and triggering a control module 12;
the control module 12 is specifically configured to control the number of CPU cores of the virtual machine whose scheduling delay is greater than the upper threshold limit to decrease and/or control the number of CPU cores of the virtual machine whose scheduling delay is less than the lower threshold limit to increase.
Further, the device further comprises:
a second obtaining module 13, configured to obtain a load rate of a CPU of the physical machine;
the second judging module 14 is configured to judge whether the load factor is higher than a preset load factor set value, and if so, trigger the first acquiring module.
In another embodiment, the first obtaining module 10 is specifically configured to obtain a scheduling delay of each virtual machine;
a first judging module 11, configured to specifically judge whether the scheduling delay is greater than a preset upper threshold limit and/or less than a preset lower threshold limit; if yes, determining that the reference data meets the core number adjusting condition, and triggering a control module;
The control module 12 includes:
the acquisition unit is used for acquiring the priority of each virtual machine and comparing the priority with a preset priority set value;
and the control unit is used for controlling the CPU core number of the virtual machine with the scheduling delay larger than the upper threshold limit and the priority lower than the priority set value to be reduced, and/or controlling the CPU core number of the virtual machine with the scheduling delay smaller than the lower threshold limit and the priority higher than the priority set value to be increased.
Further, the obtaining module 10 is specifically configured to obtain an average scheduling delay of each virtual machine.
In another specific embodiment, the first obtaining module 10 is specifically configured to obtain a load rate of a CPU of the physical machine;
the first judging module 11 is specifically configured to judge whether the load factor is greater than a preset load factor upper limit or less than a preset load factor lower limit; if yes, determining that the reference data meets the core number adjustment condition, and triggering the control module 12;
the control module 12 is specifically configured to control the number of CPU cores of all virtual machines to decrease if the load factor is greater than the upper load factor limit, and control the number of CPU cores of all virtual machines to increase if the load factor is less than the lower load factor limit.
In another specific embodiment, the first obtaining module 10 is specifically configured to obtain a load rate of a CPU of the physical machine;
The first judging module 11 is specifically configured to judge whether the load factor is greater than a preset load factor upper limit or less than a preset load factor lower limit; if yes, determining that the reference data meets the core number adjusting condition; and triggers the control module 12;
the control module 12 includes:
the acquisition unit is used for acquiring the priority of each virtual machine and comparing the priority with a preset priority set value;
and the control unit is used for controlling the CPU core number of the virtual machine with the priority lower than the priority set value to be reduced if the load rate is larger than the upper limit of the load rate, and controlling the CPU core number of the virtual machine with the priority higher than the priority set value to be increased if the load rate is smaller than the lower limit of the load rate.
Fig. 7 is a block diagram of a device for adjusting the number of CPU cores of a virtual machine according to an embodiment of the present invention. Based on the angle of the hardware structure, the embodiment of the invention provides an adjusting device for the CPU core number of the virtual machine, as shown in FIG. 7, the device comprises a memory 20 for storing a computer program;
the processor 21 is configured to implement the steps of the method for adjusting the number of CPU cores of the virtual machine as mentioned in the above-described method embodiment when executing the computer program.
The device for adjusting the number of CPU cores of the virtual machine provided in this embodiment may include, but is not limited to, a smart phone, a tablet computer, a notebook computer, a desktop computer, or the like.
Processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 may be implemented in at least one hardware form of DSP (Digital Signal Processing ), FPGA (Field-Programmable Gate Array, field programmable gate array), PLA (Programmable Logic Array ). The processor 21 may also comprise a main processor, which is a processor for processing data in an awake state, also called CPU (Central Processing Unit ); a coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 21 may integrate a GPU (Graphics Processing Unit, image processor) for rendering and drawing of content required to be displayed by the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence ) processor for processing computing operations related to machine learning.
Memory 20 may include one or more computer-readable storage media, which may be non-transitory. Memory 20 may also include high-speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In this embodiment, the memory 20 is at least used for storing a computer program 201, where the computer program, after being loaded and executed by the processor 21, can implement the relevant steps of the device for adjusting the CPU core number of the virtual machine disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 20 may further include an operating system 202, data 203, and the like, where the storage manner may be transient storage or permanent storage. The operating system 202 may include Windows, unix, linux, among others. The data 203 may include, but is not limited to, reference data, and the like.
In some embodiments, the device for adjusting the CPU core number of the virtual machine may further include a display 22, an input/output interface 23, a communication interface 24, a power supply 25, and a communication bus 26.
Those skilled in the art will appreciate that the structure shown in fig. 7 does not constitute a limitation of the adjustment device for the CPU core number of the virtual machine, and may include more or less components than those illustrated.
The device for adjusting the CPU core number of the virtual machine, provided by the embodiment of the application, comprises a memory and a processor, wherein the processor can realize the following method when executing a program stored in the memory: acquiring reference data for representing the resource consumption of a CPU of a physical machine; judging whether the reference data meets the preset core number adjusting condition or not; and if so, controlling the target virtual machine to adjust the CPU core number according to the adjustment mode corresponding to the type of the reference data.
Since the embodiments of the present section and the embodiments of the method section correspond to each other, the embodiments of the present section refer to the description of the embodiments of the method section, and are not repeated herein.
The device for adjusting the CPU core number of the virtual machine provided by the embodiment of the application comprises a memory and a processor, wherein the processor can execute the method. Therefore, the method can dynamically adjust the CPU core number of the target virtual machine according to whether the reference data accords with the core number adjustment condition or not, and can take the peak-valley characteristic of the load into consideration, so that the CPU resource of the physical machine is maximally utilized, the overall experience is improved, and compared with the prior art, the method is suitable for a large-scale desktop cloud environment, has higher adjustment efficiency and does not need to increase additional hardware resources.
Finally, the present application also provides a corresponding embodiment of the computer readable storage medium. The computer-readable storage medium has stored thereon a computer program which, when executed by a processor, performs the steps as described in the method embodiments above.
It will be appreciated that the methods of the above embodiments, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored on a computer readable storage medium. With such understanding, the technical solution of the present application, or a part contributing to the prior art or all or part of the technical solution, may be embodied in the form of a software product stored in a storage medium, performing all or part of the steps of the method described in the various embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The computer readable storage medium provided in the embodiments of the present application stores a program capable of implementing the above method, and when the program is executed, the above method can be implemented. Therefore, the method can dynamically adjust the CPU core number of the target virtual machine according to whether the reference data accords with the core number adjustment condition or not, and can take the peak-valley characteristic of the load into consideration, so that the CPU resource of the physical machine is maximally utilized, the overall experience is improved, and compared with the prior art, the method is suitable for a large-scale desktop cloud environment, has higher adjustment efficiency and does not need to increase additional hardware resources.
The method, the device, the equipment and the medium for adjusting the CPU core number of the virtual machine provided by the invention are described in detail. In the description, each embodiment is described in a progressive manner, and each embodiment is mainly described by the differences from other embodiments, so that the same similar parts among the embodiments are mutually referred. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section. It should be noted that it will be apparent to those skilled in the art that various modifications and adaptations of the invention can be made without departing from the principles of the invention and these modifications and adaptations are intended to be within the scope of the invention as defined in the following claims.
It should also be noted that in this specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.