Load balancing method and device for service traffic, electronic equipment and storage medium
Patent Information
- Application Number
- CN202311248067.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-25
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2043-09-25
AI Technical Summary
Achieving consistency in business traffic during load balancing is very difficult, and existing technologies struggle to guarantee the consistency and continuity of business traffic distribution during load balancing.
A load balancer cluster is built using an extended Berkeley packet filter. The consistent hashing algorithm determines the server when business traffic is received for the first time, and uses the load balancer's local data or packets to determine the server when traffic is received for subsequent times. This avoids duplicate hash value calculations and achieves consistency in business traffic.
It achieves consistency of business traffic, improves load balancing efficiency, reduces computation and memory usage, and ensures session maintenance of business traffic.
Smart Images

Figure CN118827675B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of load balancing technology, and more specifically, to a load balancing method, apparatus, storage medium, and electronic device for business traffic. Background Technology
[0002] With the widespread adoption of technologies such as containers and microservices, the demand for inter-service traffic calls and load balancing is increasing. As a core component for distributing and transforming business traffic, load balancing needs to ensure uninterrupted business traffic, consistent distribution, and continuous service even in the event of its own failure or backend service failure. However, achieving business traffic consistency during load balancing is extremely difficult. Business traffic consistency refers to using the same backend server to process the same business traffic.
[0003] Therefore, how to achieve consistency of business traffic during load balancing has become a technical problem that the industry urgently needs to solve. Summary of the Invention
[0004] This application provides a load balancing method, apparatus, storage medium, and electronic device for business traffic, to solve the technical problem of how to achieve consistency of business traffic during the load balancing process in the prior art.
[0005] Firstly, this application provides a load balancing method for business traffic, applied to a load balancer cluster built based on an extended Berkeley packet filter, including:
[0006] Upon receiving the current service traffic for the first time, the server that will process the current service traffic is determined based on the consistent hashing algorithm;
[0007] If the current service traffic is not received for the first time, the server that will process the current service traffic is determined based on the local data of the first load balancer; or, the server that will process the current service traffic is determined based on the data packets received by the first load balancer.
[0008] Wherein, the first load balancer is the load balancer in the load balancer cluster that receives the current service traffic; the local data includes the service traffic received by the first load balancer, and the server assigned by the first load balancer to process the service traffic; the data packet includes the identifier of the first server, which is the server that has processed the current service traffic.
[0009] In some embodiments, determining the server to process the current service traffic based on a consistent hashing algorithm upon first receiving the current service traffic includes:
[0010] Obtain local data from the first load balancer;
[0011] If the current service traffic is not included in the local data, it is determined that the first load balancer receives the current service traffic for the first time.
[0012] The hash value of the current business traffic is determined based on the consistent hashing algorithm;
[0013] The server that processes the current business traffic is determined based on the hash value;
[0014] The current service traffic is associated with the server that processes the current service traffic, and the association result is stored in the local data of the first load balancer.
[0015] In some embodiments, determining the server to process the current service traffic based on a consistent hashing algorithm upon first receiving the current service traffic includes:
[0016] Obtain the data packets of the current service traffic;
[0017] If the header of the data packet does not include the identifier of the first server, it is determined that the current service traffic is being received for the first time.
[0018] Based on the consistent hashing algorithm and the server identifier list stored in the first load balancer, the server that processes the current business traffic is determined.
[0019] The server identifier list is constructed based on the identifiers of servers currently in a normal operating state; the server identifier list is stored in each load balancer in the load balancer cluster; the packet header of the data packet is updated based on the identifier of the server processing the current business traffic, and the updated data packet is stored in the client sending the business traffic.
[0020] In some embodiments, determining the server processing the current service traffic based on local data from the first load balancer, when the current service traffic is not received for the first time, includes:
[0021] The local data of the first load balancer is parsed;
[0022] If the local data includes the current service traffic, it is determined that the first load balancer has received the current service traffic within a historical time period.
[0023] The server associated with the current business traffic in the local data is used as the server to process the current business traffic.
[0024] In some embodiments, determining the server to process the current service traffic based on the data packets received by the first load balancer when the current service traffic is not being received for the first time includes:
[0025] The header of the data packet received by the first load balancer is parsed;
[0026] If the header includes the identifier of the first server, it is determined that the load balancer cluster has received the current service traffic within a historical time period.
[0027] Based on the first server and the server identifier list, the server that will process the current business traffic is determined.
[0028] In some embodiments, the load balancer cluster is constructed based on the following steps:
[0029] Each load balancer is built based on an extended Berkeley packet filter;
[0030] The load balancer cluster is constructed based on each load balancer.
[0031] The service traffic is distributed to each load balancer in the load balancer cluster based on equal-cost routing.
[0032] Secondly, this application provides a load balancing device for business traffic, applied to a load balancer cluster built based on an extended Berkeley packet filter, comprising:
[0033] The first determining module is used to determine the server that will process the current service traffic based on a consistent hashing algorithm when the current service traffic is received for the first time.
[0034] The second determining module is used to determine, based on local data of the first load balancer, the server processing the current service traffic when the current service traffic is not received for the first time; or, based on data packets received by the first load balancer, the server processing the current service traffic.
[0035] Wherein, the first load balancer is the load balancer in the load balancer cluster that receives the current service traffic; the local data includes the service traffic received by the first load balancer, and the server assigned by the first load balancer to process the service traffic; the data packet includes the identifier of the first server, which is the server that has processed the current service traffic.
[0036] In some embodiments, the first determining module is specifically used for:
[0037] Obtain local data from the first load balancer;
[0038] If the current service traffic is not included in the local data, it is determined that the first load balancer receives the current service traffic for the first time.
[0039] The hash value of the current business traffic is determined based on the consistent hashing algorithm;
[0040] The server that processes the current business traffic is determined based on the hash value;
[0041] The current service traffic is associated with the server that processes the current service traffic, and the association result is stored in the local data of the first load balancer.
[0042] In some embodiments, the first determining module is specifically used for:
[0043] Obtain the data packets of the current service traffic;
[0044] If the header of the data packet does not include the identifier of the first server, it is determined that the current service traffic is being received for the first time.
[0045] Based on the consistent hashing algorithm and the server identifier list stored in the first load balancer, the server that processes the current business traffic is determined.
[0046] The server identifier list is constructed based on the identifiers of servers currently in a normal operating state; the server identifier list is stored in each load balancer in the load balancer cluster; the packet header of the data packet is updated based on the identifier of the server processing the current business traffic, and the updated data packet is stored in the client sending the business traffic.
[0047] In some embodiments, the apparatus further includes:
[0048] Build modules for constructing individual load balancers based on extended Berkeley packet filters;
[0049] The load balancer cluster is constructed based on each load balancer.
[0050] The service traffic is distributed to each load balancer in the load balancer cluster based on equal-cost routing.
[0051] Thirdly, this application provides a business traffic processing device, which sequentially connects a client, a router, a load balancer cluster, and multiple servers;
[0052] The client is used to send business traffic;
[0053] The router is used to distribute the service traffic to each load balancer in the load balancer cluster;
[0054] The load balancer cluster is used to execute the load balancing method for the business traffic described above.
[0055] The server is used to process the service traffic.
[0056] Fourthly, embodiments of this application provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to implement the above-described method when executing the program through the computer program.
[0057] Fifthly, embodiments of this application provide a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method.
[0058] Sixthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0059] The service traffic load balancing method, apparatus, electronic device, and storage medium provided in this application embodiment construct a load balancer cluster based on an extended Berkeley packet filter. When the load balancer cluster receives the current service traffic for the first time, it determines the server to process the current service traffic through a consistent hash algorithm. When the current service traffic is received for the second time, it determines the server to process the current service traffic through the local data of the first load balancer or the received data packet. This achieves consistency of service traffic without sharing data among the various load balancers in the load balancer cluster. It also avoids the repeated calculation of hash values, improves the load balancing efficiency of service traffic, and facilitates the maintenance of service traffic sessions. Attached Figure Description
[0060] To more clearly illustrate the technical solutions in this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0061] Figure 1 One of the flowcharts for a load balancing method for service traffic provided in an embodiment of this application;
[0062] Figure 2 A second schematic flowchart of the service traffic load balancing method provided in the embodiments of this application;
[0063] Figure 3 The third flowchart illustrates the load balancing method for service traffic provided in the embodiments of this application.
[0064] Figure 4 A schematic diagram of the structure of a load balancing device for service traffic provided in the embodiments of this application;
[0065] Figure 5 This is a schematic diagram of the structure of the service traffic processing device provided in the embodiments of this application;
[0066] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0067] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0068] Figure 1 This is one of the flowcharts illustrating the load balancing method for service traffic provided in the embodiments of this application, such as... Figure 1 As shown, the method includes steps 110 and 120. These method steps are merely one possible implementation of this application.
[0069] Step 110: Upon receiving the current business traffic for the first time, determine the server that will process the current business traffic based on the consistent hashing algorithm.
[0070] Specifically, the execution subject of the service traffic load balancing method provided in this application embodiment is a service traffic load balancing device, which can be a load balancer cluster.
[0071] A load balancer cluster can consist of multiple load balancers, which are built based on the Extended Berkeley Packet Filter (eBPF).
[0072] The current business traffic refers to the business traffic currently received by the load balancer cluster. Business traffic can be traffic or requests that need to be processed by the server.
[0073] When the load balancer cluster receives the current business traffic for the first time, it can calculate the hash value of the current business traffic using a consistent hashing algorithm. Based on the hash value of the current business traffic, it can determine the server that will handle the current business traffic, which can be a backend server.
[0074] Once the load balancing server cluster has determined which server will handle the current business traffic, it can send the current business traffic to that server, which will then process the current business traffic.
[0075] Step 120: If the current service traffic is not received for the first time, determine the server that will handle the current service traffic based on the local data of the first load balancer; or, determine the server that will handle the current service traffic based on the data packets received by the first load balancer.
[0076] The first load balancer is the load balancer in the load balancer cluster that receives the current business traffic; the local data includes the business traffic received by the first load balancer and the servers assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, which is the server that has processed the current business traffic.
[0077] Specifically, when the load balancer cluster receives the current service traffic for the first time, in order to avoid repeatedly calculating the hash value of the current service traffic, it can quickly determine the server that handles the current service traffic in the following two ways.
[0078] (1) Each load balancer in the load balancer cluster maintains a local cache and determines the server for the current business traffic based on the data cached in the local cache.
[0079] Each load balancer's local cache stores established business traffic and connection information between the server and the load balancer.
[0080] For example, a router sends service traffic to any load balancer in a load server cluster; this load balancer is referred to as the first load balancer. After the first load balancer forwards the received service traffic to a server, the server processes the traffic, thus establishing a connection between the service traffic and the server. Therefore, the first load balancer's local cache stores the service traffic it has received, as well as the servers assigned by the first load balancer to process that traffic.
[0081] The data cached in the local cache is the local data. Therefore, if the first load balancer is not receiving the current service traffic for the first time, its local data will include the current service traffic and the server that has processed the current service traffic, as assigned by the first load balancer. The first load balancer can directly send the current service traffic to the server that has processed the current service traffic based on the local data, so that even if the current service traffic is assigned multiple times, it can be processed through the same server, thus facilitating the maintenance of all sessions for the current service traffic.
[0082] Because the local data is cached in the first load balancer and is not shared with other load balancers in the load balancer cluster, when the load balancer cluster receives the current business traffic for the first time, but the first load balancer receives the current business traffic for the first time, the first load balancer still needs to calculate the hash value of the current business traffic. However, when the load balancer cluster receives the current business traffic for the first time, and the first load balancer also receives the current business traffic for the first time, the first load balancer does not need to calculate the hash value of the current business traffic.
[0083] Therefore, in order to further reduce the computational load of the load balancer cluster, this application embodiment further provides a method (2), as follows:
[0084] (2) Assign a unique Security Identifier (SID) to each server and use the SID as the identifier to identify the server. Based on the identifier of the server that has processed the current business traffic and the current business traffic, construct the data packet of the current business traffic. Based on the data packet received by the first load balancer, determine the server that processes the current business traffic.
[0085] Data packets can be stored on the client. If the load balancer cluster is not receiving the current service traffic for the first time, the client will store the data packets of the current service traffic. When the client sends the current service traffic, it sends the data packet to the router, and the router then sends the data packet to the first load balancer in the load balancer cluster. The first load balancer parses the data packet to determine the server that has processed the current service traffic.
[0086] Because the data packet carries the identifier of the server that has processed the current business traffic (i.e., the identifier of the first server), and the data packet is stored on the client, the data packet can be assigned to a server by any load balancer in the load balancer cluster. The load balancer server can determine the server that has processed the current business traffic through the data packet.
[0087] Therefore, the server that has processed the current service traffic can be assigned by the first load balancer or not. That is, if the first load balancer becomes unavailable due to a failure or upgrade, the server that processed the current service traffic can still be quickly identified based on the identifier in the data packet, even if other load balancers in the load balancer cluster distribute the current service traffic. In other words, as long as there is a load balancer in the load balancer cluster that has previously calculated the hash value of the current service traffic, when the same service traffic is sent to the load balancer cluster again, regardless of which load balancer in the cluster it is sent to, there is no need to recalculate the hash value of the current service traffic.
[0088] The two methods mentioned above can be randomly selected according to the actual situation. For example, method (1) can be selected when all load balancers in the load balancer cluster are running normally; method (2) can be selected when some load balancers in the load balancer cluster are being upgraded, maintained or have failed.
[0089] The load balancing method for service traffic provided in this application constructs a load balancer cluster based on an extended Berkeley packet filter. When the load balancer cluster receives the current service traffic for the first time, it determines the server to process the current service traffic using a consistent hash algorithm. When it receives the current service traffic for the second time, it determines the server to process the current service traffic using the local data of the first load balancer or the received data packet. This achieves consistency of service traffic without sharing data among the various load balancers in the load balancer cluster. It also avoids the repeated calculation of hash values, improves the load balancing efficiency of service traffic, and facilitates the maintenance of service traffic sessions.
[0090] It should be noted that each implementation method of this application can be freely combined, rearranged, or executed individually, and does not need to rely on or depend on a fixed execution order.
[0091] In some embodiments, the load balancer cluster is built based on the following steps:
[0092] Each load balancer is built based on an extended Berkeley packet filter;
[0093] Build a load balancer cluster based on each load balancer;
[0094] In this process, business traffic is distributed to the various load balancers in the load balancer cluster based on equal-cost routing.
[0095] Specifically, a load balancer cluster can be formed by multiple load balancers built using eBPF.
[0096] You can write eBPF programs that are executed when events such as LISTEN, CONNECT, or CONN_ESTD are triggered, thereby running the load balancer.
[0097] Load balancers in a load balancer cluster can distribute service traffic using Equal Cost Multi Path (ECMP) routing through routers connected to the network. This ensures that service traffic is evenly distributed across all load balancers in the cluster. Furthermore, in the event of upgrades, maintenance, or failures of one or more load balancers, service traffic can be redistributed to other available load balancers in the cluster, achieving high availability. The Equal Cost Multi Path routing in this embodiment is also referred to as equal cost routing.
[0098] The service traffic load balancing method provided in this application improves load balancing efficiency by constructing a load balancer using eBPF, constructing a load balancer cluster using multiple load balancers, and allocating service traffic through equal-cost routing. This enables the service traffic load balancing device to have high availability.
[0099] In some embodiments, step 110 includes:
[0100] Obtain local data from the first load balancer;
[0101] If the current business traffic is not included in the local data, determine when the first load balancer first receives the current business traffic.
[0102] The hash value of the current business traffic is determined based on the consistent hashing algorithm;
[0103] The server that will handle the current business traffic is determined based on the hash value;
[0104] Associate the current business traffic with the server that processes the current business traffic, and store the association result in the local data of the first load balancer.
[0105] Specifically, after the router sends the current service traffic to the first load balancer in the load balancer cluster, the first load balancer will obtain local data. Since the local data includes the service traffic that the first load balancer has received, if the local data does not include the current service traffic, it indicates that the first load balancer is receiving the current service traffic for the first time.
[0106] The first load balancer can calculate the hash value of the current business traffic using a consistent hashing algorithm, and then select a server based on the hash value. This server selection process can be implemented using pseudocode.
[0107] For example, the logic for selecting a backend server in pseudocode, where current business traffic is allocated in the form of data packets, is as follows:
[0108] Select backend host (data packet) {
[0109] If the destination server of the data packet has a record in its local cache.
[0110] Return to local cache (data packet)
[0111] Otherwise, return a consistent hash (data packet) % server hash ring; record to local cache.
[0112] }
[0113] After the first load balancer in the load balancer cluster assigns a server to the current business traffic, it associates the current business traffic with the server that processes the current business traffic and stores the association result in the local data of the first load balancer. That is, the current business traffic that establishes a connection and the server that processes the current business traffic are cached in the local cache of the first load balancer.
[0114] Therefore, when the first load balancer receives the same traffic again, it does not need to recalculate the hash value; it can determine which server to distribute the traffic to using local data.
[0115] Furthermore, since this application embodiment only stores the business traffic and the connection relationship established by the server in the local data of the first load balancer, and does not share this data with other load balancers in the load balancer cluster, the operating burden of the load balancer cluster is reduced, as is the memory usage.
[0116] The load balancing method for service traffic provided in this application stores the current service traffic and the server in local data when the current service traffic is received for the first time. This eliminates the need to repeatedly calculate the hash value of the service traffic when the same service traffic is received, thereby reducing the operating burden of the load balancer cluster, reducing memory usage, and improving load balancing efficiency.
[0117] In some embodiments, step 120 includes:
[0118] Parse the local data of the first load balancer;
[0119] If the local data includes the current business traffic, determine whether the first load balancer has received the current business traffic within a historical time period.
[0120] The server associated with the current business traffic in the local data will be used as the server to process the current business traffic.
[0121] Specifically, the first load balancer in the load balancer cluster parses the local data. Since the local data includes the service traffic that the first load balancer has received, if the local data includes the current service traffic, it indicates that the first load balancer is not receiving the current service traffic for the first time.
[0122] As the load balancer runs, the amount of local data will continue to increase, and the structure of the load balancer cluster and servers may change after a long time interval. Therefore, it is possible to retain only the local data within a certain period of time, or to set a data volume threshold to manage the local data.
[0123] Therefore, the first load balancer is not receiving the current service traffic for the first time; that is, the first load balancer has received the current service traffic within a historical time period. The first load balancer can directly obtain the server that has established a connection with the current service traffic through local data and use that server as the server to process the current service traffic.
[0124] The load balancing method for service traffic provided in this application embodiment determines the server to process the current service traffic directly based on local data when the first load balancer receives the current service traffic for the first time, thereby reducing the computational load of the load balancer and improving the load balancing efficiency of service traffic.
[0125] In some embodiments, step 110 includes:
[0126] Retrieve the data packets of the current business traffic;
[0127] If the header of the data packet does not include the identifier of the first server, determine that the current service traffic is being received for the first time;
[0128] Based on the consistent hashing algorithm and the server identifier list stored in the first load balancer, the server that handles the current business traffic is determined.
[0129] The server identifier list is constructed based on the identifiers of servers currently in a normal operating state; the server identifier list is stored in each load balancer in the load balancer cluster; the packet header is updated based on the identifier of the server processing the current business traffic, and the updated packet is stored in the client sending the business traffic.
[0130] Specifically, each backend server can be assigned an identifier, which is then used as routing information for data packets and written into the Transmission Control Protocol (TCP) header. Taking SID as an example, the packet header structure includes: |Type|Length|SID|. Writing the identifier into the header allows clients and the load balancing cluster to quickly obtain the server's identifier directly from the packet header without needing to parse the data packets, thus enabling them to identify the server based on the identifier.
[0131] Figure 2 This is the second flowchart illustrating the load balancing method for service traffic provided in the embodiments of this application. Figure 2 As shown, a local cache of a server identifier list can be maintained on each load balancer in the load balancing server cluster. The server identifier list records the identifiers of the currently running servers, as well as the server information corresponding to each identifier.
[0132] A synchronization process can be set up to synchronize the server identifier list to each load balancer in the load balancing server cluster, ensuring that the server identifier list is the same on each load balancer, and to update the server identifier list according to the server's running status.
[0133] eBPF programs can obtain the TCP header information of data packets and then write the server SID into the data packet as routing information, or read the SID from the data packet header as routing information.
[0134] The first load balancer in the load balancing server cluster can obtain the current business traffic data packets according to the eBPF program, because the data packets will include the identifier of the server that has processed the current business traffic, that is, the identifier of the first server.
[0135] If the header of the current data packet does not include the identifier of the first server, it indicates that the load balancer server cluster is receiving the current business traffic for the first time. It can calculate the hash value of the current business traffic according to the consistent hashing algorithm, and then select an identifier from the list of server identifiers stored in the first load balancer based on the hash value. The server that will handle the current business traffic is determined based on the selected identifier.
[0136] After the first load balancer identifies the server that will handle the current business traffic, it writes the server's identifier into a data packet and sends the data packet to that server.
[0137] After receiving the data packet, the server will obtain its own identifier, write the value of the identifier into the TCP header, and send the data packet with the identifier value to the client.
[0138] After receiving a data packet, the client retrieves an identifier from the packet header and saves it. When a client generates the same service traffic, the header of the data packet generating that service traffic will include the identifier of the first server. Thus, the first load balancer can directly determine the server to process the current service traffic based on the packet header.
[0139] The load balancing method for service traffic provided in this application improves load balancing efficiency by storing the server's identifier in the header of the data packet and storing the identifier on the client. This ensures that when the load balancer cluster receives the same service traffic again, the header of the received data packet directly includes the identifier of the server that processes the service traffic, eliminating the need to recalculate the hash value of the service traffic.
[0140] In some embodiments, step 120 includes:
[0141] Parse the header of the data packets received by the first load balancer;
[0142] If the header includes the identifier of the first server, it can be determined that the load balancer cluster has received the current service traffic within a historical time period.
[0143] Based on the first server and the server identifier list, determine the server that will handle the current business traffic.
[0144] Specifically, when the load balancing server cluster receives current business traffic for the first time, the header of the data packet received by the first load balancer will include the identifier of the first server.
[0145] The first load balancer parses the TCP header information of the data packets, extracts the identifier of the first server, and queries the server identifier list. If the server identifier list includes the identifier of the first server, it indicates that the first server is currently running normally. Then, the data packets of the current business traffic can be sent to the first server, which will then process the current business traffic again.
[0146] The load balancing method for service traffic provided in this application determines the server that processes the current service traffic by using the packet header and server identifier list. This avoids the same service traffic from repeatedly calculating hash values when it is allocated to different load balancers, and also avoids the load balancer from allocating service traffic to servers that are not functioning properly. This improves load balancing efficiency and achieves consistency of service traffic.
[0147] Figure 3 This is the third flowchart illustrating the load balancing method for service traffic provided in the embodiments of this application. Figure 3 As shown, the method includes:
[0148] Step 1: In response to the current business traffic, the client initiates a Synchronize Sequence Number (SYN).
[0149] Step 2: Determine the load balancing server cluster to receive the current business traffic for the first time, select a backend server for the current business traffic using the consistent hashing algorithm, and then forward the data packets of the current business traffic to that backend server.
[0150] Step 3: The backend server obtains its identifier, SID, from the data packet. Taking SID = 2 as an example, the value 2 is written into the TCP header of the data packet. The backend server responds with a Synchronize Sequence Numbers-Acknowledgment (SYN-ACK) to the client, and the eBPF program on the backend server embeds the SID into the TCP header.
[0151] Step 4: After receiving the data packet, the client parses and saves the SID embedded in the TCP header. When sending subsequent data packets containing the same business traffic as the current business traffic, the client will embed the SID in the header.
[0152] If, during the operation of the load balancer for business traffic, the load balancer (load balancer 1) that previously distributed the business traffic is undergoing upgrades, maintenance, or a failure, the handling procedure is as follows:
[0153] According to the router's ECMP algorithm, the packets of service traffic will be forwarded to another load balancer in the load balancer cluster, such as load balancer 2.
[0154] Step 5: Load balancer 2 parses the TCP header information of the data packet, extracts the SID, and queries the server identifier list. If it is determined that the backend server with SID 2 is still running normally, the data packet of the business traffic is directly sent to the backend server with SID 2 for processing.
[0155] The load balancing method for service traffic provided in this application has the following advantages:
[0156] (1) is a completely stateless method, meaning that there is no need to share a centralized or distributed cache among the various load balancers. It does not introduce the overhead of external cache access or the complexity and stability issues brought about by distribution, and can achieve unlimited horizontal scaling.
[0157] (2) The distribution of business traffic is based on eBPF program, which has very low overhead. The backend server that processes business traffic can be determined by the packet header, without the need to identify the content of the packet, which further reduces additional overhead and improves load balancing efficiency.
[0158] The load balancing device for service traffic provided in the embodiments of this application will be described below. The load balancing device for service traffic described below can be referred to in correspondence with the load balancing method for service traffic described above.
[0159] The parsing performance testing device provided in the embodiments of this application is described below. The parsing performance testing device described below and the load balancing method for service traffic described above can be referred to in correspondence.
[0160] Figure 4 A schematic diagram of the structure of the load balancing device for service traffic provided in the embodiments of this application is shown below. Figure 4 As shown, the device is applied to a load balancer cluster built on an extended Berkeley packet filter and includes a first determining module 410 and a second determining module 420.
[0161] The first determining module is used to determine the server that will handle the current business traffic based on a consistent hashing algorithm when the current business traffic is received for the first time.
[0162] The second determining module is used to determine the server that processes the current business traffic based on the local data of the first load balancer when the current business traffic is not received for the first time; or, based on the data packets received by the first load balancer, to determine the server that processes the current business traffic.
[0163] The first load balancer is the load balancer in the load balancer cluster that receives the current business traffic; the local data includes the business traffic received by the first load balancer and the servers assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, which is the server that has processed the current business traffic.
[0164] Specifically, according to the embodiments of this application, any multiple modules in the first determining module and the second determining module can be combined into one module, or any one of the modules can be split into multiple modules.
[0165] Alternatively, at least some of the functionality of one or more of these modules can be combined with at least some of the functionality of other modules and implemented in a single module.
[0166] According to embodiments of this application, at least one of the first determining module and the second determining module can be at least partially implemented as a hardware circuit, such as a field-programmable gate array (FPGA), a programmable logic array (PLA), a system-on-a-chip, a system-on-a-substrate, a system-on-package, an application-specific integrated circuit (ASIC), or implemented by any other reasonable means of integrating or packaging the circuit, or implemented by any one of the three implementation methods of software, hardware, and firmware, or by any appropriate combination of any of them.
[0167] Alternatively, at least one of the first determining module and the second determining module can be at least partially implemented as a computer program module, which can perform corresponding functions when the computer program module is run.
[0168] The load balancing device for service traffic provided in this application embodiment constructs a load balancer cluster based on an extended Berkeley packet filter. When the load balancer cluster receives the current service traffic for the first time, it determines the server to process the current service traffic through a consistent hash algorithm. When the current service traffic is received for the second time, it determines the server to process the current service traffic through the local data of the first load balancer or the received data packet. This achieves consistency of service traffic without sharing data among the various load balancers in the load balancer cluster. It also avoids the repeated calculation of hash values, improves the load balancing efficiency of service traffic, and facilitates the maintenance of service traffic sessions.
[0169] In some embodiments, the first determining module is specifically used for:
[0170] Obtain local data from the first load balancer;
[0171] If the current business traffic is not included in the local data, determine when the first load balancer first receives the current business traffic.
[0172] The hash value of the current business traffic is determined based on the consistent hashing algorithm;
[0173] The server that will handle the current business traffic is determined based on the hash value;
[0174] Associate the current business traffic with the server that processes the current business traffic, and store the association result in the local data of the first load balancer.
[0175] In some embodiments, the first determining module is specifically used for:
[0176] Retrieve the data packets of the current business traffic;
[0177] If the header of the data packet does not include the identifier of the first server, determine that the current service traffic is being received for the first time;
[0178] Based on the consistent hashing algorithm and the server identifier list stored in the first load balancer, the server that handles the current business traffic is determined.
[0179] The server identifier list is constructed based on the identifiers of servers currently in a normal operating state; the server identifier list is stored in each load balancer in the load balancer cluster; the packet header is updated based on the identifier of the server processing the current business traffic, and the updated packet is stored in the client sending the business traffic.
[0180] In some embodiments, the second determining module is specifically used for:
[0181] Parse the local data of the first load balancer;
[0182] If the local data includes the current business traffic, determine whether the first load balancer has received the current business traffic within a historical time period.
[0183] The server associated with the current business traffic in the local data will be used as the server to process the current business traffic.
[0184] In some embodiments, the second determining module is specifically used for:
[0185] Parse the header of the data packets received by the first load balancer;
[0186] If the header includes the identifier of the first server, it can be determined that the load balancer cluster has received the current service traffic within a historical time period.
[0187] Based on the first server and the server identifier list, determine the server that will handle the current business traffic.
[0188] In some embodiments, the load balancing device for service traffic further includes a construction module, which is used to:
[0189] Each load balancer is built based on an extended Berkeley packet filter;
[0190] Build a load balancer cluster based on each load balancer;
[0191] In this process, business traffic is distributed to the various load balancers in the load balancer cluster based on equal-cost routing.
[0192] It should be noted that the load balancing device for service traffic provided in this application embodiment can implement all the method steps implemented in the above-mentioned service traffic load balancing method embodiment and can achieve the same technical effect. Here, the parts that are the same as those in the method embodiment and the beneficial effects will not be described in detail.
[0193] Figure 5 This is a schematic diagram of the structure of the service traffic processing device provided in the embodiments of this application; as shown below. Figure 5 As shown, the business traffic processing device includes a client 510, a router 520, a load balancer cluster 530, and multiple backend servers 540 connected in sequence.
[0194] The client is used to send business traffic;
[0195] Routers are used to distribute business traffic to various load balancers in a load balancer cluster;
[0196] A load balancer cluster is used to perform the load balancing method for the business traffic described above.
[0197] Backend servers are used to process business traffic.
[0198] Figure 6 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application, such as... Figure 6 As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630, and a communication bus 640, wherein the processor 610, the communication interface 620, and the memory 630 communicate with each other via the communication bus 640. The processor 610 can call a computer program stored in the memory 630 to execute the above-described methods, such as including:
[0199] Upon receiving the current business traffic for the first time, the server that will handle the current business traffic is determined based on the consistent hashing algorithm;
[0200] If the current service traffic is not received for the first time, the server that will handle the current service traffic is determined based on the local data of the first load balancer; or, the server that will handle the current service traffic is determined based on the data packets received by the first load balancer.
[0201] The first load balancer is the load balancer in the load balancer cluster that receives the current business traffic; the local data includes the business traffic received by the first load balancer and the servers assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, which is the server that has processed the current business traffic.
[0202] Furthermore, the logical instructions in the aforementioned memory 630 can be implemented as software functional modules and sold or used as independent products, and can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0203] On the other hand, embodiments of this application also provide a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can perform the methods provided in the above embodiments, such as including:
[0204] Upon receiving the current business traffic for the first time, the server that will handle the current business traffic is determined based on the consistent hashing algorithm;
[0205] If the current service traffic is not received for the first time, the server that will handle the current service traffic is determined based on the local data of the first load balancer; or, the server that will handle the current service traffic is determined based on the data packets received by the first load balancer.
[0206] The first load balancer is the load balancer in the load balancer cluster that receives the current business traffic; the local data includes the business traffic received by the first load balancer and the servers assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, which is the server that has processed the current business traffic.
[0207] On the other hand, embodiments of this application also provide a processor-readable storage medium storing a computer program for causing a processor to execute the methods provided in the above embodiments, such as including:
[0208] Upon receiving the current business traffic for the first time, the server that will handle the current business traffic is determined based on the consistent hashing algorithm;
[0209] If the current service traffic is not received for the first time, the server that will handle the current service traffic is determined based on the local data of the first load balancer; or, the server that will handle the current service traffic is determined based on the data packets received by the first load balancer.
[0210] The first load balancer is the load balancer in the load balancer cluster that receives the current business traffic; the local data includes the business traffic received by the first load balancer and the servers assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, which is the server that has processed the current business traffic.
[0211] The processor-readable storage medium can be any available medium or data storage device that the processor can access, including but not limited to magnetic memory (e.g., floppy disk, hard disk, magnetic tape, magneto-optical disk (MO)), optical memory (e.g., CD, DVD, BD, HVD), and semiconductor memory (e.g., ROM, EPROM, EEPROM, non-volatile memory (NAND FLASH), solid-state drive (SSD)).
[0212] The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0213] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0214] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A load balancing method for business traffic, characterized in that, The method, applied to a load balancer cluster built on an extended Berkeley packet filter, includes: Upon receiving the current service traffic for the first time, the server that processes the current service traffic is determined based on the consistent hashing algorithm, and the packet header of the current service traffic data packet is updated based on the identifier of the server that processes the current service traffic, so that the updated data packet is sent and stored in the client that sent the current service traffic; If the current service traffic is not received for the first time, the server that will process the current service traffic is determined based on the local data of the first load balancer; or, the server that will process the current service traffic is determined based on the data packets received by the first load balancer. Wherein, the first load balancer is the load balancer in the load balancer cluster that receives the current service traffic; the local data includes the service traffic received by the first load balancer, and the server assigned by the first load balancer to process the service traffic; the data packet includes the identifier of the first server, which is the server that has processed the current service traffic. Specifically, determining the server to process the current service traffic based on the data packets received by the first load balancer when the current service traffic is not being received for the first time includes: By parsing the header of the data packet, the identifier of the first server carried in the data packet is obtained, and the server that processes the current business traffic is determined based on the identifier of the first server. Upon first receiving current service traffic, the header of the current service traffic data packet is updated based on the identifier of the server processing the current service traffic, so that the updated data packet is sent and stored in the client sending the current service traffic, including: The identifier of the server processing the current service traffic is written into the data packet of the current service traffic, and the data packet of the current service traffic is sent to the server processing the current service traffic. After receiving the data packet of the current service traffic, the server processing the current service traffic obtains its own identifier, writes the server's own identifier into the header of the transmission control protocol, and sends the data packet with the server's own identifier written into it to the client. After receiving the data packet with the server's own identifier written into it, the client obtains and saves the server's own identifier from the header, and includes the server's own identifier in the header of the data packet of the same service traffic generated. If the load balancer that previously allocated the current service traffic is upgraded, under maintenance, or fails, the data packets of the service traffic will be forwarded to another load balancer in the load balancer cluster according to the router's equal-cost multi-path routing algorithm.
2. The load balancing method for service traffic according to claim 1, characterized in that, The step of determining the server to process the current service traffic based on a consistent hashing algorithm upon first receiving the current service traffic includes: Obtain local data from the first load balancer; If the current service traffic is not included in the local data, it is determined that the first load balancer receives the current service traffic for the first time. The hash value of the current business traffic is determined based on the consistent hashing algorithm; The server that processes the current business traffic is determined based on the hash value; The current service traffic is associated with the server that processes the current service traffic, and the association result is stored in the local data of the first load balancer.
3. The load balancing method for service traffic according to claim 1, characterized in that, The step of determining the server to process the current service traffic based on a consistent hashing algorithm upon first receiving the current service traffic includes: Obtain the data packets of the current service traffic; If the header of the data packet does not include the identifier of the first server, it is determined that the current service traffic is being received for the first time. Based on the consistent hashing algorithm and the server identifier list stored in the first load balancer, the server that processes the current business traffic is determined. The server identifier list is constructed based on the identifiers of servers currently in a normal operating state; the server identifier list is stored in each load balancer in the load balancer cluster.
4. The load balancing method for service traffic according to claim 2, characterized in that, In cases where the current service traffic is not received for the first time, determining the server to process the current service traffic based on local data from the first load balancer includes: The local data of the first load balancer is parsed; If the local data includes the current service traffic, it is determined that the first load balancer has received the current service traffic within a historical time period. The server associated with the current business traffic in the local data is used as the server to process the current business traffic.
5. The load balancing method for service traffic according to claim 3, characterized in that, In cases where the current service traffic is not received for the first time, determining the server to process the current service traffic based on the data packets received by the first load balancer includes: The header of the data packet received by the first load balancer is parsed; If the header includes the identifier of the first server, it is determined that the load balancer cluster has received the current service traffic within a historical time period. Based on the first server and the server identifier list, the server that will process the current business traffic is determined.
6. The load balancing method for service traffic according to any one of claims 1-5, characterized in that, The load balancer cluster is built based on the following steps: Each load balancer is built based on an extended Berkeley packet filter; The load balancer cluster is constructed based on each load balancer. The service traffic is distributed to each load balancer in the load balancer cluster based on equal-cost routing.
7. A load balancing device for business traffic, characterized in that, Applications include load balancer clusters built on an extended Berkeley packet filter, including: The first determining module is used to determine the server that processes the current service traffic based on a consistent hashing algorithm when the current service traffic is received for the first time, and to update the packet header of the current service traffic data packet based on the identifier of the server that processes the current service traffic, so that the updated data packet is sent and stored in the client that sends the current service traffic. The second determining module is used to determine, based on local data of the first load balancer, the server processing the current service traffic when the current service traffic is not received for the first time; or, based on data packets received by the first load balancer, the server processing the current service traffic. Wherein, the first load balancer is the load balancer in the load balancer cluster that receives the current service traffic; the local data includes the service traffic received by the first load balancer, and the server assigned by the first load balancer to process the service traffic; the data packet includes the identifier of the first server, which is the server that has processed the current service traffic. Specifically, determining the server to process the current service traffic based on the data packets received by the first load balancer when the current service traffic is not being received for the first time includes: By parsing the header of the data packet, the identifier of the first server carried in the data packet is obtained, and the server that processes the current business traffic is determined based on the identifier of the first server. Upon first receiving current service traffic, the header of the current service traffic data packet is updated based on the identifier of the server processing the current service traffic, so that the updated data packet is sent and stored in the client sending the current service traffic, including: The identifier of the server processing the current service traffic is written into the data packet of the current service traffic, and the data packet of the current service traffic is sent to the server processing the current service traffic. After receiving the data packet of the current service traffic, the server processing the current service traffic obtains its own identifier, writes the server's own identifier into the header of the transmission control protocol, and sends the data packet with the server's own identifier written into it to the client. After receiving the data packet with the server's own identifier written into it, the client obtains and saves the server's own identifier from the header, and includes the server's own identifier in the header of the data packet of the same service traffic generated. If the load balancer that previously allocated the current service traffic is upgraded, under maintenance, or fails, the data packets of the service traffic will be forwarded to another load balancer in the load balancer cluster according to the router's equal-cost multi-path routing algorithm.
8. The load balancing device for service traffic according to claim 7, characterized in that, The first determining module is specifically used for: Obtain local data from the first load balancer; If the current service traffic is not included in the local data, it is determined that the first load balancer receives the current service traffic for the first time. The hash value of the current business traffic is determined based on the consistent hashing algorithm; The server that processes the current business traffic is determined based on the hash value; The current service traffic is associated with the server that processes the current service traffic, and the association result is stored in the local data of the first load balancer.
9. The load balancing device for service traffic according to claim 7, characterized in that, The first determining module is specifically used for: Obtain the data packets of the current service traffic; If the header of the data packet does not include the identifier of the first server, it is determined that the current service traffic is being received for the first time. Based on the consistent hashing algorithm and the server identifier list stored in the first load balancer, the server that processes the current business traffic is determined. The server identifier list is constructed based on the identifiers of servers currently in a normal operating state; the server identifier list is stored in each load balancer in the load balancer cluster.
10. The load balancing device for service traffic according to any one of claims 7-9, characterized in that, The device further includes: Build modules for constructing individual load balancers based on extended Berkeley packet filters; The load balancer cluster is constructed based on each load balancer. The service traffic is distributed to each load balancer in the load balancer cluster based on equal-cost routing.
11. A business traffic processing device, characterized in that, This includes clients, routers, a load balancer cluster, and multiple servers connected in sequence; The client is used to send business traffic; The router is used to distribute the service traffic to each load balancer in the load balancer cluster; The load balancer cluster is used to perform the load balancing method for service traffic as described in any one of claims 1 to 6; The server is used to process the service traffic.
12. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to execute the load balancing method for service traffic as described in any one of claims 1 to 6 through the computer program.
13. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the load balancing method for service traffic as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Load balancing method, device and system based on address forwarding
CN107070983A
Multi-cluster load balancing method and device, electronic equipment and storage medium
CN115987990A
Data packet sending method and device, equipment and storage medium
CN116582544A
