Data forwarding method and device of four-layer load balancer, equipment and storage medium
The method for four-layer load balancer data transfer addresses consistency challenges by using local and synchronized tables with RS Hash trees and sequence numbers, reducing resource usage and maintaining high-bandwidth performance in CDN environments.
Patent Information
- Application Number
- CN202411753679.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-02
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2044-12-02
AI Technical Summary
In the context of Content Delivery Networks (CDN), existing four-layer load balancing technologies face challenges in maintaining data transfer consistency across multiple load balancers, leading to resource-intensive full-table synchronization, which is not suitable for high-bandwidth scenarios due to high bandwidth, CPU, and memory usage.
A method for four-layer load balancer data transfer that involves each load balancer maintaining a local table and a synchronized table with an RS Hash tree for consistent routing, allowing load balancers to determine the correct backend server even when the OSFP protocol restarts, reducing the need for full-table synchronization by using sequence numbers to verify rule consistency.
This approach ensures consistent data transfer without the need for full-table synchronization, significantly reducing resource consumption and maintaining high-bandwidth performance in CDN environments.
Smart Images

Figure CN119728542A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of CDN acceleration technology, and in particular to a data forwarding method for a four-layer load balancer, a data forwarding device for a four-layer load balancer, a computer device and a storage medium. Background Art
[0002] In the field of distributed network architecture (Content Delivery Network, CDN) acceleration, in order to achieve efficient traffic distribution and acceleration services, multiple backend servers (RealServer, RS) are usually deployed, and traffic is evenly forwarded to different backend servers through a four-layer load balancer (Linux Virtual Server, LVS). When forwarding traffic to the backend server, the four-layer load balancer will save the current forwarding information to ensure that the same flow can be forwarded to the same backend server, thereby maintaining the stability and consistency of the connection.
[0003] In order to ensure that the same connection can be forwarded to the same RS, the Layer 3 switch needs to forward the request of the same connection to the same Layer 4 load balancer, and the Layer 4 load balancer needs to forward the request of the same connection to the same RS based on the locally stored forwarding table information. However, in actual operation, when the OSPF (Open Shortest Path First) protocol of the Layer 4 load balancer is restarted (for example, the Layer 4 load balancer is removed from the shelf, expanded, or fails), the number of Equal-Cost Multi-Path (ECMP) routes on the Layer 3 switch will change, resulting in the traffic of the same connection reaching the Layer 3 switch. The Layer 4 load balancer obtained according to the IP Hash method of the switch may change. Since each Layer 4 load balancer currently only retains its own forwarding table information, when the Layer 3 switch forwards the traffic of the same connection to different Layer 4 load balancers, the Layer 4 load balancer cannot forward the connection to the original RS, resulting in abnormal client requests.
[0004] In this regard, the common method is to synchronize all the forwarding table information of the four-layer load balancer, that is, each four-layer load balancer saves a copy of the forwarding table information of other four-layer load balancers. However, when there is a lot of forwarding table information, the bandwidth, CPU, memory and other resources of the four-layer load balancer are consumed, which affects the performance of the system and is not suitable for high-bandwidth business scenarios such as CDN. Summary of the invention
[0005] In view of the above problems, an embodiment of the present invention provides a data forwarding method, device, equipment and storage medium for a four-layer load balancer to solve the problem of large resource consumption required for LVS to achieve data forwarding consistency in the prior art.
[0006] In order to solve the above problem, an embodiment of the present invention discloses a data forwarding method of a four-layer load balancer, which is applied to a first four-layer load balancer, wherein the first four-layer load balancer and a plurality of second four-layer load balancers form a network group, and the method includes:
[0007] Receiving a connection request and parsing the message information of the connection request;
[0008] According to the message information, query whether a local forwarding table and a synchronous forwarding table have a first forwarding rule corresponding to the connection request, wherein the local forwarding table is a forwarding table locally created by the first four-layer load balancer, and the synchronous forwarding table is a forwarding table synchronized to the first four-layer load balancer by multiple second four-layer load balancers;
[0009] If it is found that the first forwarding rule does not exist in the local forwarding table and the synchronous forwarding table, the backend information corresponding to the first RS backend is obtained from the RS hash tree according to the hash value calculated according to the message information, and the RS hash tree is a hash tree that records the consistency of the RS backend hash values of all four-layer load balancers;
[0010] According to the backend information, a second forwarding rule corresponding to the connection request is created and saved in the local forwarding table, and the message information is forwarded to the first RS backend.
[0011] In some embodiments, after querying the local forwarding table and the synchronous forwarding table according to the message information whether there is a first forwarding rule corresponding to the connection request, the method further includes:
[0012] If it is found that the first forwarding rule exists in the local forwarding table, determine whether the first sequence value of the first forwarding rule is consistent with the second sequence value of the RS hash tree, the second sequence value is the accumulated count value corresponding to each update of the RS hash value, and the first sequence value is the latest sequence value corresponding to the RS hash tree when the first forwarding rule is created;
[0013] If the first sequence value is inconsistent with the second sequence value, determining whether the time difference between the last update time of the RS hash tree and the current time is greater than a preset time length;
[0014] If the time difference is greater than the preset duration, the forwarding rules in the local forwarding table that are inconsistent with the sequence value of the RS hash tree are synchronized to multiple second-layer four load balancers, and the message information is forwarded to the second RS backend corresponding to the first forwarding rule.
[0015] In some embodiments, after determining whether the first sequence value of the first forwarding rule is consistent with the second sequence value of the RS hash tree, the method further includes:
[0016] If the first sequence value is consistent with the second sequence value, the message information is forwarded to the second RS backend corresponding to the first forwarding rule.
[0017] In some embodiments, after determining whether the time difference between the last update time of the RS hash tree and the current time is greater than a preset time length, the method further includes:
[0018] If the time difference is not greater than the preset duration, the message information is forwarded to the second RS backend corresponding to the first forwarding rule.
[0019] In some embodiments, after querying the local forwarding table and the synchronous forwarding table according to the message information whether there is a forwarding rule corresponding to the connection request, the method further includes:
[0020] If it is found that the local forwarding table does not contain the first forwarding rule, and the synchronous forwarding table contains the first forwarding rule, the message information of the connection request is forwarded to the second RS backend corresponding to the first forwarding rule.
[0021] In some embodiments, the method comprises:
[0022] When the first four-layer load balancer is restarted, RS backend information is added, and then the RS backend information is fully synchronized to multiple second four-layer load balancers;
[0023] Receive full RS information and target forwarding rules replied by multiple second-layer four-layer load balancers, where the target forwarding rules are forwarding rules in the multiple second-layer four-layer load balancers that are inconsistent with the sequence value of the RS hash tree;
[0024] The full amount of RS information is saved to the target local RS linked list, and the RS hash tree is updated and the target forwarding rule is synchronized, wherein the target local RS linked list is an RS linked list corresponding to the second four-layer load balancer and stored locally in the first four-layer load balancer;
[0025] If the target forwarding rule is synchronized, the OSPF protocol is started to guide the traffic to the first four-layer load balancer.
[0026] In some embodiments, before the first four-layer load balancer is restarted, it also includes:
[0027] When the first four-layer load balancer exits, the RS backend information is deleted;
[0028] Synchronize the exit information to the plurality of the second-layer four load balancers, so that the plurality of the second-layer four load balancers clear the RS backend information of the first-layer four load balancer stored locally, wherein the exit information includes the RS backend information.
[0029] The embodiment of the present invention further provides a data forwarding device of a four-layer load balancer, which is applied to a first four-layer load balancer, wherein the first four-layer load balancer and a plurality of second four-layer load balancers form a network group, and the device comprises:
[0030] A parsing module, used for receiving a connection request and parsing message information of the connection request;
[0031] A query module, configured to query a local forwarding table and a synchronous forwarding table, based on the message information, whether there is a first forwarding rule corresponding to the connection request, wherein the local forwarding table is a forwarding table locally created by the first four-layer load balancer, and the synchronous forwarding table is a forwarding table synchronized to the first four-layer load balancer by multiple second four-layer load balancers;
[0032] An acquisition module, for obtaining backend information corresponding to the first RS backend from an RS hash tree according to a hash value calculated from the message information if the first forwarding rule does not exist in the local forwarding table and the synchronous forwarding table, wherein the RS hash tree is a hash tree that records the consistency of the RS backend hash values of all four-layer load balancers;
[0033] A creation module is used to create a second forwarding rule corresponding to the connection request according to the backend information and save it to the local forwarding table, and forward the message information to the first RS backend.
[0034] An embodiment of the present invention further provides a computer device, including:
[0035] one or more processors; and
[0036] One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, enable the computer device to perform the method described in the embodiment of the present invention.
[0037] An embodiment of the present invention further provides a computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, enables the processors to execute the method described in the embodiment of the present invention.
[0038] The embodiments of the present invention include the following advantages:
[0039] The present invention receives a connection request and parses the message information of the connection request, and queries the local forwarding table and the synchronous forwarding table according to the message information whether there is a first forwarding rule corresponding to the connection request, wherein the local forwarding table is a forwarding table locally created by the first four-layer load balancer, and the synchronous forwarding table is a forwarding table synchronized to the first four-layer load balancer by multiple second four-layer load balancers, so as to save a local forwarding table and a forwarding table synchronized by other four-layer load balancers in each four-layer load balancer, so as to facilitate the use of a hash consistency algorithm to determine the RS backend to which the connection request needs to be forwarded, so that when the traffic of the same connection is forwarded to different four-layer load balancers, the four-layer load balancer can still forward it to the original RS backend, avoiding abnormality of the client request; if it is queried that the local forwarding table and the synchronous forwarding table do not have the first Forwarding rules, then according to the hash value calculated from the message information, the backend information corresponding to the first RS backend is obtained from the RS hash tree, the RS hash tree is a hash tree that records the consistency of the RS backend hash values of all four-layer load balancers, so that all four-layer load balancers use the RS hash tree to ensure the synchronization of RS backend information; according to the backend information, a second forwarding rule corresponding to the connection request is created and saved to the local forwarding table, and the message information is forwarded to the first RS backend, all four-layer load balancers collaboratively update the RS hash tree based on the same RS information, to ensure that the new connection creates forwarding rules based on the same RS hash tree, so that there is no need to perform real-time full synchronization of the forwarding table information of multiple four-layer load balancers, which greatly reduces the consumption of resources such as bandwidth, CPU and memory of the four-layer load balancer, and can meet large-bandwidth business scenarios such as CDN. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 It is a flow chart of the steps of a data forwarding method of a four-layer load balancer provided by an embodiment of the present invention;
[0041] Figure 2 This is a schematic diagram of connection request distribution of the related technology provided by an embodiment of the present invention;
[0042] Figure 3 It is a synchronization schematic diagram when the four-layer load balancer provided by an embodiment of the present invention adds an RS backend;
[0043] Figure 4 It is a synchronization schematic diagram of the four-layer load balancer provided by the embodiment of the present invention when the RS backend is removed;
[0044] Figure 5It is a flowchart of another data forwarding method of a four-layer load balancer provided by an embodiment of the present invention;
[0045] Figure 6 It is a flow chart of synchronization steps when a four-layer load balancer is restarted according to an embodiment of the present invention;
[0046] Figure 7 It is a structural block diagram of a data forwarding device of a four-layer load balancer provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0047] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0048] As described in the background technology, when there are multiple layer 4 load balancers, the master + backup mode can be used to improve the reliability of the system, or the master + master mode can be used to improve the load capacity of the system. When multiple layer 4 load balancers work in the master + master mode, each layer 4 load balancer can provide services to the outside world. The layer 4 load balancer is mainly implemented through Keepalived + OSPF.
[0049] like Figure 2 As shown in the figure, 1. Multiple clients initiate access to VIP (10.0.10.100); 2. When the access traffic reaches the three-layer switch, the three-layer switch distributes the traffic accessing VIP to different four-layer load balancers through ECMP equal-cost routing; generally, a fixed IP Hash method is used to select which four-layer load balancer the traffic is to be sent to. When the number of ECMP equal-cost routes remains unchanged, the four-layer load balancer to which the same connection request is hashed will also be the same; 3. After receiving the request, the four-layer load balancer selects an RS backend information through a fixed algorithm based on the backend RS information sent by Keepalived and forwards the traffic to the corresponding RS. At the same time, the four-layer load balancer records the RS backend information forwarded by the connection. When the same connection request is received later, the request is directly forwarded to the same RS backend.
[0050] It can be seen that in order to ensure that the same connection can be forwarded to the same RS, the three-layer switch needs to forward the request of the same connection to the same four-layer load balancer, and the four-layer load balancer needs to forward the request of the same connection to the same RS based on the locally stored forwarding table information. However, when the OSPF protocol of the four-layer load balancer is restarted, the traffic of the same connection forwarded to different four-layer load balancers cannot be forwarded to the original RS. In this regard, the relevant method fully synchronizes the forwarding table information of the four-layer load balancer. When the forwarding table information is relatively large, the bandwidth, CPU, memory and other resources of the four-layer load balancer are consumed relatively large, affecting the performance of the system, and is therefore not suitable for high-bandwidth business scenarios such as CDN.
[0051] In response to the above problems, one of the core concepts of the embodiment of the present invention is that the four-layer load balancer uses the RSHash consistency algorithm to calculate the backend RS that needs to be forwarded for the connection request. By synchronizing the RS backend information in real time, each four-layer load balancer saves a copy of the RS backend information of other four-layer load balancers, and the four-layer load balancers collaboratively update the RS Hash tree based on the same RS information to ensure that the new connection creates forwarding rules based on the same RS Hash tree. In this way, it is not necessary to synchronize the forwarding table information in full.
[0052] One of the core concepts of the embodiments of the present invention is to maintain a serial number information on the forwarding rule and the RS Hash tree. When the RS Hash tree is updated, the serial number of the RS Hash tree is updated synchronously; when the forwarding rule is created, the serial number information of the current RS Hash tree is recorded in the forwarding rule; when the four-layer load balancer accesses a forwarding rule, it can be determined by the serial number whether the forwarding rule is calculated based on the latest RS Hash tree, so as to determine whether the forwarding rule needs to be synchronized, thereby greatly reducing unnecessary synchronization scenarios.
[0053] One of the core concepts of the embodiment of the present invention is that when the four-layer load balancer is restarted, the consistency of the RS backend is guaranteed by fully synchronizing the RS backend information. At the same time, the restarted four-layer load balancer senses that the other four-layer load balancers have synchronized the forwarding rules, and then starts the OSPF protocol to ensure that when the switch dispatches the traffic to the restarted load balancer, the forwarding rules have been synchronized.
[0054] Among them, the four-layer load balancer is a device or software responsible for distributing and load balancing network traffic at the transport layer (fourth layer). It can distribute incoming connection requests to multiple backend servers according to specific rules to achieve load balancing and high availability.
[0055] ECMP (Equal-Cost Multipath) is a network routing technology used to achieve load balancing between multiple paths with the same cost. It allows traffic to be distributed on multiple paths with the same cost to improve the bandwidth utilization and fault tolerance of the network.
[0056] OSPF (Open Shortest Path First) is an interior gateway protocol (IGP) used to exchange routing information and calculate the shortest path between routers within an autonomous system (AS).
[0057] Keepalived is an open source software for implementing high availability (HA) and load balancing (LB) on Linux systems. It provides a simple and effective way to monitor and manage the status of multiple servers.
[0058] RS (Real Server) backend server refers to the server that provides specific services. The four-layer load balancer forwards the request data to RS to provide external services.
[0059] LIP (local ip address) indicates the local ip address of the server.
[0060] VIP (virtual ip addredd) represents a virtual IP address, which refers to the IP address that the business component uses to provide services to the outside world.
[0061] LVS (Linux Virtual Server) is a high-performance, scalable load balancer based on Linux. It is an open source software project that aims to provide a reliable load balancing solution for distributing network traffic to multiple backend servers to improve system availability and performance.
[0062] CDN (Content Delivery Network) is a distributed network architecture designed to provide efficient content transmission and delivery services. Its main goal is to enable users to access and obtain network content faster by storing content on edge servers distributed around the world.
[0063] Reference Figure 1 , Figure 1A flow chart of the steps of a data forwarding method of a four-layer load balancer provided by an embodiment of the present invention is shown, and the method is applied to a first four-layer load balancer, and the first four-layer load balancer and a plurality of second four-layer load balancers form a network group. It should be understood that the first four-layer load balancer and the second four-layer load balancer described in the present invention are not specific, but any four-layer load balancer in the network group is used as the first four-layer load balancer, and the other four-layer load balancers are used as the second four-layer load balancer.
[0064] like Figure 1 As shown, the method includes steps S101 to S104, which are described in detail as follows:
[0065] Step S101, receiving a connection request and parsing message information of the connection request.
[0066] In this step, the connection request is initiated by the client and distributed by the three-layer switch. The message information is the key information of the message, which includes but is not limited to the protocol type (TCP / UDP), source IP address, source port, destination IP address and destination port.
[0067] Optionally, the process of parsing the message information of the connection request includes: determining the protocol type used by the connection request, such as HTTP, TCP, UDP, WebSocket, etc., where different protocols have different standards and message formats; extracting the message header, the TCP message header contains information such as the source port, destination port, sequence number, confirmation number and flag; the IP message header contains the source IP address, destination IP address and protocol type, etc.; according to the protocol type, parsing the specific content of the message: for HTTP, parsing the request line and header fields, extracting information such as URL, method, user agent, etc.; for TCP / IP, parsing information such as source port, destination port, IP address, etc.; for WebSocket, parsing the handshake request, extracting fields such as Sec-WebSocket-Key and Sec-WebSocket-Version.
[0068] Step S102: query the local forwarding table and the synchronous forwarding table based on the message information whether there is a first forwarding rule corresponding to the connection request, wherein the local forwarding table is a forwarding table locally created by the first four-layer load balancer, and the synchronous forwarding table is a forwarding table synchronized to the first four-layer load balancer by multiple second four-layer load balancers.
[0069] In this step, the forwarding table contains forwarding rules. The local forwarding table is queried based on the message information to see if there is a first forwarding rule, so as to determine whether the RS backend information to be forwarded by the connection request is in the local forwarding table of the first four-layer load balancer. If the local forwarding table does not have the first forwarding rule, the synchronous forwarding table is queried based on the message information to see if there is a first forwarding rule, so as to determine whether the RS backend information to be forwarded by the connection request is in the forwarding table of the second four-layer load balancer. In this way, when the traffic of the same connection is forwarded to different four-layer load balancers, the four-layer load balancer can still forward it to the original RS backend, avoiding abnormal client requests.
[0070] The four-layer load balancer locally stores a copy of the RS backend information of other four-layer load balancers; when the local RS backend information of the four-layer load balancer changes, it is synchronized to other four-layer load balancers in real time through multicast messages. When all four-layer load balancers have a certain RS backend information, the four-layer load balancer adds the RS backend information to the RS hash tree; when a four-layer load balancer removes a certain RS backend information, all four-layer load balancers need to remove the RS backend information from the local RS hash tree.
[0071] Alternatively, if Figure 3 The synchronization diagram of the four-layer load balancer when adding the RS backend is shown. The four-layer load balancer 2 adds a new RS (RSn). After adding RSn to the RS linked list corresponding to the four-layer load balancer 2, if it is determined that the four-layer load balancer 1 and the four-layer load balancer 3 also have RSn, RSn is added to the RS hash tree (RS hash consistency tree), and then the four-layer load balancer 1 and the four-layer load balancer 3 are notified by multicast message to also add RSn synchronously; after the four-layer load balancer 1 and the four-layer load balancer 3 receive the synchronous addition message, RSn is added to the RS linked list of the four-layer load balancer 2 locally stored by the four-layer load balancer 1, and RSn is added to the RS linked list of the four-layer load balancer 2 locally stored by the four-layer load balancer 3; then RSn is also added to the local RS hash tree of the four-layer load balancer 1 and the four-layer load balancer 3.
[0072] Alternatively, if Figure 4The synchronization diagram of the four-layer load balancer when removing the RS backend is shown. The four-layer load balancer 2 receives the Keepalived notification to remove RSn, removes RSn from the RS linked list of the four-layer load balancer 2, and then removes RSn from the RS hash tree. After the removal is completed, the RSn removal information of the four-layer load balancer 2 is synchronized through the multicast message. After the four-layer load balancer 1 and the four-layer load balancer 3 receive the message that the four-layer load balancer 2 removes RSn, they remove RSn from the RS linked list of the four-layer load balancer 2 local to the four-layer load balancer 1, and remove RSn from the RS linked list of the four-layer load balancer 2 local to the four-layer load balancer 3, and then remove RSn from the RS hash tree local to the four-layer load balancer 1 and the four-layer load balancer 3.
[0073] Step S103, if it is found that the first forwarding rule does not exist in the local forwarding table and the synchronous forwarding table, the backend information corresponding to the first RS backend is obtained from the RS hash tree based on the hash value calculated according to the message information, and the RS hash tree is a hash tree that records the consistency of the RS backend hash values of all four-layer load balancers.
[0074] In this step, the four-layer load balancer selects the RS backend to which the connection request traffic is to be distributed based on the RS Hash consistency algorithm. The four-layer load balancer maintains an RS hash tree. The four-layer load balancer adds the RS backend information to the RS hash tree based on the hash value calculated based on the RS IP address. When the four-layer load balancer receives a new connection request, it obtains the RS backend information to be forwarded from the RS hash tree based on the hash value of the source IP + source port of the connection request.
[0075] If the first forwarding rule does not exist in the local forwarding table and the synchronous forwarding table, it means that the connection request is a new connection, so it is necessary to create a forwarding rule for the new connection to allocate the RS backend corresponding to the new connection. In order to reduce resource consumption, the RS hash tree is used to ensure the consistency of the RS backend hash value.
[0076] Optionally, a hash value is calculated using the source IP+source port of the connection request, and based on the hash value, RS backend information that is most adjacent to the hash value on the RS hash tree is selected.
[0077] Step S104: creating a second forwarding rule corresponding to the connection request according to the backend information and saving it to the local forwarding table, and forwarding the message information to the first RS backend.
[0078] In this step, when the four-layer load balancer receives a new connection request, it creates a forwarding rule for the new connection request based on the current RS hash tree, and records the sequence value of the current RS hash tree in the forwarding rule, so as to facilitate the subsequent comparison of the sequence value between the forwarding rule and the RS hash tree to determine whether the forwarding rule is calculated based on the latest RS hash tree, and then determine whether synchronization is needed, which greatly reduces unnecessary synchronization scenarios.
[0079] This embodiment receives a connection request and parses the message information of the connection request. According to the message information, it queries the local forwarding table and the synchronous forwarding table to see whether there is a first forwarding rule corresponding to the connection request. The local forwarding table is a forwarding table locally created by the first four-layer load balancer, and the synchronous forwarding table is a forwarding table synchronized to the first four-layer load balancer by multiple second four-layer load balancers, so as to save a local forwarding table and a forwarding table synchronized by other four-layer load balancers in each four-layer load balancer, so as to facilitate the use of a hash consistency algorithm to determine the RS backend to which the connection request needs to be forwarded, so that when the traffic of the same connection is forwarded to different four-layer load balancers, the four-layer load balancer can still forward it to the original RS backend, avoiding abnormalities in client requests; if it is found that the local forwarding table and the synchronous forwarding table do not have the first Forwarding rules, then according to the hash value calculated from the message information, the backend information corresponding to the first RS backend is obtained from the RS hash tree, the RS hash tree is a hash tree that records the consistency of the RS backend hash values of all four-layer load balancers, so that all four-layer load balancers use the RS hash tree to ensure the synchronization of RS backend information; according to the backend information, a second forwarding rule corresponding to the connection request is created and saved to the local forwarding table, and the message information is forwarded to the first RS backend, all four-layer load balancers collaboratively update the RS hash tree based on the same RS information, to ensure that the new connection creates forwarding rules based on the same RS hash tree, so that there is no need to perform real-time full synchronization of the forwarding table information of multiple four-layer load balancers, which greatly reduces the consumption of resources such as bandwidth, CPU and memory of the four-layer load balancer, and can meet large-bandwidth business scenarios such as CDN.
[0080] In some embodiments, Figure 5 As shown, after step S102, the following further includes:
[0081] If it is found that the local forwarding table does not contain the first forwarding rule, and the synchronous forwarding table contains the first forwarding rule, forwarding the message information of the connection request to the second RS backend corresponding to the first forwarding rule;
[0082] If it is found that the first forwarding rule exists in the local forwarding table, determine whether the first sequence value of the first forwarding rule is consistent with the second sequence value of the RS hash tree, the second sequence value is the accumulated count value corresponding to each update of the RS hash value, and the first sequence value is the latest sequence value corresponding to the RS hash tree when the first forwarding rule is created;
[0083] If the first sequence value is consistent with the second sequence value, forwarding the message information to the second RS backend corresponding to the first forwarding rule;
[0084] If the first sequence value is inconsistent with the second sequence value, determining whether the time difference between the last update time of the RS hash tree and the current time is greater than a preset time length;
[0085] If the time difference is greater than the preset duration, the forwarding rules in the local forwarding table that are inconsistent with the sequence value of the RS hash tree are synchronized to the plurality of second-layer four load balancers, and the message information is forwarded to the second RS backend corresponding to the first forwarding rule;
[0086] If the time difference is not greater than the preset duration, the message information is forwarded to the second RS backend corresponding to the first forwarding rule.
[0087] In this embodiment, since the RS information between different four-layer load balancers will be synchronized in real time, after the synchronization is completed, the RS hash trees between multiple four-layer load balancers will be consistent, and the forwarding rules will not be synchronized in real time, so the four-layer load balancer only synchronizes the forwarding rules that are not created based on the latest RS hash tree, and the RS backend selected by the forwarding rules created based on the same RS hash tree is the same, so synchronization is not required. By associating the RS information between multiple four-layer load balancers through the RS hash tree, there is no need to synchronize the forwarding table in real time, which greatly reduces unnecessary synchronization scenarios.
[0088] Among them, this embodiment uses sequence values to record the update of the RS hash tree (including adding RS backend information and removing RS backend information). Specifically, the four-layer load balancer adds a sequence value count information to the RS hash tree. When the RS hash tree is updated, its sequence value is accumulated by 1; when the four-layer load balancer receives a new connection request, it creates a forwarding rule for the connection based on the current RS hash tree, and records the latest sequence value of the current RS hash tree in the forwarding rule. By comparing the sequence value between the forwarding rule and the RS hash tree, it can be known whether the forwarding rule is calculated based on the latest RS hash tree, so that it can be determined whether synchronization is required for a certain forwarding rule, and there is no need to synchronize all forwarding rules. It is only necessary to synchronize individual forwarding rules, which greatly reduces the resource consumption of the forwarding rule synchronization process.
[0089] When the first forwarding rule does not exist in the local forwarding table and the first forwarding rule exists in the synchronous forwarding table, it means that the connection request is the same connection previously allocated by the second four-layer load balancer, so according to the synchronous forwarding table, the message information of the connection request is forwarded to the second RS backend corresponding to the first forwarding rule.
[0090] When the first forwarding rule exists in the local forwarding table, it means that the connection request is the same connection that was previously allocated by the first four-layer load balancer, so according to the local forwarding table, the message information of the connection request can be forwarded to the second RS backend corresponding to the first forwarding rule. However, in order to determine whether the first forwarding rule is created based on the latest RS hash tree, it is verified whether the first sequence value of the first forwarding rule is equal to the second sequence value of the RS hash tree; if the first sequence value is not equal to the second sequence value, it means that the first forwarding rule is not created based on the latest RS hash tree, so it is further determined whether the RS hash tree is more than the preset time from the last update time point to the current time point. If it exceeds the preset time, the first forwarding rule is synchronized to the second four-layer load balancer through a multicast message. When the second four-layer load balancer receives the message of synchronization of the first forwarding rule, it saves it to the synchronization forwarding table. For details, please refer to Figure 3 synchronization process; if the first sequence value is equal to the second sequence value, it means that the first forwarding rule is created based on the latest RS hash tree, so no synchronization is required.
[0091] In some embodiments, the method comprises:
[0092] When the first four-layer load balancer exits, the RS backend information is deleted;
[0093] Synchronizing exit information to the plurality of second-layer four-layer load balancers, so that the plurality of second-layer four-layer load balancers clear RS backend information of the first-layer four-layer load balancer stored locally, the exit information including the RS backend information;
[0094] When the first four-layer load balancer is restarted, RS backend information is added, and then the RS backend information is fully synchronized to multiple second four-layer load balancers;
[0095] Receive full RS information and target forwarding rules replied by multiple second-layer four-layer load balancers, where the target forwarding rules are forwarding rules in the multiple second-layer four-layer load balancers that are inconsistent with the sequence value of the RS hash tree;
[0096] The full amount of RS information is saved to the target local RS linked list, and the RS hash tree is updated and the target forwarding rule is synchronized, wherein the target local RS linked list is an RS linked list corresponding to the second four-layer load balancer and stored locally in the first four-layer load balancer;
[0097] If the target forwarding rule is synchronized, the OSPF protocol is started to guide the traffic to the first four-layer load balancer.
[0098] In this embodiment, when the first layer 4 load balancer is restarted, it needs to fully synchronize the RS backend information, and the second layer 4 load balancer needs to fully synchronize the forwarding rules that are not created based on the latest RS hash tree to the restarted first layer 4 load balancer; the restarted first layer 4 load balancer waits until the synchronization of other layer 4 load balancers is completed, starts the OSPF protocol component, and then the three-layer switch dispatches the traffic to the restarted first layer 4 load balancer.
[0099] like Figure 6 As shown in the figure, the synchronization process when the four-layer load balancer 1 is restarted:
[0100] When the four-layer load balancer 1 exits, Keepalived notifies the four-layer load balancer 1 to remove the RS information. After all the removals are completed, the four-layer load balancer 1 multicasts the exit message; when other four-layer load balancers (such as the four-layer load balancer 2) receive the message of the four-layer load balancer 1 exiting, they clear all the RS information of the four-layer load balancer 1 saved locally.
[0101] When the four-layer load balancer 1 is restarted, Keepalived fully notifies the four-layer load balancer 1 to add RS information. After the full addition is completed, the four-layer load balancer 1 is fully synchronized to other four-layer load balancers 2 through multicast; after receiving the full RS synchronization of the four-layer load balancer 1, the four-layer load balancer 2 saves the RS information to the local RS linked list of the four-layer load balancer 1, and then updates the RS hash tree, and replies to the four-layer load balancer 1 with its own full RS information; after receiving the full RS information of the four-layer load balancer 2, the four-layer load balancer 1 saves the RS information to the local RS linked list of the four-layer load balancer 2, and then updates the RS hash tree; the four-layer load balancer 2 synchronizes the local forwarding rules that need to be synchronized to the four-layer load balancer 1; after the four-layer load balancer 1 determines that all four-layer load balancers have completed the forwarding rule synchronization, it starts the OPSF protocol to enable the three-layer switch to direct the traffic to the four-layer load balancer 1.
[0102] When the four-layer load balancer of this embodiment is restarted, the consistency of the RS backend is guaranteed by fully synchronizing the RS backend information. At the same time, the restarted four-layer load balancer senses that the other four-layer load balancers have synchronized the forwarding rules before starting OPSF, ensuring that when the switch dispatches the traffic to the restarted load balancer, the forwarding rules have been synchronized.
[0103] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0104] Reference Figure 7 , shows a structural block diagram of a data forwarding device of a four-layer load balancer provided in an embodiment of the present invention, the data forwarding device is applied to a first four-layer load balancer, the first four-layer load balancer and a plurality of second four-layer load balancers form a network group, and the data forwarding device specifically includes the following modules:
[0105] The parsing module 701 is used to receive a connection request and parse the message information of the connection request;
[0106] A query module 702 is used to query a local forwarding table and a synchronous forwarding table according to the message information to see whether there is a first forwarding rule corresponding to the connection request, wherein the local forwarding table is a forwarding table locally created by the first four-layer load balancer, and the synchronous forwarding table is a forwarding table synchronized to the first four-layer load balancer by multiple second four-layer load balancers;
[0107] The acquisition module 703 is used to obtain the backend information corresponding to the first RS backend from the RS hash tree according to the hash value calculated by the message information if the local forwarding table and the synchronous forwarding table do not have the first forwarding rule, wherein the RS hash tree is a hash tree that records the consistency of the RS backend hash values of all four-layer load balancers;
[0108] The creation module 704 is used to create a second forwarding rule corresponding to the connection request according to the backend information and save it to the local forwarding table, and forward the message information to the first RS backend.
[0109] In some embodiments, the device further comprises:
[0110] A first judgment module is used to determine whether a first sequence value of the first forwarding rule is consistent with a second sequence value of the RS hash tree if the first forwarding rule exists in the local forwarding table, the second sequence value is a corresponding accumulated count value of each update of the RS hash value, and the first sequence value is the latest sequence value corresponding to the RS hash tree when the first forwarding rule is created;
[0111] A second judgment module is used to determine whether the time difference between the last update time of the RS hash tree and the current time is greater than a preset time length if the first sequence value is inconsistent with the second sequence value;
[0112] A synchronization module is used to synchronize the forwarding rules in the local forwarding table that are inconsistent with the sequence value of the RS hash tree to multiple second-layer four load balancers if the time difference is greater than the preset duration, and forward the message information to the second RS backend corresponding to the first forwarding rule.
[0113] In some embodiments, the device further comprises:
[0114] A forwarding module is used to forward the message information to a second RS backend corresponding to the first forwarding rule if the first sequence value is consistent with the second sequence value.
[0115] In some embodiments, the forwarding module is further used to:
[0116] If the time difference is not greater than the preset duration, the message information is forwarded to the second RS backend corresponding to the first forwarding rule.
[0117] In some embodiments, the forwarding module is further used to:
[0118] If it is found that the local forwarding table does not contain the first forwarding rule, and the synchronous forwarding table contains the first forwarding rule, the message information of the connection request is forwarded to the second RS backend corresponding to the first forwarding rule.
[0119] In some embodiments, the device further comprises:
[0120] An adding module, used for adding RS backend information when the first four-layer load balancer is restarted, and then synchronizing the RS backend information in full to multiple second four-layer load balancers;
[0121] A receiving module, used to receive the full amount of RS information and target forwarding rules replied by the plurality of second-layer four-layer load balancers, wherein the target forwarding rule is a forwarding rule in the plurality of second-layer four-layer load balancers that is inconsistent with the sequence value of the RS hash tree;
[0122] An update module, configured to save the full RS information to a target local RS linked list, and to update the RS hash tree and synchronize the target forwarding rule, wherein the target local RS linked list is an RS linked list corresponding to the second four-layer load balancer and stored locally in the first four-layer load balancer;
[0123] A startup module is used to start the OSPF protocol if the target forwarding rule is synchronized and completed to guide the traffic to the first four-layer load balancer.
[0124] In some embodiments, the apparatus further comprises:
[0125] A removal module, used for removing the RS backend information when the first four-layer load balancer exits;
[0126] A synchronous clearing module is used to synchronize exit information to multiple second-layer four-layer load balancers so that multiple second-layer four-layer load balancers clear the RS backend information of the first four-layer load balancer stored locally, and the exit information includes the RS backend information.
[0127] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0128] An embodiment of the present invention further provides a computer device, including:
[0129] one or more processors; and
[0130] One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, enable the computer device to perform the method described in the embodiment of the present invention.
[0131] An embodiment of the present invention further provides a computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, enables the processors to execute the method described in the embodiment of the present invention.
[0132] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0133] It should be understood by those skilled in the art that the embodiments of the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, EEPROM, Flash, and eMMC, etc.) containing computer-usable program codes.
[0134] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0135] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0136] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0137] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0138] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0139] The above is a detailed introduction to a data forwarding method for a four-layer load balancer and a data forwarding device for a four-layer load balancer provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for general technicians in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A data forwarding method for a four-layer load balancer, characterized in that: Applied to a first four-layer load balancer, the first four-layer load balancer and a plurality of second four-layer load balancers form a network group, the method comprising: Receiving a connection request and parsing the message information of the connection request; According to the message information, query whether a local forwarding table and a synchronous forwarding table have a first forwarding rule corresponding to the connection request, wherein the local forwarding table is a forwarding table locally created by the first four-layer load balancer, and the synchronous forwarding table is a forwarding table synchronized to the first four-layer load balancer by multiple second four-layer load balancers; If it is found that the first forwarding rule does not exist in the local forwarding table and the synchronous forwarding table, the backend information corresponding to the first RS backend is obtained from the RS hash tree according to the hash value calculated according to the message information, and the RS hash tree is a hash tree that records the consistency of the RS backend hash values of all four-layer load balancers; According to the backend information, a second forwarding rule corresponding to the connection request is created and saved in the local forwarding table, and the message information is forwarded to the first RS backend.
2. The data forwarding method of the four-layer load balancer according to claim 1, characterized in that: After querying the local forwarding table and the synchronous forwarding table according to the message information whether there is a first forwarding rule corresponding to the connection request, the method further includes: If it is found that the first forwarding rule exists in the local forwarding table, determine whether the first sequence value of the first forwarding rule is consistent with the second sequence value of the RS hash tree, the second sequence value is the accumulated count value corresponding to each update of the RS hash value, and the first sequence value is the latest sequence value corresponding to the RS hash tree when the first forwarding rule is created; If the first sequence value is inconsistent with the second sequence value, determining whether the time difference between the last update time of the RS hash tree and the current time is greater than a preset time length; If the time difference is greater than the preset duration, the forwarding rules in the local forwarding table that are inconsistent with the sequence value of the RS hash tree are synchronized to multiple second-layer four load balancers, and the message information is forwarded to the second RS backend corresponding to the first forwarding rule.
3. The data forwarding method of the four-layer load balancer according to claim 2, characterized in that: After determining whether the first sequence value of the first forwarding rule is consistent with the second sequence value of the RS hash tree, the method further includes: If the first sequence value is consistent with the second sequence value, the message information is forwarded to the second RS backend corresponding to the first forwarding rule.
4. The data forwarding method of the four-layer load balancer according to claim 2, characterized in that: After determining whether the time difference between the last update time of the RS hash tree and the current time is greater than a preset time length, the method further includes: If the time difference is not greater than the preset duration, the message information is forwarded to the second RS backend corresponding to the first forwarding rule.
5. The data forwarding method of the four-layer load balancer according to claim 1, characterized in that: After querying the local forwarding table and the synchronous forwarding table according to the message information whether there is a forwarding rule corresponding to the connection request, the method further includes: If it is found that the local forwarding table does not contain the first forwarding rule, and the synchronous forwarding table contains the first forwarding rule, the message information of the connection request is forwarded to the second RS backend corresponding to the first forwarding rule.
6. The data forwarding method of the four-layer load balancer according to claim 1, characterized in that: The method comprises: When the first four-layer load balancer is restarted, RS backend information is added, and then the RS backend information is fully synchronized to multiple second four-layer load balancers; Receive full RS information and target forwarding rules replied by multiple second-layer four-layer load balancers, where the target forwarding rules are forwarding rules in the multiple second-layer four-layer load balancers that are inconsistent with the sequence value of the RS hash tree; The full amount of RS information is saved to the target local RS linked list, and the RS hash tree is updated and the target forwarding rule is synchronized, wherein the target local RS linked list is an RS linked list corresponding to the second four-layer load balancer and stored locally in the first four-layer load balancer; If the target forwarding rule is synchronized and completed, the OSPF protocol is started to guide the traffic to the first four-layer load balancer.
7. The data forwarding method of the four-layer load balancer according to claim 6, characterized in that: Before the first four-layer load balancer is restarted, the method further includes: When the first four-layer load balancer exits, the RS backend information is deleted; Synchronize the exit information to the plurality of the second-layer four load balancers, so that the plurality of the second-layer four load balancers clear the RS backend information of the first-layer four load balancer stored locally, wherein the exit information includes the RS backend information.
8. A data forwarding device for a four-layer load balancer, characterized in that: Applied to a first four-layer load balancer, the first four-layer load balancer and a plurality of second four-layer load balancers form a network group, the device comprising: A parsing module, used for receiving a connection request and parsing message information of the connection request; A query module, configured to query a local forwarding table and a synchronous forwarding table, based on the message information, whether there is a first forwarding rule corresponding to the connection request, wherein the local forwarding table is a forwarding table locally created by the first four-layer load balancer, and the synchronous forwarding table is a forwarding table synchronized to the first four-layer load balancer by multiple second four-layer load balancers; An acquisition module, for obtaining backend information corresponding to the first RS backend from an RS hash tree according to a hash value calculated from the message information if the first forwarding rule does not exist in the local forwarding table and the synchronous forwarding table, wherein the RS hash tree is a hash tree that records the consistency of the RS backend hash values of all four-layer load balancers; A creation module is used to create a second forwarding rule corresponding to the connection request according to the backend information and save it to the local forwarding table, and forward the message information to the first RS backend.
9. A computer device, characterized in that: include: one or more processors; and One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, cause the computer device to perform the method of any one of claims 1-7.
10. A computer-readable storage medium having instructions stored thereon, which, when executed by one or more processors, cause the processors to perform the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and system for forwarding message based on OpenStack cloud platform
CN109361602A
Load balancing method and device, electronic equipment and storage medium
CN119011594A
Load balancing method and apparatus, node, and storage medium
WO2023151264A1
Cited By
Data forwarding method and apparatus for layer 4 load balancer, device, and storage medium
WO2026118891A1