Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The networking shown in fig. 1 includes aclient 100, anLB device 110, aserver 120, aserver 130, and aserver 140.Server 120,server 130, andserver 140 form a server cluster X. The VIP (Virtual Internet Protocol) address provided outside the server cluster X is VIP _ X, the address of theserver 120 is IP _1, the address of theserver 130 is IP _2, and the address of theserver 140 is IP _ 3.
Currently, when implementing load balancing, theLB device 110 receives a network packet 1 sent by theclient 100 to the server cluster X. The destination address of the network packet 1 is VIP _ X, and the LB device may determine that VIP _ X corresponds to the server cluster X. TheLB device 110 selects one server from the 3 servers including theserver 120, theserver 130, and theserver 140 in the server cluster X according to the load balancing rule, for example, theserver 120 is selected, and the address of theserver 120 is IP _1, so that the destination address VIP _ X of the network packet 1 may be replaced with IP _ 1. Then, theLB device 110 sends the destination address replaced network packet 1 to theserver 120.
Subsequently, in the process of service interaction between theclient 100 and theserver 120, each network packet sent by theclient 100 to theserver 120 is sent to theserver 120 after the destination address is changed by theLB device 110. As can be seen from the above, in the network system, a network packet for performing service interaction between any client and any server in the server cluster X needs to be forwarded through theLB device 120, the performance of theLB device 120 plays an important role in the performance of the entire network, and the performance of theLB device 120 is easily a bottleneck of the entire network.
In order to reduce the influence of the performance of the LB device on the network performance under the condition of implementing load balancing, an embodiment of the present application provides a message processing method. In the method, an LB device determines a server cluster according to a destination address of a received first network message sent by a client, and determines a target server from the server cluster based on a preset load balancing rule. The LB device does not change the address of the network message, but sends the address of the target server to the client. At this time, the client may regenerate the second network packet using the address of the target server as the destination address, and send the second network packet to the target server, thereby implementing direct access to the target server. That is, the second network packet of the client accessing the target server subsequently can be forwarded without address replacement by the LB device, which effectively reduces the influence of the performance of the LB device on the network performance under the condition of realizing load balancing.
The present application will be described in detail below with reference to specific examples.
Referring to fig. 2, fig. 2 is a schematic flowchart of a message processing method according to an embodiment of the present disclosure. The method is applied to the LB device and comprises the following steps.
Step 201, receiving a first network packet sent by a client, where a destination address of the first network packet is a virtual address corresponding to a server cluster to be accessed by the client.
In this embodiment of the present application, a possible implementation manner is that the LB device maintains virtual address information provided by the server cluster connected to the LB device. Since the destination address of the first network packet sent by the client is the virtual address corresponding to the server cluster to be accessed by the client, the first network packet sent by the client can be understood as the first network packet sent by the client to the server cluster.
In practical application, when a client needs to acquire a service provided by a server cluster, the client sends a first network message to the server cluster through an LB device. The server cluster comprises a plurality of servers which can provide corresponding services for users. The services that can be provided by the server cluster include HTTP (hypertext Transfer Protocol) services, FTP (File Transfer Protocol) services, and the like.
The destination address of the first network packet is a virtual address provided outside the server cluster pair, such as a VIP address. For ease of understanding, the VIP address is used below as the address provided outside the server cluster pair. The VIP addresses provided by the server cluster outside are stored in the LB device. Specifically, the LB device stores therein a correspondence relationship between a VIP address and addresses of a plurality of servers. When the VIP address provided by the server cluster to the outside changes or the servers in the server cluster change, the corresponding relation between the pre-stored VIP address and the addresses of the plurality of servers is updated.
When the client needs to obtain the service provided by the server cluster, the client sends a first network message with a destination address being a VIP address. The LB device can determine a plurality of servers providing the same service according to the corresponding relation between the pre-stored VIP address and the addresses of the servers, and determine a target server capable of providing service for the client side based on a preset load balancing rule, so that load balancing is realized.
Step 202, determining the server cluster based on the destination address of the first network packet, and determining a target server from the server cluster based on a preset load balancing rule.
After receiving the first network message, the LB device can determine a server cluster according to the destination address of the first network message, so that a target server is determined from a plurality of servers included in the determined server cluster according to a preset load balancing rule. The LB device may determine one server as a target server from a plurality of servers included in the server cluster, or may determine a plurality of servers as target servers, which is not limited in this embodiment of the present application.
In the embodiment of the application, the load balancing rule can be set according to the user requirement.
For example, the load balancing rule may be that the selection distance is closest. That is, the LB device selects a server closest to the client as a target server from the plurality of servers.
As another example, the load balancing rule may be to select the largest free resource. That is, the LB device selects a server having the largest free resource from the plurality of servers as a target server.
In this embodiment of the present application, the LB device may obtain one or more of parameters such as a CPU usage rate and an available Network bandwidth of each server in the server cluster by using an SNMP (Simple Network Management Protocol) or another Protocol, determine whether each server is busy according to one or more of the parameters such as the CPU usage rate and the available Network bandwidth, and determine idle resources of each server. For example, for a server, the higher the CPU utilization, the smaller the available network bandwidth, and the smaller the idle resources of the server; conversely, the lower the CPU utilization rate, the larger the available network bandwidth, the larger the idle resources of the server.
In this embodiment of the present application, the LB device may further determine whether each server is busy by using other parameters, and determine idle resources of each server, which is not limited herein.
In an embodiment of the present application, in order to improve the efficiency of the LB device in determining the target server, the LB device is provided with a corresponding service resource list for the server cluster, where the service resource list stores information of each server in the server cluster, where an idle resource of the server is greater than or equal to a preset threshold. The preset threshold value can be determined according to the requirements of the user. If the idle resources of the server are more than or equal to a preset threshold value, determining that the server is available; and if the idle resources of the server are less than the preset threshold value, determining that the server is unavailable.
In this case, after receiving the first network packet sent by the client, the LB device directly selects, as the target server, the server with the largest free resource from the service resource list corresponding to the server cluster if the service resource list corresponding to the server cluster is not empty.
In an embodiment of the present application, an LB device periodically obtains idle resource information of each server in the server cluster; and updating the information of the server with the idle resource more than or equal to the preset threshold value into the service resource list, and deleting the information of the server with the idle resource less than the preset threshold value in the service resource list.
Specifically, in order to adapt to changes in the network environment, the LB device may periodically obtain one or more of parameters such as CPU utilization, available network bandwidth, and the like of each server in the server cluster, determine idle resources of each server in the server cluster, and update the service resource list. Of course, the calculation of the free resources of the server may also be performed on the server side, and the server periodically sends the free resource information to the LB device. Further, the LB device updates information of the server having the idle resource greater than or equal to the preset threshold to the service resource list corresponding to the server cluster, and deletes information of the server having the idle resource less than the preset threshold in the service resource list corresponding to the server cluster.
In one example, in order to more quickly determine the target server, the LB device previously sorts the information of the servers stored in the service resource list in order of the free resources from large to small. After receiving a first network message sent by a client, if a service resource list corresponding to a server cluster is not empty, the LB device directly selects a first server in the service resource list corresponding to the server cluster as a target server.
For example, as shown in the networking of FIG. 3, server cluster Z includes server 12, server 13, and server 14. The LB device 11 determines that the free resources of the server 12, the free resources of the server 13, and the free resources of the server 14 are all greater than or equal to a preset threshold, and stores information of the server 12, the server 13, and the server 14 in a service resource list. If the free resource of the server 13 > the free resource of the server 12 > the free resource of the server 14, the LB device 11 establishes a service resource list, which can be referred to as shown in table 1.
TABLE 1
| Service | Server identification | Server address |
| HTTP | Server 13 | IP_02 |
| HTTP | Server 12 | IP_01 |
| HTTP | Server 14 | IP_03 |
In table 1, IP _02 is the address of server 13, IP _01 is the address of server 12, and IP _03 is the address of server 14.
After the LB device receives the network packet sent by the client to the server cluster Z, it can directly determine that the server 13 is the target server according to table 1.
In another embodiment of the present application, if the service resource list is empty, the first network packet is discarded. That is, if the service resource list corresponding to the server cluster does not include information of the server, the LB device may determine that each server in the server cluster is unavailable, and discard the received first network packet in order to avoid affecting performance of each server.
Step 203, sending the address of the target server to the client, so that the client generates a second network message with the address of the target server as a destination address, and sends the second network message to the target server.
In one possible embodiment, the LB device determines a target server and sends the address of the target server to the client. Another possible embodiment is that the LB device determines a plurality of target servers, selects one target server from the plurality of target servers, and transmits an address of the selected target server to the client.
In the embodiment of the application, the LB device sends the address of the target server to the client, the client generates a second network message with the address of the target server as a destination address according to the received address of the target server, and sends the second network message to the target server through the forwarding device in networking. The forwarding device may be a switch, a router, or the like.
At the moment, the messages of the access server cluster are distributed to each server in the server cluster in a balanced mode for processing, and load balancing is achieved. In addition, the client directly accesses the server through the forwarding device in the network, address replacement is not required to be performed through the LB device, and ALG (Application Layer Gateway) related processing is not required to be performed by the LB device, so that errors in a message load processing process are reduced, the influence of the performance of the LB device on the network performance is reduced, and the capability of the network for providing services to the outside is greatly improved.
The embodiment of the application is more suitable for IPv6 networking. In IPv6 networking, the IPv6 address is abundant, and the server can be allowed to directly interact with the client by utilizing a unicast address.
In this embodiment, a possible implementation manner is that the address of the target server may be an IP address of the target server. The LB device sends the IP address of the target server to the client, and the client directly accesses the target server through the forwarding device in the network according to the IP address of the target server.
For example, in the networking shown in fig. 3, if the LB device 11 determines that the target server is the server 12 after receiving the network packet 2, the LB device 11 sends the address IP _1 of the server 12 to the client 10. The client 10 generates a network packet 21 with IP _1 as a destination address, and determines that the network packet 21 is finally transmitted to the server 12 through the router 15 by route calculation. Then the client 10 sends a network packet 21 to the server 12 via the router 15 in the networking.
Another possible implementation manner is that the LB device stores therein a virtual IP address (i.e., a mapping address) corresponding to an IP address of each server in the server cluster, and then the address of the target server may be the virtual IP address corresponding to the IP address of the target server.
In practical application, in order to improve the security of the network, the address provided by each server in the server cluster is a virtual IP address, and the LB device stores a mapping relationship between the IP address of each server in the server cluster and the corresponding virtual IP address, wherein the virtual IP address of any server in the LB device is obtained by performing static address conversion on the IP address of any server, and then, after determining a target server from the server cluster based on a preset load balancing rule, the LB device sends the virtual IP address corresponding to the target server to the client, and the client generates a second network packet by using the virtual IP address as a destination address, and sends the second network packet to the target server through forwarding devices in the network, specifically, when the second network packet is sent to a previous forwarding device of the target server, and converting the destination address of the second network message from the virtual IP address to the IP address of the target server.
For example, in the networking shown in fig. 3, if the LB device 11 determines that the target server is the server 12 after receiving the network packet 3, the LB device 11 determines the VIP _1 corresponding to the address IP _1 of the server 12 from the correspondence between the pre-stored server address and the mapping address, and sends the VIP _1 to the client 10. The client 10 generates the network message 4 with the VIP _1 as the destination address, and determines that the network message 4 is sent to the server 12 through the router 15 by routing calculation. When the client 10 sends the network packet sent to the server 12 to the router 15, the router 15 converts the destination address of the network packet 4 from VIP _1 to IP _1 using a static address translation technique. The router 15 forwards the destination address translated network message 4 to the server 12.
In another possible implementation, a server cluster may include multiple sub-server clusters, such as the networking shown in FIG. 4, with the server cluster including sub-server clusters 1-3. Here, different sub-server clusters may be understood as server clusters located in different data centers. At this time, the LB device may be divided into a main LB device (e.g.,LB device 300 in the networking shown in fig. 4) and a branch LB device (e.g.,LB device 310 and 330 in the networking shown in fig. 4).
After receiving a first network message sent by a client, a main LB device determines a target sub-server cluster from a plurality of sub-server clusters based on idle resource information and/or region information of the sub-server clusters; and replacing the destination address of the first network message with a virtual address corresponding to the target sub-server, and sending the destination address to the LB device corresponding to the target sub-server cluster, so that the LB device corresponding to the target sub-server cluster determines the target server from the target sub-server cluster based on a preset load balancing rule. Further, the LB device corresponding to the target sub-server cluster sends the address of the target server to the client, so that the client generates a second network packet with the address of the target server as a destination address, and sends the second network packet to the target server.
In practical application, the server cluster provides one external VIP address, and different sub-server clusters respectively provide different external VIP addresses. That is, the VIP address of one server cluster corresponds to the VIP addresses of multiple sub-server clusters, and the VIP address of one sub-server cluster corresponds to the VIP addresses of multiple servers.
For the backbone LB device, if a first network packet sent by the client is received, a destination address of the first network packet is a VIP address of a server cluster of the backbone LB device. In order to implement load balancing, the main LB device determines a target sub-server cluster from a plurality of sub-server clusters included in the server cluster. And the main LB device replaces the destination address of the first network message with the virtual address corresponding to the target sub-server cluster and sends the destination address to the branch LB device corresponding to the target sub-server cluster. For the branch LB device, if receiving the first network message sent by the main LB device, the preset load balancing rule determines the target server from the target sub-server cluster, and sends the address of the target server to the client through the main LB device. The detailed description ofstep 201 and 203 can be taken into account.
In the embodiment of the present application, when the main LB device determines the target sub-server cluster, a sub-server cluster closest to the client may be selected as the target sub-server cluster from among the server clusters including a plurality of sub-server clusters, or a sub-server cluster with the largest idle resource may be selected as the target sub-server cluster from among the server clusters including a plurality of sub-server clusters, which is not limited herein.
The following describes the message processing method provided in this embodiment in detail with reference to fig. 4.
The networking shown in fig. 4 includes:client 600,LB device 300, 330,server 400, 480, androuter 500, 550. Wherein, theserver 400 and 480 form a server cluster Y1, theserver 400 and 420 form a sub server cluster Y11 of the server cluster Y1, theserver 430 and 450 form a sub server cluster Y12 of the server cluster Y1, and theserver 460 and 480 form a sub server cluster Y13 of the server cluster Y1.
The VIP address of server cluster Y1 is VIP _ a0, the VIP address of child server cluster Y11 is VIP _ a1, the VIP address of child server cluster Y12 is VIP _ a2, and the VIP address of child server cluster Y13 is VIP _ a 3.
In step 41, theclient 600 sends the network packet 11 to theLB device 300. The destination address of the network packet 11 is VIP _ a 0.
In step 42, theLB device 300 determines that VIP _ a0 corresponds to 3 addresses of VIP _ a1, VIP _ a2, and VIP _ a3, that is, VIP _ a0 corresponds to 3 sub-server clusters of sub-server cluster Y11, sub-server cluster Y12, and sub-server cluster Y12, and selects a sub-server cluster closest to theclient 600 from the 3 sub-server clusters, for example, sub-server cluster Y11.
In step 43, theLB device 300 replaces the destination address of the network packet 11 with the address VIP _ a1 of the sub-server cluster Y11, and sends the network packet 11 with the replaced destination address to theLB device 310 corresponding to the sub-server cluster Y11.
In step 44, theLB device 310 selects a server with the largest free resource from the service resource list corresponding to the sub-server cluster Y11, as a target server, for example, theserver 400 is selected.
In step 45, theLB device 310 determines the VIP _ a11 corresponding to the address IP _ a11 of theserver 400 from the correspondence between the IP address of the server and the virtual IP address stored in advance, and sends the address VIP _ a11 to theclient 600 through theLB device 300.
At step 46, theclient 600 generates the network packet 12 with VIP _ a11 as the destination address, and determines that the network packet 12 is sent to theserver 400 through therouter 500 by routing computation.
At step 47,client 600 sends network packet 12 torouter 500.
At step 48, therouter 500 translates the destination address of the network packet 12 from the VIP _ a11 to the IP _ a11 according to static address translation techniques.
In step 49, therouter 500 sends the network packet 12 with the translated destination address to theserver 400.
At this time, the network packets sent by the client are not necessarily all processed by the LB device, which effectively reduces the influence of the performance of the LB device on the network performance under the condition of realizing load balancing.
Corresponding to the embodiment of the message processing method, the embodiment of the application also provides a message processing device. Referring to fig. 5, fig. 5 is a schematic structural diagram of a message processing apparatus provided in this embodiment, where the apparatus is applied to an LB device, and the apparatus includes a receivingunit 501, a determiningunit 502, and a sendingunit 503.
A receivingunit 501, configured to receive a first network packet sent by a client, where a destination address of the first network packet is a virtual address corresponding to a server cluster to be accessed by the client;
a determiningunit 502, configured to determine the server cluster based on the destination address of the first network packet, and determine a target server from the server cluster based on a preset load balancing rule;
a sendingunit 503, configured to send the address of the target server to the client, so that the client generates a second network packet using the address of the target server as a destination address, and sends the second network packet to the target server.
Optionally, a corresponding service resource list is set for the server cluster, where the service resource list stores information of each server in which idle resources in the server cluster are greater than or equal to a preset threshold;
when the step of determining the target server from the server cluster based on the preset load balancing rule is performed, the determiningunit 502 is configured to:
and selecting the server with the largest free resource from the service resource list as a target server.
Optionally, the apparatus further includes a determining unit, where the determining unit is configured to:
and discarding the first network message when the service resource list is judged to be empty.
Optionally, the apparatus further includes an updating unit, where the updating unit is configured to:
periodically acquiring idle resource information of each server in the server cluster;
and updating the information of the server with the idle resource more than or equal to the preset threshold value into the service resource list, and deleting the information of the server with the idle resource less than the preset threshold value in the service resource list.
Optionally, the server cluster includes a plurality of sub-server clusters;
when the step of determining the target server from the server cluster based on the preset load balancing rule is performed, the determiningunit 502 is configured to:
determining a target sub-server cluster from the plurality of sub-server clusters based on the idle resource information and/or the region information of the plurality of sub-server clusters;
and replacing the destination address of the first network message with a virtual address corresponding to the target sub-server, and sending the destination address to the LB device corresponding to the target sub-server cluster, so that the LB device corresponding to the target sub-server cluster determines the target server from the target sub-server cluster based on a preset load balancing rule.
Optionally, the address of the target server is: the IP address of the target server; or,
the LB device stores virtual IP addresses corresponding to the IP addresses of the servers in the server cluster, and the address of the target server is as follows: and the virtual IP address corresponds to the IP address of the target server.
By applying the embodiment of the application, an LB device receives a first network message sent by a client, wherein the destination address of the first network message is a virtual address corresponding to a server cluster to be accessed by the client; determining the server cluster based on the destination address of the first network message, and determining a target server from the server cluster based on a preset load balancing rule; and sending the address of the target server to the client so that the client generates a second network message with the address of the target server as a destination address, and sending the second network message to the target server. That is, the network messages subsequently sent by the client may not be processed by the LB device any more, and the client generates new network messages by using the IP address of the target server determined by the LB device based on the preset load balancing policy as the destination address, and sends the new network messages to the target server, thereby avoiding a situation that all the network messages sent by the client need to be processed by the LB device, and effectively reducing the influence of the performance of the LB device on the network performance on the basis of realizing load balancing.
Corresponding to the foregoing message processing method embodiment, an LB device is further provided in the embodiment of the present application, as shown in fig. 6, and includes aprocessor 601 and a machine-readable storage medium 602, where the machine-readable storage medium 602 stores machine-executable instructions that can be executed by theprocessor 601. Theprocessor 601 is caused by machine executable instructions to implement the message processing methods described above. The message processing method comprises the following steps:
receiving a first network message sent by a client, wherein the destination address of the first network message is a virtual address corresponding to a server cluster to be accessed by the client;
determining the server cluster based on the destination address of the first network message, and determining a target server from the server cluster based on a preset load balancing rule;
and sending the address of the target server to the client so that the client generates a second network message with the address of the target server as a destination address, and sending the second network message to the target server.
By applying the embodiment of the application, an LB device receives a first network message sent by a client, wherein the destination address of the first network message is a virtual address corresponding to a server cluster to be accessed by the client; determining the server cluster based on the destination address of the first network message, and determining a target server from the server cluster based on a preset load balancing rule; and sending the address of the target server to the client so that the client generates a second network message with the address of the target server as a destination address, and sending the second network message to the target server. That is, the network messages subsequently sent by the client may not be processed by the LB device any more, and the client generates new network messages by using the IP address of the target server determined by the LB device based on the preset load balancing policy as the destination address, and sends the new network messages to the target server, thereby avoiding a situation that all the network messages sent by the client need to be processed by the LB device, and effectively reducing the influence of the performance of the LB device on the network performance on the basis of realizing load balancing.
In addition, as shown in fig. 7, the LB apparatus may further include: acommunication interface 603 and acommunication bus 604; theprocessor 601, the machine-readable storage medium 602, and thecommunication interface 603 complete communication with each other through thecommunication bus 604, and thecommunication interface 603 is used for communication between the LB device and other devices.
Corresponding to the foregoing message processing method embodiment, an embodiment of the present application further provides a machine-readable storage medium, which stores machine-executable instructions, and when the machine-readable storage medium is called and executed by a processor, the machine-executable instructions cause the processor to implement any one of the method steps of the embodiments shown in fig. 2 to 4.
The communication bus may be a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc.
The machine-readable storage medium may include a RAM (Random Access Memory) and a NVM (Non-Volatile Memory), such as at least one disk Memory. Additionally, the machine-readable storage medium may be at least one memory device located remotely from the aforementioned processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also DSPs (Digital Signal Processing), ASICs (Application Specific Integrated circuits), FPGAs (Field Programmable Gate arrays) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. Especially, for the embodiments of the message processing apparatus, the LB device, and the machine-readable storage medium, since they are substantially similar to the embodiments of the method, the description is relatively simple, and for the relevant points, reference may be made to the partial description of the embodiments of the method.
The above description is only for the preferred embodiment of the present application, and is not intended to limit the scope of the present application. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application are included in the protection scope of the present application.