Resource allocation method, apparatus, device, and storage medium
By obtaining the transmission rate parameters of the physical network card and the virtual machine, and dynamically planning the number of PMD threads, the problems of resource waste and inefficiency in the virtual network are solved, and the rational allocation of resources and efficiency improvement are achieved.
Patent Information
- Application Number
- CN202210387958.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-14
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2042-04-14
AI Technical Summary
In existing technologies, allocating PMD threads based on experience leads to a waste of vCPU resources or low overall efficiency in packet processing within the virtual network.
By obtaining the transmission rate parameters of the physical network card and the virtual machine, the number of PMD threads is dynamically planned, and combined with the virtual processor resources of the host machine, the problems of resource waste and inefficiency are avoided.
This enables the rational allocation of vCPU resources in the virtual network, improving the efficiency and throughput of virtual machine packet processing and avoiding resource waste.
Smart Images

Figure CN116954874B_ABST
Abstract
Description
Technical Field
[0001] This application relates to communication technology, and more particularly to a resource allocation method, apparatus, device, and storage medium. Background Technology
[0002] Cloud computing enables the creation of multiple virtual machines (VMs) on one or more host machines, sharing the host machine's CPU and memory resources. Currently, OpenvSwitch with DPDK (Data Plane Development Kit) technology is used to optimize the VM's packet sending and receiving capabilities. Data packets are sent via the host machine's physical network card, bypassing the kernel space, and are forwarded directly into the VM by the Poll Mode Driver (PMD) thread. Typically, after deploying OpenvSwitch (OvS), the host machine allocates a fixed number of PMD threads based on the number of Non-Uniform Memory Access (NUMA) nodes, using experience.
[0003] However, based on experience, allocating a fixed number of PMD threads often fails to capture the server's maximum virtual network throughput or expected packet rate and throughput. Allocating too many PMDs wastes Virtual Central Processing Unit (vCPU) resources, reducing the server's vCPU resources available for computation; conversely, allocating too few PMDs results in lower overall efficiency for packet processing within the virtual network. Summary of the Invention
[0004] This application provides a resource allocation method, apparatus, device, and storage medium to solve the problem in the prior art that vCPU resource allocation leads to waste of vCPU resources or low efficiency of overall virtual machine packet processing in virtual networks.
[0005] In a first aspect, this application provides a resource allocation method, wherein M virtual machines are deployed on a host machine, the host machine has N allocatable virtual processor resources, and Q PMD threads are currently deployed on the host machine. Each PMD thread forwards packets received by the host machine's physical network interface card to the corresponding virtual machine for processing. Each PMD thread occupies one virtual processor resource. M and Q are both integers greater than or equal to 1, and N is an integer greater than or equal to 2. The method includes:
[0006] Obtain the first parameter of the physical network interface card (NIC), which is related to the maximum transmission rate of the physical NIC.
[0007] The virtual test machine is controlled to perform packet sending stress test on the host machine at a first rate, and a second parameter of the host machine is obtained. The second parameter is related to the total maximum transmission rate of the M virtual machines based on the Q PMD threads for processing packets. The first rate is greater than or equal to the maximum transmission rate of the physical network card.
[0008] Based on the first parameter and the second parameter, the target number Z of the PMD threads is obtained; Z is less than N, and Z is used to determine the number of virtual processor resources allocated to the PMD threads.
[0009] Optionally, the first parameter includes: the maximum bandwidth of the physical network card and the rate-limited packet rate, and the second parameter includes: the total bandwidth of the M virtual machines processing packets based on the Q PMD threads and the total packet rate.
[0010] Optionally, obtaining Z based on the first parameter and the second parameter includes: obtaining a first initial target number Z1 of the PMD threads based on the total packet rate and the rate-limited packet rate; obtaining a second initial target number Z2 of the PMD threads based on the total bandwidth and the maximum bandwidth; and obtaining Z based on the first Z1 and the Z2.
[0011] Optionally, obtaining the first initial target number Z1 of the PMD threads based on the total packet rate and the rate-limited packet rate includes: if the total packet rate is less than the rate-limited packet rate, increasing the number of the PMD threads until the total packet rate is less than the rate-limited packet rate and the total packet rate no longer increases, or the total packet rate is equal to the rate-limited packet rate, thus obtaining the Z1.
[0012] Optionally, obtaining the second initial target number Z2 of the PMD threads based on the total bandwidth and the maximum bandwidth includes: if the total bandwidth is less than the maximum bandwidth, increasing the number of the PMD threads until the total bandwidth is less than the maximum bandwidth and the total bandwidth no longer increases, or the total bandwidth is equal to the maximum bandwidth, thus obtaining the Z2.
[0013] Optionally, obtaining Z based on Z1 and Z2 includes: taking the maximum value among Z1 and Z2 as Z.
[0014] Optionally, the step of controlling the virtual test machine to perform packet sending stress testing on the host machine at a first rate and obtaining the second parameters of the host machine includes: deploying the virtual test machine; controlling the virtual test machine to run a server process and controlling the virtual machines on the host machine to run a packet forwarding process, wherein the server process is used to send test packets to the host machine at the first rate, and the packet forwarding process is used to swap the address information of the sender and the address information of the receiver in the test packet and return it to the virtual test machine; obtaining the packet rate and bandwidth value of each virtual machine; adding the packet rates of each virtual machine to obtain the total packet rate; and adding the bandwidth values of each virtual machine to obtain the total bandwidth.
[0015] Optionally, obtaining the first parameter of the physical network interface card includes: obtaining the maximum bandwidth of the physical network interface card; and obtaining the rate-limiting packet rate of the physical network interface card based on the maximum bandwidth of the physical network interface card and the minimum packet length.
[0016] Optionally, if the values of Z and Q are different, then based on Z, a mapping relationship between Z PMD threads and the virtual processor resources of the host machine is obtained, and the mapping relationship is used to configure the number of PMD threads of the host machine.
[0017] Optionally, the N allocable virtual processor resources include X virtual processor resources reserved for virtual machines. The step of obtaining the mapping relationship between the Z PMD threads and the virtual processor resources of the host machine based on Z includes:
[0018] If Z is less than or equal to Y, then Z virtual processor resources are allocated from the Y virtual processor resources to Z PMD threads to obtain the mapping relationship between the Z PMD threads and the virtual processor resources of the host machine; Y is the virtual processor resources other than the X virtual processor resources among the N virtual processor resources.
[0019] If Z is greater than Y, and there are H idle virtual processor resources among the X virtual processor resources, then the Y virtual processor resources and the H idle virtual processor resources are allocated to Z PMD threads to obtain the mapping relationship between the Z PMD threads and the virtual processor resources of the host machine, wherein H is an integer less than or equal to the difference between Z and Y.
[0020] Secondly, this application provides a resource allocation device, wherein the test equipment is connected to the host machine, the host machine has M virtual machines deployed on it, the host machine has N allocatable virtual processor resources, and the host machine currently has Q PMD threads deployed on it. Each PMD thread forwards packets received by the host machine's physical network interface card to the corresponding virtual machine for processing. Each PMD thread occupies one virtual processor resource. M and Q are both integers greater than or equal to 1, and N is an integer greater than or equal to 2. The resource allocation device is applied to the test equipment and includes:
[0021] The acquisition module is used to acquire a first parameter of the physical network card, the first parameter being related to the maximum transmission rate of the physical network card; acquire a second parameter of the host machine, the second parameter being related to the total maximum transmission rate of the M virtual machines processing packets based on the Q PMD threads; the first rate is greater than or equal to the maximum transmission rate of the physical network card.
[0022] The testing module is used to control the virtual testing machine to perform packet sending stress tests on the host machine at a first rate.
[0023] The processing module is configured to obtain the target number Z of the PMD threads based on the first parameter and the second parameter; Z is less than N, and Z is used to determine the number of virtual processor resources allocated to the PMD threads.
[0024] Thirdly, this application provides a testing device, comprising: a processor, and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the resource allocation method as described in any of the first aspects.
[0025] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the resource allocation method as described in any of the first aspects.
[0026] The resource allocation method, apparatus, device, and storage medium provided in this application dynamically plan the number of PMD threads by combining the data transmission rate of the host machine's physical network card and the total data transmission rate of the virtual machines deployed on the host machine, thereby avoiding the waste of vCPU resources or the low efficiency of the overall virtual machines in processing packets in the virtual network. Attached Figure Description
[0027] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0028] Figure 1 A schematic diagram of a virtual network scenario provided in an embodiment of this application;
[0029] Figure 2 A schematic diagram of a host architecture provided in an embodiment of this application;
[0030] Figure 3 A flowchart illustrating a resource allocation method provided in an embodiment of this application;
[0031] Figure 4 This is a schematic diagram of the structure of a resource allocation device provided in an embodiment of this application;
[0032] Figure 5 This is a schematic diagram of a test device structure provided in an embodiment of this application.
[0033] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0034] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0035] To facilitate understanding, a possible virtual network scenario involved in the embodiments of this application will be described first.
[0036] Figure 1 This is a schematic diagram of a possible virtual network scenario involved in an embodiment of this application, such as... Figure 1 As shown, the host machine can deploy M virtual machines, which are used to process data packets.
[0037] The host machine mentioned here can be an electronic device used for data processing, such as a server or terminal device. In the host machine's operating system, virtual memory is divided into two parts: kernel space and user space. Kernel space runs independent of ordinary applications, operating at a higher privilege level. This kernel software resides in a protected memory space and has full access to hardware devices. Code in user space runs at a lower privilege level, can only see a portion of the system resources it is allowed to use, and cannot use certain system functions, directly access kernel space and hardware devices, and faces other specific usage restrictions. The M virtual machines mentioned above are deployed in the host machine's user space.
[0038] The host machine uses Open vSwitch with DPDK (Data Plane Development Kit) technology to send and receive packets for the virtual machine. Specifically, data packets are routed across the kernel space via the host's physical network interface card (NIC). The host machine then calls the Poll Mode Driver (PMD) thread to forward the data packets directly to the virtual machine. In other words, the host machine forwards data packets received on its physical NIC to the virtual machine for processing by calling the PMD thread. Further, the host machine, by calling the PMD thread, forwards data packets received by the network interface controller (NIC) on its physical NIC to the virtual machine's virtual NIC port, through which the virtual machine receives these data packets.
[0039] The host machine's physical network interface card (NIC) is used for communication and data transmission between the host machine and external devices. Internally, the host machine calls the PMD thread to connect the physical NIC to the virtual network interface port of the virtual machine. The PMD thread, acting as the data transmission entry point, is responsible for data transmission between the physical NIC and the virtual network interface port of the virtual machine.
[0040] The host machine can be an electronic device using a NUMA architecture processor, and the processor can be divided into multiple NUMA nodes according to actual needs. Additionally, the host machine has N allocatable virtual processor (vCPU) resources, which are evenly distributed across the multiple NUMA nodes. For example, using... Figure 2 The host architecture shown is an example. Figure 2 As shown, the host machine divides the processor into 4 NUMA nodes according to actual needs. The host machine has 96 virtual processor (vCPU) resources that can be allocated, and each NUMA node has 24 vCPU resources.
[0041] The host machine can deploy one or more virtual machines as needed, and each virtual machine can occupy one or more vCPU resources as required. Additionally, each PMD thread needs to occupy and bind one vCPU resource; the more PMD threads, the higher the data transmission efficiency. For example, if, based on actual needs, five dual-core virtual machines are deployed, with each core of each virtual machine occupying one vCPU resource, then the five virtual machines will require a total of 10 vCPU resources from the host machine. If, based on experience, the number of PMD threads is set to 20, then each PMD thread will occupy and bind one vCPU resource, for a total of 20 vCPU resources. All of the above virtual machines are deployed in the host machine's user space. These one or more virtual machines are based on the OpenvSwitch standard and are used to process the data content in the data packets received from the PMD threads.
[0042] Existing technologies optimize virtual machine packet transmission and reception capabilities based on Open vSwitch with DPDK (Data Plane Development Kit, DPDK). Typically, after deploying Open vSwitch, the host machine can allocate a fixed number of PMD threads based on the number of NUMA nodes, meaning a fixed number of PMD threads are evenly distributed across each NUMA node. Alternatively, the host machine can allocate the fixed number of PMD threads, based on experience, to only one NUMA node. These fixed number of PMD threads are used for data transmission.
[0043] However, in this virtual network scenario using Open vSwitch with DPDK, the total packet sending and receiving capacity of N virtual machines is limited by the packet distribution capability of the PMD threads in the Open vSwitch. Current technologies, which allocate a fixed number of PMD threads based on experience, often fail to capture the maximum throughput or expected packet per second (PPS) of the virtual network on the server host. Allocating too many PMD threads wastes vCPU resources, reducing the vCPU resources available for computation by the virtual machines on the server host; conversely, allocating too few PMD threads results in low utilization of the host's physical network interface card (NIC), meaning lower overall packet processing efficiency for the virtual machines in the virtual network.
[0044] In view of this, this application proposes a resource allocation method based on Open vSwitch with DPDK technology, which can dynamically plan the number of PMD threads by combining the data transmission rate of the host's physical network card and the total data transmission rate of the virtual machines deployed on the host, so as to avoid the waste of vCPU resources or the low efficiency of the overall virtual machines in the virtual network in processing packets.
[0045] The embodiments of this application are as follows: Figure 2 The example shown is a host machine using a NUMA architecture processor. Since the host machine's physical network card is directly connected to the NUMA0 node, the PMD thread configured on the NUMA0 node has high working efficiency. Therefore, the following embodiments of this application take the example of configuring the PMD thread on the NUMA0 node first.
[0046] Continue to refer to Figure 1 The execution entity of this method can be a test device, and the host machine can communicate with the test device via a wired or wireless network. The test device can be a specially deployed physical device, a configuration device for remotely configuring the host machine, or a monitoring device for remotely monitoring the host machine. The test device can be, for example, a terminal device, a server, or other electronic device.
[0047] The following is based on Figure 1 Taking the virtual network scenario shown as an example, the technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems will be described in detail with reference to specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0048] Figure 3 This is a flowchart illustrating a resource allocation method provided in an embodiment of this application, as shown below. Figure 3 As shown, the method in this embodiment includes the following steps:
[0049] S301. Obtain the first parameter of the physical network card. The first parameter is related to the maximum transmission rate of the physical network card.
[0050] For example, the first parameter includes the physical network card's maximum bandwidth and rate-limited packet rate, or the first parameter is the physical network card's maximum bandwidth, or the first parameter is the physical network card's rate-limited packet rate.
[0051] Taking the case where the first parameter includes the maximum bandwidth of the physical network card and the rate-limited packet rate as an example, it can be obtained in the following way:
[0052] Step A: Obtain the maximum bandwidth of the physical network interface card (NIC). The maximum bandwidth of the physical NIC is the bandwidth value corresponding to the actual highest transmission rate of the physical NIC. This bandwidth value can be obtained by the test device from the transmission rate of the host machine's physical NIC, or it can be obtained by the test device through stress testing the transmission capacity of the host machine's physical NIC.
[0053] Step B: Obtain the rate-limited packet rate of the physical network card. The rate-limited packet rate P of the physical network card is the packet data transmission rate corresponding to the actual maximum transmission rate of the physical network card. It can be obtained by stress testing the transmission capacity of the host physical network card through a test device, or it can be calculated by the bandwidth value M corresponding to the maximum bandwidth of the physical network card and the minimum packet length L, as shown in the following formula (1):
[0054] P=M*1000*1000 / (L+12+8) (1)
[0055] Before sending a message, the system listens for a period of time to check if the line is idle; only if it is idle can the message be sent. This listening time is called the Inter-Packet Gap (IPG), which is the time required to send 12 bytes. To enable synchronization, an 8-byte preamble is added before the Ethernet frame structure. Seven bytes are AA (01010101 in binary) for synchronization with the receiver, and the eighth byte is AB (frame delimiter) to delimit the frame, indicating that the following frames are Ethernet frames. Therefore, the actual length of the shortest frame is L + 12 + 8.
[0056] For example, if the maximum bandwidth of a physical network card corresponds to a bandwidth value M of 10000Mb / s and the minimum packet length L is 64 bytes, then the rate-limited packet rate can be calculated to be 14880952PPS.
[0057] S302. Control the virtual test machine to perform packet sending stress test on the host machine at a first rate, and obtain the second parameter of the host machine. The second parameter is related to the total maximum transmission rate of the M virtual machines based on Q PMD threads for processing packets. The first rate is greater than or equal to the maximum transmission rate of the physical network card.
[0058] For example, when the first parameter includes the maximum bandwidth of the physical network card and the rate-limited packet rate, the second parameter may include the total bandwidth and the total packet rate of the M virtual machines processing packets based on the Q PMD threads; or, when the first parameter is the maximum bandwidth of the physical network card, the second parameter may be the total bandwidth of the M virtual machines processing packets based on the Q PMD threads; or, when the first parameter is the rate-limited packet rate of the physical network card, the second parameter may be the total packet rate of the M virtual machines processing packets based on the Q PMD threads.
[0059] The packet sending capability of the virtual test machine is no less than the data transmission capability of the host machine's physical network card. That is, the rate at which the virtual test machine sends packets is greater than or equal to the maximum transmission rate of the host machine's physical network card. This is so that the virtual test machine can pass the stress test and obtain the transmission rate of the physical network card and the virtual machine when the host machine's physical network card is using its maximum transmission rate for data transmission.
[0060] Controlling the virtual test machine to perform packet-sending stress tests on the host machine at a first rate, and obtaining the host machine's second parameters, can be achieved, for example, in the following way:
[0061] First, a virtual test machine is deployed on the test equipment, or on an electronic device that the test equipment can control. This virtual test machine can communicate with the host machine via a wired or wireless network and is used to send test data packets to the host machine.
[0062] It should be understood that if a virtual test machine has already been deployed, it can be used directly to perform packet sending stress tests without further deployment. In other words, deploying a virtual test machine is an optional step.
[0063] In the embodiments described below, the test device is referred to as the test terminal, and the host machine is referred to as the server.
[0064] Secondly, the testing equipment can control the virtual test machine to run the server process and control the virtual machine on the host machine to run the message forwarding process. The server process is used to send test messages to the host machine at the first rate, and the message forwarding process is used to swap the address information of the sender and the address information of the receiver in the test message and then return it to the virtual test machine.
[0065] The virtual test machine runs a server process, causing the test machine to send test packets to the host machine at a first rate greater than or equal to the rate-limited packet rate of the host machine's physical network card. The length of the data packet containing the test packet can be the minimum data packet length containing the test packet, specifically related to the data packet length used when calculating the rate-limited packet rate of the physical network card. In other words, both the rate-limited packet rate of the physical network card and the length of the data packet containing the test packet are determined based on the data packet length supported by the host machine. This embodiment uses the aforementioned minimum data packet length as an example.
[0066] The test message may carry information such as the tenant network's VLAN, the test virtual machine's MAC address, the test virtual machine's IP address, and the virtual machine's MAC address and IP address. The test message is transmitted to M virtual machines on the host machine via Q PMD threads. After the M virtual machines process the test message, the virtual test machine controls the virtual machines on the host machine to run a message forwarding process. This process allows the host machine on the server to exchange the sending address and destination address in the received test message, thus enabling the test message to be forwarded from the virtual machines on the host machine on the server to the virtual test machine on the test side via the Q PMD threads. Q can be the number of PMD threads currently in use or used during the last run on the host machine. Alternatively, it can be an initial value set for the host machine during testing, such as 1.
[0067] Taking the second parameter as an example, which includes the total bandwidth of M virtual machines processing packets based on Q PMD threads and the total packet rate, after controlling the virtual test machine to perform a packet sending stress test on the host machine at a first rate, the packet rate and bandwidth value of each virtual machine can be obtained. For example, the test device can obtain the data transmission rate of the M virtual machines forwarding test packets through Q PMD threads by the number of data packets containing the above test packets sent at the first rate and the number of data packets containing the above test packets returned.
[0068] The virtual test machine can obtain the bandwidth value and packet rate of M virtual machines forwarding test messages through Q PMD threads by the number of data packets containing the above test messages sent at the first rate and the number of data packets containing the above test messages returned. The packet rates of each virtual machine are added together to obtain the total packet rate of the M virtual machines forwarding test messages through Q PMD threads. The bandwidth values of each virtual machine are added together to obtain the total bandwidth of the M virtual machines forwarding test messages through Q PMD threads.
[0069] For example, the linear packet rate of each virtual machine is A. n Then the linear packet rate of the first virtual machine is A1, the linear packet rate of the second virtual machine is A2, and the linear packet rate of the Mth virtual machine is A... M The total packet transmission rate of the virtual network on the host machine is A, where A = A1 + A2 + ... + A M The bandwidth value for each virtual machine is B. n Then the bandwidth value of the first virtual machine is B1, the bandwidth value of the second virtual machine is B2, and the bandwidth value of the Mth virtual machine is B... M The total virtual network bandwidth of the host machine is B, where B = B1 + B2 + ... + B M .
[0070] It should be noted that the above is only an example of how to obtain the second parameters of the host machine using packet stress testing. Of course, other methods of existing technology can also be used to obtain the second parameters of the host machine, and there is no limitation on this.
[0071] S303. Based on the first and second parameters, obtain the target number Z of PMD threads; Z is less than N.
[0072] The following example illustrates how to obtain the target number Z of PMD threads based on the first and second parameters.
[0073] In the first scenario, the first parameters of the physical network interface card (NIC) include: the maximum bandwidth and rate-limited packet rate of the NIC. The second parameter includes: the total bandwidth and total packet rate of M virtual machines processing packets based on Q PMD threads.
[0074] In this scenario, the target number Z of PMD threads is obtained based on the first and second parameters, which may include the following steps:
[0075] S401. Based on the total packet rate and the rate-limited packet rate, obtain the first initial target number Z1 for the PMD thread;
[0076] In step S302, the packet rate An of each virtual machine is obtained when the current number of PMD threads is Q, and the total packet rate A of M virtual machines processing packets based on Q PMD threads is calculated. The total packet rate A is then compared with the rate-limited packet rate P corresponding to the actual maximum transmission rate of the host machine's physical network card.
[0077] For example, if the total packet rate is less than P, then the number of PMD threads is increased by one, i.e., the increased number of PMD threads is Q+1. Correspondingly, the number of virtual processor resources used for the PMD threads is also Q+1. The increased number of PMD threads is used to repeat step S302 until the total packet rate is less than the rate-limited packet rate and the total packet rate no longer increases, or the total packet rate is equal to P, thus obtaining Z1.
[0078] For example, if the total packet rate is equal to P, then Q is taken as Z1.
[0079] For example, if the total packet rate is greater than P, the number of PMD threads is reduced by one, i.e., the reduced number of PMD threads is Q-1. Correspondingly, the number of virtual processor resources used for PMD threads is also Q-1. Step S302 is repeated using the reduced number of PMD threads until the total packet rate is greater than the rate-limited packet rate and the total packet rate no longer decreases, or the total packet rate is equal to P, thus obtaining Z1.
[0080] S402. Based on the total bandwidth and the maximum bandwidth, obtain the second initial target number Z2 of PMD threads;
[0081] In step S302, the bandwidth value Bn of each virtual machine is obtained when the current number of PMD threads is Q, and the total bandwidth B of M virtual machines processing packets based on Q PMD threads is calculated. The total bandwidth B is then compared with the maximum bandwidth M corresponding to the actual highest transmission rate of the host physical network card.
[0082] For example, if the total bandwidth is less than M, then the number of PMD threads is increased by one, that is, the increased number of PMD threads is Q+1, and correspondingly, the number of virtual processor resources used for PMD threads is also Q+1. The increased number of PMD threads is used to repeat step S302 until the total bandwidth is less than the maximum bandwidth and the total bandwidth no longer increases, or the total bandwidth value is equal to M, thus obtaining Z2.
[0083] For example, if the total bandwidth equals M, then Q is taken as Z2.
[0084] For example, if the total bandwidth is greater than M, the number of PMD threads is reduced by one, i.e., the reduced number of PMD threads is Q-1. Correspondingly, the number of virtual processor resources used for PMD threads is also Q-1. Step S302 is repeated using the reduced number of PMD threads until the total bandwidth is greater than the maximum bandwidth and the total bandwidth no longer increases, or the total bandwidth is equal to M, resulting in Z2.
[0085] S403. Based on the first Z1 and Z2, we obtain Z.
[0086] Optionally, based on the Z1 and Z2 obtained above, the maximum value of Z1 and Z2 is taken as Z.
[0087] Optionally, based on the Z1 and Z2 obtained above, the minimum value between Z1 and Z2 is taken as Z.
[0088] Optionally, based on the Z1 and Z2 obtained above, any integer value between Z1 and Z2 can be used as Z.
[0089] In the second scenario, the first parameter of the physical network interface card (NIC) includes its maximum bandwidth. The second parameter includes the total bandwidth for M virtual machines to process packets using Q PMD threads.
[0090] In this scenario, the target number Z of PMD threads is obtained based on the first and second parameters, which may include the following steps:
[0091] S501. Based on the total bandwidth and the maximum bandwidth, obtain the target number Z of PMD threads;
[0092] The method for obtaining the total bandwidth is described in the aforementioned embodiment and will not be repeated here.
[0093] For example, if the total bandwidth is less than M, then the number of PMD threads is increased by one, i.e., the increased number of PMD threads is Q+1. Correspondingly, the number of virtual processor resources used for the PMD threads is also Q+1. Step S302 is repeated using the increased number of PMD threads until the total bandwidth is less than the maximum bandwidth and the total bandwidth no longer increases, or the total bandwidth equals M, thus obtaining Z.
[0094] For example, if the total bandwidth is equal to M, then Q is taken as Z.
[0095] For example, if the total bandwidth is greater than M, then the number of PMD threads is reduced by one, i.e., the reduced number of PMD threads is Q-1. Correspondingly, the number of virtual processor resources used for PMD threads is also Q-1. Step S302 is repeated using the reduced number of PMD threads until the total bandwidth is greater than the maximum bandwidth and the total bandwidth no longer decreases, or the total bandwidth equals M, thus obtaining Z.
[0096] The third scenario: The first parameter of the physical network card includes the rate-limited packet rate of the physical network card. The second parameter includes the total packet rate at which M virtual machines process packets based on Q PMD threads.
[0097] In this scenario, the target number Z of PMD threads is obtained based on the first and second parameters, which may include the following steps:
[0098] S601. Based on the total packet rate and the rate-limited packet rate, obtain the target number Z of PMD threads.
[0099] The method for obtaining the total package rate is described in the aforementioned embodiment and will not be repeated here.
[0100] For example, if the total packet rate is less than P, then the number of PMD threads is increased by one, i.e., the increased number of PMD threads is Q+1. Correspondingly, the number of virtual processor resources used for the PMD threads is also Q+1. The increased number of PMD threads is used to repeat step S302 until the total packet rate is less than the rate-limited packet rate and the total packet rate no longer increases, or the total packet rate is equal to P, thus obtaining Z.
[0101] For example, if the total packet rate is equal to P, then Q is taken as Z.
[0102] For example, if the total packet rate is greater than P, the number of PMD threads is reduced by one, i.e., the reduced number of PMD threads is Q-1. Correspondingly, the number of virtual processor resources used for PMD threads is also Q-1. Step S302 is repeated using the reduced number of PMD threads until the total packet rate is greater than the rate-limited packet rate and the total packet rate no longer decreases, or the total packet rate is equal to P, thus obtaining Z.
[0103] The Z value obtained in the above manner can be used to determine the amount of virtual processor resources allocated to the PMD thread.
[0104] Optionally, after the testing device obtains the Z-value, it outputs the Z-value, and the user can configure the host machine based on the Z-value output by the testing device. The host machine can be configured by the user manually modifying the host machine parameters; this application does not limit the specific configuration method.
[0105] Optionally, after obtaining the Z value through the testing device, the testing device can directly modify the parameters of the host machine and configure the resource allocation method of the host machine.
[0106] In this implementation, after step S303 above, the embodiments of this application may further include the following:
[0107] S304. If the values of Z and Q are different, then based on Z, obtain the mapping relationship between Z PMD threads and the virtual processor resources of the host machine. This mapping relationship is used to configure the number of PMD threads on the host machine.
[0108] On the host machine, the N allocatable virtual processor resources can include X virtual processor resources reserved for virtual machines and Y virtual processor resources reserved for PMD threads, where Y represents the virtual processor resources other than the X virtual processor resources among the N virtual processor resources. In addition to the allocatable virtual processor resources, the host machine may also include non-allocatable virtual processor resources, such as virtual processor resources reserved for the operating system.
[0109] The different values of Z and Q indicate that the resources currently allocated to PMD are unreasonable, resulting in a waste of vCPU resources or low efficiency in the overall processing of packets by virtual machines in the virtual network.
[0110] If the number of virtual processor resources reserved for the virtual machine (X) and the number of virtual processor resources reserved for the PMD thread are fixed, meaning the maximum number of virtual processor resources that the virtual machine can use is X and the maximum number of virtual processor resources that the PMD thread can use is Y, then in this implementation:
[0111] If Z is less than or equal to Y, then Z virtual processor resources are allocated from Y virtual processor resources to Z PMD threads.
[0112] If Z is greater than Y, then allocate Y virtual processor resources to Y PMD threads.
[0113] If the X virtual processor resources reserved for the virtual machine and the Y virtual processor resources reserved for the PMD thread can be dynamically adjusted based on the usage of another part, then in this implementation:
[0114] If Z is less than or equal to Y, then Z virtual processor resources are allocated from Y virtual processor resources to Z PMD threads.
[0115] If Z is greater than Y, and there are no idle virtual processor resources among the X virtual processor resources, then the Y virtual processor resources will be allocated to the Y PMD threads.
[0116] If Z is greater than Y, and there are H idle virtual processor resources out of X virtual processor resources, then the Y virtual processor resources and the H idle virtual processor resources out of X virtual processor resources will be allocated to Z PMD threads. Here, H is an integer less than or equal to the difference between Z and Y.
[0117] It should be noted that although the above example illustrates the dynamic use of virtual processor resources reserved for the virtual machine by the PMD thread, it should be understood that when Z is less than Y, and when the virtual machine's resources are insufficient, it can also dynamically use virtual processor resources reserved for the PMD thread that are currently idle. This will not be elaborated further.
[0118] Optionally, after step S304 above, the method may further include the following steps:
[0119] The system maintains a mapping between Z virtual processor resources allocated to Z PMD threads. This mapping ensures a one-to-one correspondence between each PMD thread and a virtual processor, thus determining the number of PMD threads Z and the range of Z virtual processors bound to each PMD thread. This facilitates the allocation of resources to the host machine, determining the virtual processors bound to each PMD thread and preventing each virtual processor from being used for more than one purpose, which could reduce the overall efficiency of packet processing in the virtual network.
[0120] This application obtains the data transfer rate of the host machine's physical network card and the data transfer rate of each virtual machine, and then sums the data transfer rates of all virtual machines to obtain the total data transfer rate of all virtual machines. By comparing the total data transfer rate with the data transfer rate of the host machine's physical network card, the number of PMD threads can be dynamically planned to rationally allocate vCPU resources, improve PPS (Packet Per Second) and throughput in the virtual network, and avoid waste of vCPU resources or low overall packet processing efficiency of virtual machines in the virtual network.
[0121] Figure 4This is a schematic diagram of a resource allocation device provided in an embodiment of this application. The test device is connected to a host machine, on which M virtual machines are deployed. The host machine has N allocatable virtual processor resources, and Q PMD threads are currently deployed on the host machine. The PMD threads are used to forward packets received by the host machine's physical network card to the corresponding virtual machines for processing. One PMD thread occupies one virtual processor resource. M and Q are both integers greater than or equal to 1, and N is an integer greater than or equal to 2. This device is applied to the test device.
[0122] like Figure 4 As shown, the resource allocation device includes: an acquisition module 11, a testing module 12, and a processing module 13.
[0123] The acquisition module 11 is used to acquire the first parameter of the physical network interface card (NIC), which is related to the maximum transmission rate of the physical NIC. For example, it acquires the bandwidth of the physical NIC; based on the bandwidth of the physical NIC and the minimum packet length, it acquires the rate-limited packet rate of the physical NIC.
[0124] Test module 12 is used to control the virtual test machine to perform packet sending stress tests on the host machine at a first rate. For example, test module 12 is specifically used to deploy the virtual test machine. It controls the virtual test machine to run a server process and controls the virtual machines on the host machine to run packet forwarding processes, obtaining the packet rate and bandwidth values of each virtual machine; it adds the packet rates of each virtual machine to obtain the total packet rate; it adds the bandwidth values of each virtual machine to obtain the total bandwidth. The packet forwarding process is used to swap the sender's address information and the receiver's address information in the test packet and return it to the virtual test machine. The server process is used to send test packets to the host machine at the first rate.
[0125] The acquisition module 11 is also used to acquire the second parameters of the host machine after the test module 12 controls the virtual test machine to perform a packet sending stress test on the host machine at a first rate. The second parameter is related to the total maximum transmission rate of the M virtual machines processing packets based on Q PMD threads; the first rate is greater than or equal to the maximum transmission rate of the physical network card.
[0126] The processing module 13 is used to obtain the target number Z of PMD threads based on the first parameter and the second parameter, where Z is less than N, and Z is used to determine the number of virtual processor resources allocated to the PMD threads.
[0127] One possible implementation includes the following parameters: the maximum bandwidth and rate-limited packet rate of the physical network card, and the following parameters: the total bandwidth and total packet rate of M virtual machines processing packets based on Q PMD threads.
[0128] In this implementation, the processing module 13 is specifically used to obtain the first initial target number Z1 of PMD threads based on the total packet rate and the rate-limited packet rate; to obtain the second initial target number Z2 of PMD threads based on the total bandwidth and the maximum bandwidth; and to obtain Z based on Z1 and Z2.
[0129] For example, processing module 13 is specifically used to increase the number of PMD threads when the total packet rate is less than the rate-limited packet rate, until the total packet rate is less than the rate-limited packet rate and the total packet rate no longer increases, or the total packet rate is equal to the rate-limited packet rate, to obtain Z1.
[0130] For example, processing module 13 is specifically used to increase the number of PMD threads when the total bandwidth is less than the maximum bandwidth, until the total bandwidth is less than the maximum bandwidth and the total bandwidth no longer increases, or the total bandwidth is equal to the maximum bandwidth, thus obtaining Z2.
[0131] For example, processing module 13 is specifically used to take the maximum value of Z1 and Z2 as Z.
[0132] Optionally, the acquisition module 11 is also used to acquire the mapping relationship between Z PMD threads and the virtual processor resources of the host machine based on Z when the values of Z and Q are different. This mapping relationship is used to configure the number of PMD threads of the host machine.
[0133] For example, processing module 13 is specifically used to allocate Z virtual processor resources from Y virtual processor resources to Z PMD threads when Z is less than or equal to Y. When Z is greater than Y, and there are H idle virtual processor resources among X virtual processor resources, the Y virtual processor resources and the H idle virtual processor resources are allocated to the Z PMD threads.
[0134] Where Y represents the virtual processor resources other than X virtual processor resources out of N virtual processor resources. H is an integer less than or equal to the difference between Z and Y. The mapping relationship between Z and the virtual processor resources allocated to Z PMD threads is stored.
[0135] This application provides a resource allocation device that can perform the methods described in the above embodiments. Figure 3 The resource allocation method shown is similar in principle and technical effect, and will not be described in detail here. The resource allocation device can be, for example, the aforementioned testing equipment, or a chip within the testing equipment, such as a processor.
[0136] Figure 5 This is a schematic diagram of a test device structure provided in this application. The test device can be, for example, the aforementioned test device for determining host machine vCPU resource allocation. Figure 5As shown, the test device 500 may include at least one processor 501, a memory 502, and a communication interface 503.
[0137] The memory 502 is used to store programs. Specifically, the program may include program code, which includes computer operation instructions.
[0138] The memory 502 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.
[0139] The processor 501 is used to execute computer execution instructions stored in the memory 502 to implement the resource allocation method described in the foregoing method embodiments. The processor 501 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.
[0140] The processor 501 can communicate and interact with external devices through the communication interface 503. The external device could be, for example, a host machine awaiting vCPU resource allocation. In practice, if the communication interface 503, memory 502, and processor 501 are implemented independently, they can be interconnected via a bus to complete communication. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc., but this does not imply that there is only one bus or one type of bus.
[0141] Optionally, in a specific implementation, if the communication interface 503, memory 502, and processor 501 are integrated on a single chip, then the communication interface 503, memory 502, and processor 501 can communicate through an internal interface.
[0142] This application also provides a computer-readable storage medium, which may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk. Specifically, the computer-readable storage medium stores program instructions, which are used in the methods described in the above embodiments.
[0143] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A resource allocation method, characterized in that, M virtual machines are deployed on a host machine, which has N allocatable virtual processor resources. Q PMD threads are currently deployed on the host machine. Each PMD thread forwards packets received by the host machine's physical network interface card to the corresponding virtual machine for processing. Each PMD thread occupies one virtual processor resource. M and Q are both integers greater than or equal to 1, and N is an integer greater than or equal to 2. The method includes: Obtain the first parameter of the physical network interface card (NIC), which is related to the maximum transmission rate of the physical NIC; the first parameter includes: the maximum bandwidth and the rate-limiting packet rate of the physical NIC. The virtual test machine is controlled to perform packet sending stress test on the host machine at a first rate, and a second parameter of the host machine is obtained. The second parameter is related to the total maximum transmission rate of the M virtual machines processing packets based on the Q PMD threads. The first rate is greater than or equal to the maximum transmission rate of the physical network card. The second parameter includes the total bandwidth and total packet rate of the M virtual machines processing packets based on the Q PMD threads. If the total packet rate is less than the rate-limited packet rate, the number of PMD threads is increased until the total packet rate is less than the rate-limited packet rate and the total packet rate no longer increases, or the total packet rate is equal to the rate-limited packet rate, thus obtaining the first initial target number Z1 of the PMD threads; If the total bandwidth is less than the maximum bandwidth, the number of PMD threads is increased until the total bandwidth is less than the maximum bandwidth and the total bandwidth no longer increases, or the total bandwidth is equal to the maximum bandwidth, thus obtaining the second initial target number Z2 of the PMD threads; The maximum value between Z1 and Z2 is taken as the target number Z of the PMD threads; Z is less than N, and Z is used to determine the number of virtual processor resources allocated to the PMD threads.
2. The method according to claim 1, characterized in that, The virtual test machine controls the host machine to perform packet sending stress testing at a first rate, and obtains a second parameter of the host machine, including: Deploy a virtual test machine; The virtual test machine is controlled to run a server process and the virtual machine on the host machine is controlled to run a packet forwarding process. The server process is used to send test packets to the host machine at a first rate. The packet forwarding process is used to swap the address information of the sender and the address information of the receiver in the test packet and then return it to the virtual test machine. Obtain the packet rate and bandwidth values for each virtual machine; The total packet rate is obtained by summing the packet rates of each virtual machine. The total bandwidth is obtained by adding up the bandwidth values of each virtual machine.
3. The method according to claim 1, characterized in that, The first parameter of obtaining the physical network card includes: Obtain the maximum bandwidth of the physical network interface card; The rate-limiting packet rate of the physical network interface card (NIC) is obtained based on its maximum bandwidth and minimum packet length.
4. The method according to any one of claims 1-3, characterized in that, The method further includes: If the values of Z and Q are different, then based on Z, the mapping relationship between Z PMD threads and the virtual processor resources of the host machine is obtained, and the mapping relationship is used to configure the number of PMD threads of the host machine.
5. The method according to claim 4, characterized in that, The N allocable virtual processor resources include X virtual processor resources reserved for virtual machines. Obtaining the mapping relationship between the Z PMD threads and the virtual processor resources of the host machine based on Z includes: If Z is less than or equal to Y, then Z virtual processor resources are allocated from the Y virtual processor resources to Z PMD threads to obtain the mapping relationship between the Z PMD threads and the virtual processor resources of the host machine; Y is the virtual processor resources other than the X virtual processor resources among the N virtual processor resources; If Z is greater than Y, and there are H idle virtual processor resources among the X virtual processor resources, then the Y virtual processor resources and the H idle virtual processor resources are allocated to Z PMD threads to obtain the mapping relationship between the Z PMD threads and the virtual processor resources of the host machine, wherein H is an integer less than or equal to the difference between Z and Y.
6. A resource allocation device, characterized in that, The test equipment is connected to a host machine, on which M virtual machines are deployed. The host machine has N allocatable virtual processor resources, and Q PMD threads are currently deployed on the host machine. Each PMD thread forwards packets received by the host machine's physical network interface card to the corresponding virtual machine for processing. Each PMD thread occupies one virtual processor resource. M and Q are both integers greater than or equal to 1, and N is an integer greater than or equal to 2. The resource allocation device is applied to the test equipment and includes: The acquisition module is used to acquire a first parameter of the physical network interface card (NIC), which is related to the maximum transmission rate of the NIC; the first parameter includes: the maximum bandwidth and rate-limited packet rate of the NIC; and to acquire a second parameter of the host machine, which is related to the total maximum transmission rate of the M virtual machines processing packets based on the Q PMD threads; the first rate is greater than or equal to the maximum transmission rate of the NIC; the second parameter includes: the total bandwidth and total packet rate of the M virtual machines processing packets based on the Q PMD threads. The testing module is used to control the virtual testing machine to perform packet sending stress tests on the host machine at a first rate; The processing module is configured to: if the total packet rate is less than the rate-limited packet rate, increase the number of PMD threads until the total packet rate is less than the rate-limited packet rate and the total packet rate no longer increases, or the total packet rate is equal to the rate-limited packet rate, to obtain a first initial target number Z1 of the PMD threads; if the total bandwidth is less than the maximum bandwidth, increase the number of PMD threads until the total bandwidth is less than the maximum bandwidth and the total bandwidth no longer increases, or the total bandwidth is equal to the maximum bandwidth, to obtain a second initial target number Z2 of the PMD threads; use the maximum value between Z1 and Z2 as the target number Z of the PMD threads; Z is less than N, and Z is used to determine the amount of virtual processor resources allocated to the PMD threads.
7. A testing device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the resource allocation method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, include: The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the resource allocation method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
NUMA node binding method and device of virtual machine, equipment and storage medium
CN112181595A
Cloud computing network configuration method, cloud computing network system and a storage medium
CN112398687A
