Message sending method, device and readable storage medium
By reducing competition among PMD threads, the virtual switch improves forwarding performance when the security group is started, solving the problem of ovs-dpdk performance degradation, and enhancing the security and performance of virtual machine instances.
Patent Information
- Application Number
- CN202310064090.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-13
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2043-01-13
Smart Images

Figure CN116095028B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the technical field of network virtualization, and in particular to a message sending method, device and readable storage medium. Background Art
[0002] In cloud computing networks, Open Virtual Switch (OVS) is usually responsible for data forwarding. Common OVS include kernel-mode OVS and OVS based on Data Plane Development Kit (DPDK). Among them, OVS based on DPDK is also called ovs-dpdk (user-mode virtual switch).
[0003] Kernel-mode OVS usually works in kernel mode, which severely limits the forwarding performance of OVS. However, ovs-dpdk can bypass the kernel when forwarding data, thus improving the forwarding performance. In addition, in cloud virtualization scenarios, security group products need to be provided for each virtual machine. A security group is a virtual firewall that determines which packets can access the virtual machine based on user-configured rules, providing basic protection capabilities for the virtual machine, thereby improving the security of the virtual machine instance.
[0004] However, when the security group is enabled, the forwarding performance of ovs-dpdk is severely degraded. Summary of the invention
[0005] The embodiments of the present application provide a message sending method, device and readable storage medium, which improve the processing performance of PMD threads by reducing the competition between PMD threads, thereby achieving the purpose of improving the forwarding performance of the virtual switch when the security group is started.
[0006] In a first aspect, an embodiment of the present application provides a message sending method, which is applied to a virtual switch, and the method includes:
[0007] Receiving a message to be forwarded by using a first thread, where the first thread is any thread in a thread set, and the threads in the thread set correspond one-to-one to the physical network card queues of the physical interface;
[0008] Determine a structure according to the first thread and the destination virtual interface of the message to be forwarded, wherein the structure is used to indicate the number of queues and queue numbers of the virtual machine interface queues allocated to the first thread by the destination virtual interface;
[0009] Determining a target queue from a plurality of virtual machine interface queues of the destination virtual interface according to the structure, the plurality of virtual machine interface queues being assigned to threads in the thread set;
[0010] Send the message to be forwarded to the target queue.
[0011] In a second aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the electronic device implements the method described in the first aspect or various possible implementation methods of the first aspect.
[0012] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed by a processor, they are used to implement the method described in the first aspect or various possible implementation methods of the first aspect.
[0013] The message sending method, device and readable storage medium provided by the embodiment of the present application, after the virtual switch receives the message to be forwarded by the first thread, the structure is determined according to the first thread and the destination virtual interface of the message to be forwarded, and the structure indicates the number of queues and queue numbers of the virtual machine interface queues assigned to the first thread by the destination virtual interface. Afterwards, the virtual switch determines the target queue from the multiple virtual machine interface queues of the destination virtual interface according to the structure, and sends the message to be forwarded to the target queue. With this solution, since the multiple virtual machine interface queues of the destination virtual interface are assigned to each thread in the thread set, each virtual machine interface queue will not be assigned to two threads at the same time, and different threads will not compete for the queue lock of the same virtual machine interface queue. The processing performance of the thread is improved by reducing the competition between threads, and the purpose of improving the forwarding performance of the virtual switch when the security group is started is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0015] Figure 1 It is a schematic diagram of the network architecture of the message sending method provided in an embodiment of the present application;
[0016] Figure 2 is a flowchart of a message sending method provided in an embodiment of the present application;
[0017] Figure 3 It is a topological structure diagram of a virtual switch in the message sending method provided by the implementation of the present application;
[0018] Figure 4It is a flowchart of initializing the topology of a virtual switch in the message sending method provided by the example of this application;
[0019] Figure 5 It is a flowchart of creating a virtual machine in the message sending method provided in an embodiment of the present application;
[0020] Figure 6 is another flow chart of the message sending method provided in an embodiment of the present application;
[0021] Figure 7 A schematic diagram of a message sending device provided in an embodiment of the present application;
[0022] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] OVS is a multi-layer virtual switch. It is widely used in virtual network forwarding due to its powerful flow table capabilities. OVS is an open source software switch. Traditional OVS mainly includes kernel space and user space. The message forwarding path is located in the kernel space. Message forwarding often requires switching between kernel space and user space to complete, resulting in low message forwarding efficiency. To solve this problem, the industry has developed ovs-dpdk. The message forwarding path of ovs-dpdk is located in the user space, and no longer relies on the kernel space. Message forwarding can be completed in the user space, which greatly improves the forwarding performance.
[0024] In addition, in the cloud virtualization scenario, a security group product is provided for each virtual machine. A security group is a virtual firewall that determines which packets can access the virtual machine based on user-configured rules, providing basic protection capabilities for the virtual machine, thereby improving the security of the virtual machine instance.
[0025] When the security group on ovs-dpdk is enabled, the processing and forwarding performance of ovs-dpdk is severely reduced, even to 49%, compared with the case where the security group is not enabled. Therefore, how to improve the performance of ovs-dpdk when the security group is enabled is considered an urgent problem to be solved.
[0026] Figure 1 This is a schematic diagram of the network architecture of the message sending method provided in the embodiment of the present application. Figure 1The network architecture includes a virtual switch 11, which is, for example, a user state virtual switch (ovs-dpdk), a virtual machine (VM) 12, and an external device 13. Each virtual machine VM12 has at least one virtual network card 121, each external device 13 has at least one physical network card 131, the virtual switch 11 provides a physical interface 111 and a virtual interface 112, the virtual network card 121 is connected to the virtual interface 112, and the physical network card 131 is connected to the physical interface 111.
[0027] The virtual switch 11 is used to provide services such as data forwarding for the virtual network card 121 and the physical network card 131, so that a communication connection is established between multiple VMs 12 in the virtual network, or between VMs 12 and external devices 13, to achieve data transmission. The virtual switch 11 has a security group function, that is, a virtual firewall function. The virtual switch 11 performs actions such as release, filtering, and blocking on the received messages to be forwarded according to the virtual firewall.
[0028] VM12 is a computer simulated on a physical computer by virtual machine software. VM12 can work like a real computer. An operating system and application programs are installed on VM12, and VM12 can also access network resources. For applications running in VM12, VM12 is like working in a real computer. Different VM12s carry different services.
[0029] Please refer to Figure 1 A VM12 has one or more virtual network cards 121, and each virtual network card 121 corresponds to a virtual interface 112. When a VM12 is created, one or more virtual interfaces 112 (also called virtual machine interfaces) are created accordingly, and a virtual interface 112 has one or more virtual machine interface queues. Virtual interface 112 refers to the network interface of VM12 on the host machine, which can be represented by the dpdkvhostuserclient interface.
[0030] An external device 13 has one or more physical network cards 131, and each physical network card 131 corresponds to a physical interface 111. A physical interface 111 has one or more physical network card queues. The physical interface 111 is a physical port of a physical machine, and is called a dpdk0 port after being taken over by the virtual switch 11.
[0031] The virtual switch 11 uses a polling mode driver (PMD) thread to process the sending and receiving of messages. After the virtual switch 11 is started, N threads are created according to the configuration. The number of threads N is usually consistent with the number of physical network card queues of the physical interface 111.
[0032] After each VM12 is created, assuming that the VM12 has a virtual interface 112, and the virtual interface 112 has M virtual machine interface queues, the virtual switch 11 allocates the M virtual machine interface queues to N threads. When M / N is divisible, the number of virtual machine interface queues allocated to each thread is the same, for example, M=16, N=4, then each thread is allocated 4 virtual machine interface queues on average. When M / N is not divisible, for example, M=18, N=4, then the number of virtual machine interface queues allocated to each of the two threads is 4, and the number of virtual machine interface queues allocated to each of the other two threads is 5.
[0033] When VM 12 has two or more virtual interfaces 112 , the virtual machine interface queue of each virtual interface 112 will be distributed to the N threads as evenly as possible.
[0034] In an embodiment of the present application, after a thread of the virtual switch 11, hereinafter referred to as the first thread, receives a message to be forwarded from the physical interface 111, for example, after receiving a message to be forwarded from a physical network card queue under the physical interface 111, the destination virtual interface is determined according to the flow table, etc., and then the virtual machine interface queue assigned to the first thread is determined from the multiple virtual machine interface queues of the destination virtual interface, and the target queue is determined from the multiple virtual machine interface queues of the first thread, and then the message to be forwarded is sent to the target queue.
[0035] Figure 2 It is a flow chart of the message sending method provided by the embodiment of the present application. The execution subject of this embodiment is a virtual switch, such as a user-mode virtual switch ovs-dpdk. This implementation includes:
[0036] 201. Receive a message to be forwarded by using a first thread, where the first thread is any thread in a thread set, and the threads in the thread set correspond one-to-one to the physical network card queues of the physical interface.
[0037] In the embodiment of the present application, N threads are created when the virtual switch is started, and the thread set includes the N threads. The number of threads N in the thread set is usually consistent with the number of physical network card queues, that is, the threads in the thread set correspond one-to-one to the physical network card queues of the physical interface.
[0038] Although the one-to-one correspondence between threads and physical network card queues is used as an example for explanation, that is, the number of physical network card queues of the physical interface L = the number of threads N. However, the embodiment of the present application is not limited, and in other feasible implementations, the number of physical network card queues of the physical interface L can also be greater than the number of threads N. For example, L = 24, N = 4, then the virtual switch evenly distributes 24 physical network card queues to 4 threads.
[0039] In this step, the first thread is any thread in the thread set. The physical network card queue corresponding to the first thread is called the physical network card queue assigned to the first thread by the physical network card. The physical network card queue assigned to the first thread is, for example, the one-to-one corresponding physical network card queue mentioned above, or four physical network card queues.
[0040] When the message to be forwarded comes from an external device, the virtual switch uses the first thread to receive the message to be forwarded, which means that the first thread receives the message to be forwarded from the physical network card queue allocated to the first thread.
[0041] When the message to be forwarded comes from the virtual machine, the virtual switch uses the first thread to receive the message to be forwarded, which means that the first thread receives the message to be forwarded from the virtual machine.
[0042] 202. Determine a structure according to the first thread and the destination virtual interface of the message to be forwarded, where the structure is used to indicate the number of queues and queue numbers of the virtual machine interface queues allocated to the first thread by the destination virtual interface.
[0043] In the embodiment of the present application, each time a virtual machine is created, multiple virtual machine queues of each virtual interface of the virtual machine are allocated to N threads. For the virtual machine, each thread has a structure that stores the number of queues and queue numbers of the virtual machine interface queues allocated to the thread.
[0044] The virtual switch receives the message to be forwarded by using the first thread, and determines the destination virtual interface according to the flow table, that is, determines which virtual machine the message to be forwarded belongs to. Then, the structure is determined according to the destination forwarding interface and the first thread. In addition, the virtual switch also performs security processing on the message to be forwarded according to the security group.
[0045] 203. Determine a target queue from a plurality of virtual machine interface queues of the destination virtual interface according to the structure, wherein the plurality of virtual machine interface queues are allocated to threads in the thread set.
[0046] In the embodiment of the present application, multiple virtual machine interface queues of a virtual machine interface of a virtual machine are assigned to threads in the thread set, and a thread is bound to these virtual machine interface queues. This thread will only process the messages of these virtual machine interface queues and will not seize the queue locks of the virtual machine interface queues of other threads.
[0047] After determining the structure, the virtual switch determines the virtual machine interface queue assigned to the first thread from the multiple virtual machine interface queues of the destination virtual interface. For example, when creating a virtual machine, a virtual interface is created, the virtual interface has 16 virtual machine interface queues, there are 4 threads in the thread set, and each thread is assigned 4 virtual machine interface queues. After the virtual switch determines the structure of the first thread, it determines the 4 virtual machine interface queues assigned to the first thread from the 16 virtual machine interface queues, and then determines the target queue from the 4 virtual machine interface queues.
[0048] 204. Send the message to be forwarded to the target queue.
[0049] The virtual switch uses the first thread to send the message to be forwarded to the target queue.
[0050] The message sending method provided in the embodiment of the present application is that after the virtual switch receives the message to be forwarded by the first thread, it determines a structure according to the first thread and the destination virtual interface of the message to be forwarded, and the structure indicates the number of queues and queue numbers of the virtual machine interface queues assigned to the first thread by the destination virtual interface. Afterwards, the virtual switch determines the target queue from the multiple virtual machine interface queues of the destination virtual interface according to the structure, and sends the message to be forwarded to the target queue. With this solution, since the multiple virtual machine interface queues of the destination virtual interface are assigned to each thread in the thread set, each virtual machine interface queue will not be assigned to two threads at the same time, and different threads will not compete for the queue lock of the same virtual machine interface queue, thereby improving the processing performance of the thread by reducing the competition between threads, and achieving the purpose of improving the forwarding performance of the virtual switch when the security group is started.
[0051] Optionally, in the above embodiment, when the virtual switch sends the message to be forwarded to the target queue, first, it is determined whether the sending condition is met, and when the sending condition is met, the message flow containing the message to be forwarded is sent to the target queue in batches. When the sending condition is not met, it continues to wait until the sending condition is met. The sending condition includes at least one of the following conditions: the number of the message to be forwarded exceeds a preset number, and the time length after receiving the message to be forwarded is greater than a preset delay.
[0052] Exemplarily, the virtual switch receives the message to be forwarded through the first thread, and after determining the target queue from multiple virtual machine interface queues of the destination virtual interface, sends the message to be forwarded to the target queue only when the batch sending condition is met.
[0053] For example, the virtual switch collects the to-be-forwarded messages of the target queue of the destination virtual interface. When the number of collected messages reaches a preset number, all the to-be-forwarded messages of the target queue of the destination virtual interface are sent in batches. The preset number is, for example, 32, 64, etc., which is not limited in the embodiment of the present application.
[0054] For another example, after the virtual switch receives the message to be forwarded through the first thread and determines the target queue from the multiple virtual machine interface queues of the destination virtual interface, it monitors the cumulative time after receiving the message to be forwarded. When the time is greater than the preset time, all messages to be forwarded with a cumulative time greater than the preset time are sent to the target queue. If the cumulative time of a message to be forwarded is less than or equal to the preset time, continue waiting.
[0055] By adopting this solution, the packets to be forwarded are sent in batches, thereby improving the forwarding performance of the virtual switch.
[0056] Optionally, in the above embodiment, before the virtual switch uses the first thread to receive the message to be forwarded, it also creates each thread in the thread set, a first bridge and a second bridge, the first bridge is used to set the virtual interface of the virtual machine, and the second bridge is used to set the physical interface of the physical network card.
[0057] The message sending method of the embodiment of the present application is implemented by, for example, a virtual switch in an OpenStack cluster, which is also called an edge cloud host platform. In the OpenStack cluster, the topology of the virtual switch is as follows: Figure 3 shown.
[0058] Figure 3 This is a topological diagram of the virtual switch in the message sending method provided by the present application. Figure 3 , the virtual switch includes a first bridge and a second bridge, as shown by the dotted line in the figure. The first bridge is also called a br-int bridge, and the second bridge is also called a br0-ovs bridge. The virtual interface 112 of VM12 is directly hung under the br-int bridge, and the physical interface 111 of the external device 13 is taken over by the virtual switch and directly hung under the br0-ovs bridge. The first bridge and the second bridge are connected through the patech interface.
[0059] Please refer to Figure 3 After the virtual switch is started, the first bridge and the second bridge, as well as N threads, such as N PMD threads, are created according to the configuration file. The configuration file is used to indicate N, which CPUs the virtual switch uses, which network interfaces and bridges are created, etc. The number of threads N is usually consistent with the number of physical network card queues of the physical interface 111.
[0060] By adopting this solution, a first network bridge for providing a virtual interface and a second network bridge for providing a physical interface are created, thereby realizing a topological structure of a virtual switch, which is simple and fast.
[0061] Optionally, in the above embodiment, after the virtual switch creates each thread in the thread set, the first bridge and the second bridge, it also allocates exclusive resources to the thread set, and then restarts the physical machine where the virtual switch is located to make the exclusive resources effective.
[0062] For example, in order to prevent the system process from preempting the PMD thread, before starting the virtual switch, it is necessary to set the isolcpus parameter for the Linux kernel, that is, configure the isolcpus parameter in the kernel startup item, so as to configure exclusive CPU and other resources for all threads in the thread set, that is, isolate the resources configured for each thread. After that, restart the physical machine where the virtual switch is located, so that the exclusive resources allocated to each thread take effect.
[0063] Figure 4 This is a flowchart of initializing the topology of a virtual switch in the message sending method provided by the example of this application. This embodiment includes:
[0064] 401. Allocate exclusive resources to the thread.
[0065] 402. Restart the physical machine where the virtual switch is located to make the exclusive resources effective.
[0066] 403. Start the virtual switch, initialize the first bridge and the second bridge, and create N threads.
[0067] By adopting this solution, exclusive resources are allocated to the thread set to prevent system processes from preempting thread resources, thereby preventing threads from being unable to receive and forward messages due to lack of resources, thereby improving the reliability of forwarding messages.
[0068] Optionally, in the above embodiment, after initializing the topology of the virtual switch, a virtual machine can be created. Figure 5 , Figure 5 This is a flowchart of creating a virtual machine in the message sending method provided in an embodiment of the present application. This embodiment includes:
[0069] 501. Create a virtual machine.
[0070] In an embodiment of the present application, each time a virtual machine is created, the virtual switch creates at least one virtual interface for the virtual machine, and the at least one virtual interface includes the above-mentioned destination virtual interface. The specifications of the virtual machine determine the number of virtual interface queues. The specifications of the virtual machine refer to the number of multiple CPUs used by the virtual machine. For example, if a virtual machine requires 4 CPUs, a virtual interface of this virtual machine has 4 virtual machine interface queues. If the virtual machine has two virtual interfaces, each virtual interface has 4 virtual machine interface queues. The total number of virtual machine interface queues of a virtual machine is: the product of the number of virtual interfaces of the virtual machine and the number of CPUs of the virtual machine.
[0071] 502. Allocate a virtual machine interface queue to each thread.
[0072] For each virtual machine, such as the destination virtual machine, any virtual interface of the destination virtual machine is called the destination virtual interface, and the virtual switch allocates multiple virtual machine interface queues of the destination virtual interface to the threads in the thread set. Assuming that after a virtual machine is created, the number of virtual machine interface queues corresponding to a virtual interface is M, and the number of threads in the thread set is N. If the result of M / N is an integer, each thread is allocated M / N virtual machine interface queues. If M / N cannot be divided evenly, some threads are allocated (M / N)+1 virtual machine interface queues, and the remaining threads are allocated M / N virtual machine interface queues. Among them, M / N refers to the value after M / N is rounded down. For example, M=19, N=4, then the number of virtual machine interface queues allocated to one thread among the four threads is 4, and the number of virtual machine interface queues allocated to each of the remaining three threads is 5. The virtual switch can randomly allocate 4 virtual machine interface queues to any one of the four threads, and the remaining threads are allocated 5 virtual machine interface queues.
[0073] 503. Initialize the structure.
[0074] The virtual switch initializes the structure of the first thread according to the number of queues and queue numbers of the virtual machine interface queues allocated to the first thread.
[0075] Exemplarily, for each thread, such as the first thread mentioned above, the virtual switch saves the correspondence between the identifier of the first thread, the number of queues of the virtual machine interface queues allocated to the first thread, and the queue number, thereby obtaining the structure of the first thread.
[0076] By adopting this solution, a structure of each thread is generated, so that after the virtual switch receives the message to be forwarded from the destination virtual interface, it can quickly determine the target queue according to the structure diagram, thereby improving the speed of forwarding the message.
[0077] Figure 6is another flow chart of the message sending method provided in an embodiment of the present application. This example includes:
[0078] 601. Create a thread.
[0079] Exemplarily, after the virtual switch is started, a first bridge, a second bridge, and N PMD threads are created.
[0080] 602. Receive a message to be forwarded using a first thread.
[0081] The first thread is any one of the multiple threads created by starting the virtual switch.
[0082] 603. Process the message to be forwarded.
[0083] Exemplarily, the virtual switch is a virtual switch with a security group function. The virtual switch processes the link tracking according to the flow table, determines the destination virtual interface, and determines whether to release the message to be forwarded according to the security group. If the message to be forwarded is released, step 604 is executed; if the message to be forwarded is not released, the message to be forwarded is discarded.
[0084] 604. Determine the target queue according to the structure of the first thread, and forward the message to be forwarded to the target queue, and then return to step 602.
[0085] Exemplarily, the virtual switch determines the index of the target queue according to the hash value of the message to be forwarded. Then, the target queue is determined from the queue set according to the index. The index is used to indicate the position of the target queue in the queue set, and the virtual machine interface queue in the queue set is the virtual machine interface queue assigned to the first thread by the destination virtual interface.
[0086] The structure is also called the XPS structure, which contains a two-dimensional array:
[0087] The first dimension represents the thread number (pmd_index) of the first thread;
[0088] The second dimension indicates the number of the destination virtual interface (interface_index);
[0089]
[0090] After the virtual switch receives the message to be forwarded by the first thread, it processes the message to be forwarded according to the security group, etc. If the message to be forwarded is released, the subscript of the target queue is obtained according to the hash value of the message to be forwarded. The hash value can be calculated according to the five-tuple of the message to be forwarded, etc. The subscript of the target queue is as follows: packet_hash%(pmd_interface_xps->queue_num).
[0091] After that, the virtual switch obtains the target queue number in the queue array according to the index. Among them, the queue array stores the queue number of the virtual machine interface queue assigned to this thread by the destination virtual interface. The queue number is as follows: pmd_interface_xps->queue[packet_hash%(pmd_interface_xps->queue_num)].
[0092] For example, a virtual machine interface of a virtual machine has 16 virtual machine interface queues, and the queue numbers are 1, 2, ..., 16. Among them, the virtual machine interface queues with queue numbers 1, 4, 9, and 13 are assigned to the first thread. The subscripts of the four elements in the queue array of the first thread are 0, 1, 2, and 3, corresponding to 1, 4, 9, and 13, respectively. The virtual switch receives the message to be forwarded using the first thread, and determines that the subscript of the target queue is 3 according to the hash value, and then obtains the target queue number 9 from the queue array according to the subscript 3. Therefore, the virtual switch sends the message to be forwarded to the virtual machine interface queue numbered 9 of the destination virtual interface.
[0093] With this solution, the virtual switch determines the index of the target queue according to the hash value of the message to be forwarded, and then determines the target queue, ensuring that a virtual machine interface queue of the destination virtual interface will not be allocated to two threads, avoiding the disadvantage of multiple threads preempting the queue lock of the same virtual machine interface queue.
[0094] Optionally, in the above embodiment, when the update condition is met, the virtual switch updates the structure. The update condition includes at least one of the following conditions: the number of threads in the thread set changes, the number of virtual machine interface queues of the destination virtual interface changes, and the virtual machine corresponding to the destination virtual interface is added or destroyed.
[0095] Exemplarily, when the number of threads in the thread set changes, the number of virtual machine interface queues of the virtual interface is adjusted, or a virtual machine is added or destroyed, it is necessary to reallocate the virtual machine interface queue to each thread, and then update the structure of each thread. When the virtual machine is destroyed, the structure of the virtual interface of the virtual machine is destroyed. Each time the virtual switch receives a message to be forwarded using the first thread, it determines the target queue according to the latest structure, thereby achieving the purpose of accurately determining the target queue, and then achieving the purpose of accurately forwarding the message to be forwarded.
[0096] Optionally, in the above embodiment, the virtual switch further determines the flow of each virtual machine interface queue in the multiple virtual machine interface queues of the destination virtual interface, and then determines whether the virtual machine interface queues are balanced according to the flow of each virtual machine interface queue.
[0097] Exemplarily, in order to cooperate with the XPS sending mode, the virtual switch also counts the traffic of each virtual machine interface queue, so as to facilitate the investigation of whether the virtual machine interface queues are balanced. If the traffic of a virtual machine interface queue is large and exceeds the preset traffic, the traffic of the virtual machine interface queue is diverted. For example, from the virtual machine interface queues assigned to the thread by the destination virtual interface, the virtual machine interface queue with the largest traffic and the virtual machine interface queue with the smallest traffic are determined, and part of the traffic of the virtual machine interface queue with large traffic is allocated to the virtual machine interface queue with small traffic.
[0098] This solution counts the traffic of each virtual machine interface queue to check whether the queues of each virtual machine interface are balanced, avoids excessive traffic in a certain virtual machine interface queue causing the virtual machine to crash, and improves network reliability.
[0099] Optionally, in the above embodiment, the virtual switch also determines the number of times that each thread in the thread set fails to obtain the queue lock, and determines whether there is a virtual machine interface queue that is simultaneously assigned to at least two threads in the multiple virtual machine interface queues of the destination virtual interface based on the number of times that each thread fails to obtain the queue lock.
[0100] Exemplarily, in an embodiment of the present application, multiple virtual machine interface queues of the destination virtual interface are assigned to threads in the thread set. Therefore, a virtual machine interface queue will only be assigned to one thread and will not be assigned to two or more threads at the same time.
[0101] If the message sending method provided in the embodiment of the present application is not adopted, it is very likely that a virtual machine interface queue is simultaneously assigned to two or more threads using the traditional method. For example, a virtual machine interface queue is simultaneously assigned to two threads, namely the first thread and the second thread. Since a thread can send a message to the virtual machine interface queue only if it seizes the queue lock of the virtual machine interface queue. Therefore, if any one of the first thread and the second thread fails to seize the queue lock of the virtual machine interface queue, it means that the virtual switch does not use the message sending method provided in the present application to send the message. Therefore, the virtual switch believes that the traditional method is currently used to send the message, and the virtual switch switches the message sending method from the traditional method to the message sending method provided in the embodiment of the present application.
[0102] This solution can be used to count the number of times each thread fails to obtain the queue lock, making it easier to check whether there is competition for the queue lock between threads, thereby improving the reliability of message forwarding.
[0103] Non Uniform Memory Access Architecture (NUMA) is a physical host system architecture that can effectively expand and build large systems. Using NUMA technology, dozens of CPUs (or even hundreds of CPUs) can be combined in one server. Assume that there are two NUMA domains in the embodiment of the present application, namely NUMA0 and NUMA1, and the virtual switch uses a total of 8 CPUs, which include 6 CPUs on NUMA0 and 2 CPUs on NUMA1. When the message method described in the embodiment of the present application is adopted, assuming that 8 PMD threads are created, when the security group is turned on, for the scenario of 60,000 concurrent connections + 64 bytes + HTTP protocol messages, if the traditional message sending method is used, the forwarding performance is 133WPPS. If the message sending method provided in the embodiment of the present application is adopted, the forwarding performance is 161WPPS, which is an increase of 21%.
[0104] The following are device embodiments of the present application, which can be used to execute the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
[0105] Figure 7 A schematic diagram of a message sending device provided in an embodiment of the present application. The message sending device 700 comprises: a receiving module 71 , a determining module 72 , a processing module 73 and a sending module 74 .
[0106] A receiving module 71, configured to receive a message to be forwarded by using a first thread, wherein the first thread is any thread in a thread set, and the threads in the thread set correspond one-to-one to the physical network card queues of the physical interface;
[0107] A determination module 72, configured to determine a structure according to the first thread and the destination virtual interface of the message to be forwarded, wherein the structure is used to indicate the number and queue number of the virtual machine interface queues of the destination virtual interface allocated to the first thread;
[0108] A processing module 73, configured to determine a target queue from a plurality of virtual machine interface queues of the destination virtual interface according to the structure, wherein the plurality of virtual machine interface queues are assigned to threads in the thread set;
[0109] The sending module 74 is used to send the message to be forwarded to the target queue.
[0110] In a feasible implementation, the processing module 73 is used to determine the subscript of the target queue according to the hash value of the message to be forwarded, and the subscript is used to indicate the position of the target queue in the queue set, and the queue in the queue set is the virtual machine interface queue assigned to the first thread by the destination virtual interface; the target queue is determined from the queue set according to the subscript.
[0111] In a feasible implementation, the processing module 73 is further used to determine whether a sending condition is met, and the sending condition includes at least one of the following conditions: the number of the to-be-forwarded messages exceeds a preset number, and the time after receiving the to-be-forwarded messages is greater than a preset delay;
[0112] The sending module 74 is used to send the message flow containing the to-be-forwarded messages in batches to the target queue when the sending condition is met.
[0113] In a feasible implementation method, the processing module 73 is also used to create at least one virtual interface for the virtual machine when creating a virtual machine before the receiving module 71 uses the first thread to receive the message to be forwarded, and the at least one virtual interface includes the destination virtual interface; assign multiple virtual machine interface queues of the destination virtual interface to the threads in the thread set; and initialize the structure of the first thread according to the number of queues and queue numbers of the virtual machine interface queues assigned to the first thread.
[0114] In a feasible implementation method, the processing module 73 is also used to update the structure when the update condition is met, and the update condition includes at least one of the following conditions: the number of threads in the thread set changes, the number of virtual machine interface queues of the destination virtual interface changes, and the virtual machine corresponding to the destination virtual interface is added or destroyed.
[0115] In a feasible implementation, the processing module 73 is also used to create each thread in the thread set, a first bridge and a second bridge before the receiving module 71 uses the first thread to receive the message to be forwarded. The first bridge is used to set the virtual interface of the virtual machine, and the second bridge is used to set the physical interface of the physical network card.
[0116] In a feasible implementation, the processing module 73 is further configured to allocate exclusive resources to the thread set; and restart the physical machine where the virtual switch is located to make the exclusive resources effective.
[0117] In a feasible implementation, the processing module 73 is further used to determine the flow of each virtual machine interface queue in the multiple virtual machine interface queues of the destination virtual interface; and determine whether each virtual machine interface queue is balanced based on the flow of each virtual machine interface queue.
[0118] In a feasible implementation method, the processing module 73 is also used to determine the number of times that each thread in the thread set fails to obtain the queue lock; based on the number of times that each thread fails to obtain the queue lock, determine whether there is a virtual machine interface queue that is simultaneously assigned to at least two threads in the multiple virtual machine interface queues of the destination virtual interface.
[0119] The message sending device provided in the embodiment of the present application can execute the actions of the virtual switch in the above embodiment. Its implementation principle and technical effect are similar and will not be repeated here.
[0120] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 8 As shown, the electronic device 800 is, for example, the above-mentioned virtual switch, and the electronic device 800 includes:
[0121] Processor 81 and memory 82;
[0122] The memory 82 stores computer instructions;
[0123] The processor 81 executes the computer instructions stored in the memory 82, so that the processor 81 executes the message sending method implemented by the virtual switch as above.
[0124] The specific implementation process of the processor 81 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0125] Optionally, the electronic device 800 further includes a communication component 83 , wherein the processor 81 , the memory 82 and the communication component 83 may be connected via a bus 84 .
[0126] An embodiment of the present application further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed by a processor, they are used to implement the message sending method implemented by the virtual switch as above.
[0127] An embodiment of the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the message sending method implemented by the virtual switch as above.
[0128] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the application disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0129] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A message sending method, characterized in that: Applied to a virtual switch, the method comprises: Receiving a message to be forwarded by using a first thread, where the first thread is any thread in a thread set, and the threads in the thread set correspond one-to-one to the physical network card queues of the physical interface; Determine a structure according to the first thread and the destination virtual interface of the message to be forwarded, wherein the structure is used to indicate the number of queues and queue numbers of the virtual machine interface queues allocated to the first thread by the destination virtual interface; Determining a target queue from a plurality of virtual machine interface queues of the destination virtual interface according to the structure, the plurality of virtual machine interface queues being assigned to threads in the thread set; Send the message to be forwarded to the target queue.
2. The method according to claim 1, characterized in that The step of determining a target queue from a plurality of virtual machine interface queues of the destination virtual interface according to the structure includes: Determine a subscript of the target queue according to a hash value of the message to be forwarded, where the subscript is used to indicate a position of the target queue in a queue set, where a queue in the queue set is a virtual machine interface queue assigned by the destination virtual interface to the first thread; The target queue is determined from the queue set according to the index.
3. The method according to claim 1, characterized in that The sending the to-be-forwarded message to the target queue includes: Determine whether a sending condition is met, the sending condition comprising at least one of the following conditions: the number of the to-be-forwarded messages exceeds a preset number, and the time after receiving the to-be-forwarded messages is greater than a preset delay; When the sending condition is met, the message flow containing the to-be-forwarded messages is sent in batches to the target queue.
4. The method according to any one of claims 1 to 3, characterized in that: Before using the first thread to receive the message to be forwarded, the method further includes: When creating a virtual machine, creating at least one virtual interface for the virtual machine, the at least one virtual interface including the destination virtual interface; Allocating multiple virtual machine interface queues of the destination virtual interface to threads in the thread set; Initialize the structure of the first thread according to the number of queues and queue numbers of the virtual machine interface queues allocated to the first thread.
5. The method according to any one of claims 1 to 3, characterized in that: Also includes: When the update condition is met, the structure is updated, and the update condition includes at least one of the following conditions: the number of threads in the thread set changes, the number of virtual machine interface queues of the destination virtual interface changes, and the virtual machine corresponding to the destination virtual interface is added or destroyed.
6. The method according to any one of claims 1 to 3, characterized in that: Before using the first thread to receive the message to be forwarded, the method further includes: Each thread in the thread set, a first bridge and a second bridge are created, wherein the first bridge is used to set a virtual interface of a virtual machine, and the second bridge is used to set a physical interface of a physical network card.
7. The method according to claim 6, characterized in that Also includes: Allocating exclusive resources to the set of threads; Restart the physical machine where the virtual switch is located to make the exclusive resources effective.
8. The method according to any one of claims 1 to 3, characterized in that: Also includes: Determine the flow of each virtual machine interface queue in multiple virtual machine interface queues of the destination virtual interface; Whether the virtual machine interface queues are balanced is determined according to the traffic of the virtual machine interface queues.
9. The method according to any one of claims 1 to 3, characterized in that: Also includes: Determine the number of times each thread in the thread set fails to acquire a queue lock; When there is no thread in the thread set that cannot obtain the queue lock, determining that there is no virtual machine interface queue that is simultaneously allocated to at least two threads in the multiple virtual machine interface queues of the destination virtual interface; When there is a thread in the thread set that cannot obtain the queue lock, it is determined that among the multiple virtual machine interface queues of the destination virtual interface, there is a virtual machine interface queue that is simultaneously assigned to at least two threads, or it is determined that there is a thread in the thread set that is not assigned a virtual machine interface queue.
10. An electronic device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the electronic device implements the method according to any one of claims 1 to 9.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Message processing method, device, switch device and storage medium
CN109495404A
Cloud load balancing optimization method and system
CN110636139A