Load balancing method and device for service traffic, electronic equipment and storage medium
By using the consistent hash algorithm and local data or packet identification in the load balancer cluster to determine the processing server, the problem of business traffic consistency in load balancing is solved, and the load balancing efficiency and business session maintenance capabilities are improved.
Patent Information
- Application Number
- CN202311248067.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-25
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2043-09-25
AI Technical Summary
In the load balancing process, it is very difficult to achieve consistency of business traffic. It is difficult for existing technology to ensure the consistency of distribution and business continuity of business traffic during the load balancing process.
By applying a consistent hash algorithm in the load balancer cluster to determine the processing server when receiving business traffic for the first time, and determining the processing server based on local data or server identification in the data packet when receiving business traffic for the first time, avoiding repeated calculation of hash values, Achieve consistent distribution of business traffic.
It achieves consistent distribution of business traffic, improves load balancing efficiency, facilitates session maintenance of business traffic, avoids repeated calculation of hash values, and reduces the calculation amount and memory usage of the load balancer cluster.
Smart Images

Figure CN118827675A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of load balancing, and in particular to a method, device, storage medium and electronic device for load balancing of business traffic. Background Art
[0002] With the widespread application of technologies such as containers and microservices, there is an increasing demand for mutual calls and load balancing between business flows. As a core component for business flow distribution and conversion, load balancing needs to ensure that business flows are not interrupted, distribution is consistent, and business continuity is achieved in the event of its own failures and backend service failures. However, in related technologies, it is very difficult to achieve consistency in business flows during the load balancing process. Business flow consistency means using the same backend server to process the same business flow.
[0003] Therefore, how to achieve consistency of business traffic during the load balancing process has become a technical problem that needs to be solved urgently in the industry. Summary of the invention
[0004] The present application provides a method, device, storage medium and electronic device for load balancing of business traffic, which are used to solve the technical problem of how to achieve consistency of business traffic in the load balancing process in the prior art.
[0005] In a first aspect, the present application provides a method for load balancing service traffic, which is applied to a load balancer cluster built based on an extended Berkeley packet filter, including:
[0006] When receiving the current business traffic for the first time, determining a server for processing the current business traffic based on a consistent hashing algorithm;
[0007] In the case where the current service traffic is not received for the first time, determining the server that processes the current service traffic based on the local data of the first load balancer; or determining the server that processes the current service traffic based on the data packet received by the first load balancer;
[0008] Among them, 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 server assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, and the first server is the server that has processed the current business traffic.
[0009] In some embodiments, when receiving the current service traffic for the first time, determining the server for processing the current service traffic based on the consistent hashing algorithm includes:
[0010] Obtaining local data of the first load balancer;
[0011] In a case where the local data does not include the current service traffic, determining that the first load balancer receives the current service traffic for the first time;
[0012] Determine a hash value of the current service flow based on a consistent hashing algorithm;
[0013] Determine a server that processes the current service traffic based on the hash value;
[0014] The current business traffic is associated with a server that processes the current business traffic, and the association result is stored in local data of the first load balancer.
[0015] In some embodiments, when receiving the current service traffic for the first time, determining the server for processing the current service traffic based on the consistent hashing algorithm includes:
[0016] Obtaining data packets of the current service flow;
[0017] In a case where the header of the data packet does not include the identifier of the first server, determining that the current service traffic is received for the first time;
[0018] Determine a server that processes the current service traffic based on a consistent hashing algorithm and a server identification list stored in the first load balancer;
[0019] Among them, the server identification list is constructed based on the identification of servers whose current operating status is normal; the server identification list is stored in each load balancer in the load balancer cluster; the packet header of the data packet is updated based on the identification 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, when the current service traffic is not received for the first time, determining the server that processes the current service traffic based on the local data of the first load balancer includes:
[0021] Parsing local data of the first load balancer;
[0022] In a case where the local data includes the current service traffic, determining 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 for processing the current business traffic.
[0024] In some embodiments, when the current service traffic is not received for the first time, determining the server that processes the current service traffic based on the data packet received by the first load balancer includes:
[0025] Parsing a header of a data packet received by the first load balancer;
[0026] In a case where the packet header includes the identifier of the first server, determining 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 identification list, a server that processes the current service traffic is determined.
[0028] In some embodiments, the load balancer cluster is constructed based on the following steps:
[0029] Build individual load balancers based on extended Berkeley packet filters;
[0030] Building the load balancer cluster 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] In a second aspect, the present application provides a load balancing device for service traffic, which is applied to a load balancer cluster built based on an extended Berkeley packet filter, including:
[0033] A first determination module is used to determine a server that processes the current business traffic based on a consistent hashing algorithm when receiving the current business traffic for the first time;
[0034] A second determination 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 determine the server that processes the current business traffic based on the data packet received by the first load balancer;
[0035] Among them, 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 server assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, and the first server is the server that has processed the current business traffic.
[0036] In some embodiments, the first determining module is specifically configured to:
[0037] Obtaining local data of the first load balancer;
[0038] In a case where the local data does not include the current service traffic, determining that the first load balancer receives the current service traffic for the first time;
[0039] Determine a hash value of the current service flow based on a consistent hashing algorithm;
[0040] Determine a server that processes the current service traffic based on the hash value;
[0041] The current business traffic is associated with a server that processes the current business traffic, and the association result is stored in local data of the first load balancer.
[0042] In some embodiments, the first determining module is specifically configured to:
[0043] Obtaining data packets of the current service flow;
[0044] In a case where the header of the data packet does not include the identifier of the first server, determining that the current service traffic is received for the first time;
[0045] Determine a server that processes the current service traffic based on a consistent hashing algorithm and a server identification list stored in the first load balancer;
[0046] Among them, the server identification list is constructed based on the identification of servers whose current operating status is normal; the server identification list is stored in each load balancer in the load balancer cluster; the packet header of the data packet is updated based on the identification 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 comprises:
[0048] Building blocks for building individual load balancers based on the extended Berkeley Packet Filter;
[0049] Building the load balancer cluster 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] In a third aspect, the present application provides a service flow processing device, a client, a router, a load balancer cluster and a plurality of servers connected in sequence;
[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 above-mentioned load balancing method for business traffic;
[0055] The server is used to process the business traffic.
[0056] In a fourth aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to implement the above method when executing the program through the computer program.
[0057] In a fifth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, which implements the above method when executed by a processor.
[0058] In a sixth aspect, an embodiment of the present application provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0059] The load balancing method, device, electronic device and storage medium for business traffic provided by the embodiments of the present application build a load balancer cluster based on an extended Berkeley packet filter. When the load balancer cluster receives the current business traffic for the first time, it determines the server that processes the current business traffic through a consistent hashing algorithm. When it is not the first time to receive the current business traffic, it determines the server that processes the current business traffic through local data of the first load balancer or the received data packet. There is no need to share data among the load balancers in the load balancer cluster, so that consistency of business traffic can be achieved. It can also avoid repeated calculation of hash values, improve the load balancing efficiency of business traffic, and facilitate the maintenance of business traffic sessions. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the technical solutions in the present application or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0061] Figure 1 One of the flow charts of the load balancing method for business traffic provided in the embodiment of the present application;
[0062] Figure 2 A second flow chart of a method for load balancing of business traffic provided in an embodiment of the present application;
[0063] Figure 3 The third flowchart of the method for load balancing of business traffic provided in the embodiment of the present application;
[0064] Figure 4 A schematic diagram of the structure of a load balancing device for business traffic provided in an embodiment of the present application;
[0065] Figure 5 A schematic diagram of the structure of a service flow processing device provided in an embodiment of the present application;
[0066] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0067] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0068] Figure 1 One of the flow diagrams of the load balancing method for business traffic provided in the embodiment of the present application is as follows: Figure 1 As shown, the method includes step 110 and step 120. The steps of the method flow are only a possible implementation of the present application.
[0069] Step 110: When the current business traffic is received for the first time, determine the server that processes the current business traffic based on the consistent hashing algorithm.
[0070] Specifically, the execution subject of the load balancing method for business traffic provided in the embodiment of the present application is a load balancing device for business traffic, and the device may 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 is the business traffic currently received by the load balancer cluster. The 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 through the consistent hashing algorithm, and determine the server that processes the current business traffic based on the hash value of the current business traffic, which server can be a backend server.
[0074] After the load balancing server cluster determines the server that processes the current business traffic, it can send the current business traffic to the server, and then the server will process the current business traffic.
[0075] Step 120: When the current service traffic is not received for the first time, determine the server that processes the current service traffic based on the local data of the first load balancer; or determine the server that processes the current service traffic based on the data packet received by the first load balancer;
[0076] Among them, 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 server assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, and the first server is the server that has processed the current business traffic.
[0077] Specifically, when the load balancer cluster receives the current business traffic not for the first time, in order to avoid repeatedly calculating the hash value of the current business traffic, the server that processes the current business traffic can be quickly determined 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] The local cache of each load balancer is used to store the connection information between the business traffic established in each load balancer and the server.
[0080] For example, the router sends the service traffic to any load balancer in the load server cluster, and the any load balancer is referred to as the first load balancer. After the first load balancer sends the received service traffic to the server, the server processes the service traffic, thereby establishing a connection relationship between the service traffic and the server. Therefore, the local cache of the first load balancer is used to store the service traffic received by the first load balancer and the server assigned by the first load balancer to process the service traffic.
[0081] The data cached in the local cache is local data. Therefore, if the first load balancer does not receive the current business traffic for the first time, the local data of the first load balancer will include the current business traffic and the server assigned by the first load balancer that has processed the current business traffic. The first load balancer can directly send the current business traffic to the server that has processed the current business traffic based on the local data, so that even if the current business traffic is assigned multiple times, it can be processed by the same server, thereby facilitating the maintenance of all sessions of the current business traffic.
[0082] Because the local data is cached in the first load balancer, the local data is not shared with other load balancers in the load balancer cluster. Therefore, when the load balancer cluster does not receive the current business traffic for the first time and 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 does not receive the current business traffic for the first time and the first load balancer does not receive 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 amount of calculation of the load balancer cluster, the embodiment of the present application further provides method (2), which is as follows:
[0084] (2) Set a unique security identifier (SID) for each server and use the SID as an identifier to identify the server. Construct a data packet of the current business traffic based on the identifier of the server that has processed the current business traffic and the current business traffic, and determine the server that processes the current business traffic based on the data packet received by the first load balancer.
[0085] The data packet can be stored in the client. If the load balancer cluster does not receive the current business traffic for the first time, the client will store the data packet of the current business traffic. When the client sends the current business traffic, it sends the data packet to the router, and then the router 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 business traffic.
[0086] Because the data packet carries the identifier of the server that has processed the current business traffic, that is, the identifier of the first server, and the data packet is stored in the client, the data packet is assigned to a server by any load balancer in the load balancer cluster, and the load balancing 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 business traffic determined here may be allocated by the first load balancer, or may not be allocated by the first load balancer. That is, when the first load balancer cannot be used due to anomalies such as failure or upgrade, the current business traffic is distributed through other load balancers in the load balancer cluster, and the server that has processed the current business traffic can also be quickly determined based on the identifier in the data packet. That is, as long as there is a load balancer in the load balancer cluster that has calculated the hash value of the current business traffic, when the business traffic that is the same as the current business traffic is sent to the load balancer cluster again, no matter which load balancer in the load balancer cluster it is sent to, there is no need to calculate the hash value of the current business traffic again.
[0088] The above two methods can be randomly selected according to actual conditions. For example, method (1) can be selected when all load balancers in the load balancer cluster can operate normally; method (2) can be selected when some load balancers in the load balancer cluster are being upgraded, maintained or fail.
[0089] The load balancing method for business traffic provided in the embodiment of the present application builds a load balancer cluster based on an extended Berkeley packet filter. When the load balancer cluster receives the current business traffic for the first time, it determines the server that processes the current business traffic through a consistent hashing algorithm. When the current business traffic is not received for the first time, the server that processes the current business traffic is determined through local data of the first load balancer or the received data packet. The consistency of the business traffic can be achieved without sharing data among the load balancers in the load balancer cluster. It can also avoid repeated calculation of hash values, improve the load balancing efficiency of the business traffic, and facilitate the maintenance of business traffic sessions.
[0090] It should be noted that each implementation method of the present application can be freely combined, the order can be changed, or it can be executed separately, and does not need to rely on or depend on a fixed execution order.
[0091] In some embodiments, a load balancer cluster is constructed based on the following steps:
[0092] Build individual load balancers based on extended Berkeley packet filters;
[0093] Build a load balancer cluster based on individual load balancers;
[0094] The service traffic is distributed to each load balancer in the load balancer cluster based on equal-cost routing.
[0095] Specifically, a load balancer cluster can be obtained by forming a cluster from multiple load balancers built through eBPF.
[0096] You can write eBPF programs to run a load balancer by triggering their execution when events such as LISTEN, CONNECT, or CONN_ESTD occur.
[0097] The load balancers in the load balancer cluster can distribute the service traffic by using equal cost multi-path routing (ECMP) through the routers of the access network, so that the service traffic can be evenly distributed to each load balancer in the load balancer cluster, and when one or more load balancers are upgraded, maintained or fail, the service traffic can be distributed to other load balancers without failure in the load balancer cluster, so as to achieve high availability performance. The equal cost multi-path routing in the embodiment of the present application is also called equal cost routing.
[0098] The load balancing method for business traffic provided in the embodiment of the present application builds a load balancer through eBPF, builds a load balancer cluster through multiple load balancers, and distributes business traffic through equal-cost routing, thereby improving the load balancing efficiency and making the load balancing device for business traffic have high availability performance.
[0099] In some embodiments, step 110 includes:
[0100] Obtain local data of the first load balancer;
[0101] In a case where the current service traffic is not included in the local data, determining that the first load balancer receives the current service traffic for the first time;
[0102] Determine the hash value of the current business traffic based on the consistent hashing algorithm;
[0103] Determine the server that handles the current business traffic based on the hash value;
[0104] The current business traffic is associated with the server that processes the current business traffic, and the association result is stored in the local data of the first load balancer.
[0105] Specifically, after the router sends the current business traffic to the first load balancer in the load balancer cluster, the first load balancer will obtain local data. Because the local data includes the business traffic received by the first load balancer, if the local data does not include the current business traffic, it indicates that the first load balancer is receiving the current business traffic for the first time.
[0106] The first load balancer can calculate the hash value of the current business flow through a consistent hashing algorithm, and select a server for the current business flow according to the hash value. The step of selecting a server can be performed through pseudo code.
[0107] For example, the current business traffic is distributed in the form of data packets. The pseudo code logic for selecting the backend server is as follows:
[0108] select backend host(packet) {
[0109] If (the destination server of the data packet has a record in the local cache)
[0110] Returns the local cache (data packet)
[0111] Otherwise return consistent hash (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, caches the current business traffic that establishes a connection and the server that currently processes the current business traffic in the local cache of the first load balancer.
[0114] Therefore, when the first load balancer receives the same business traffic again, it does not need to calculate the hash value again, and can determine which server to distribute the business traffic to through local data.
[0115] In addition, because the embodiment of the present application only stores the connection relationship between business traffic and 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, and memory usage is reduced.
[0116] The load balancing method for business traffic provided in the embodiment of the present application stores the current business traffic for establishing a connection with the server in local data when the current business traffic is received for the first time, so that when the same business traffic is received, there is no need to repeatedly calculate the hash value of the business traffic, 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] Parsing local data of the first load balancer;
[0119] In a case where the local data includes the current service traffic, determining that the first load balancer has received the current service traffic within a historical time period;
[0120] The server associated with the current business traffic in the local data is used as the server for processing 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 business traffic received by the first load balancer, if the local data includes the current business traffic, it indicates that the first load balancer is not receiving the current business 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 server may change after a long time interval. Therefore, you can only retain local data within a certain period of time, or set a data volume threshold to manage local data.
[0123] Therefore, the first load balancer does not receive the current service traffic for the first time, that is, the first load balancer has received the current service traffic in the historical time period. The first load balancer can directly obtain the server connected to the current service traffic through local data and use the server as the server for processing the current service traffic.
[0124] The load balancing method for business traffic provided in the embodiment of the present application directly determines the server for processing the current business traffic based on local data when the first load balancer does not receive the current business traffic for the first time, thereby reducing the amount of calculation of the load balancer and improving the load balancing efficiency of the business traffic.
[0125] In some embodiments, step 110 includes:
[0126] Get the data packet of the current business traffic;
[0127] In a case where the header of the data packet does not include an identifier of the first server, determining that the current service traffic is received for the first time;
[0128] Determine a server that processes current service traffic based on a consistent hashing algorithm and a server identification list stored in the first load balancer;
[0129] Among them, the server identification list is constructed based on the identification of the server whose current operating status is normal; the server identification list is stored in each load balancer in the load balancer cluster; the packet header of the data packet is updated based on the identification of the server processing the current business traffic, and the updated data packet is stored in the client sending the business traffic.
[0130] Specifically, an identifier can be assigned to each backend server, and the server identifier is used as the routing information of the data packet and written into the Transmission Control Protocol (TCP) header of the data packet. Taking the identifier as SID as an example, the header structure of the data packet includes: |Type|Length|SID|. Writing the identifier into the header allows the client and the load balancing cluster to quickly obtain the server identifier directly through the header of the data packet without parsing the data packet, and thus determine the server based on the identifier.
[0131] Figure 2 The second flow chart of the load balancing method for business traffic provided in the embodiment of the present application is as follows: Figure 2 As shown, a local cache of a server identification list can be maintained on each load balancer in the load balancing server cluster, and the server identification list records the identifications of servers that can currently run normally, as well as server information corresponding to each identification.
[0132] A synchronization process may be set up to synchronize the server identification list to each load balancer in the load balancing server cluster, ensure that the server identification list of each load balancer is the same, and update the server identification list according to the running status of the server.
[0133] The eBPF program can obtain the TCP header information of the data packet 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 data packet of the current business traffic according to the eBPF program, because the data packet includes the identifier of the server that has processed the current business traffic, that is, includes 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 balancing server cluster receives the current business traffic for the first time. The hash value of the current business traffic can be calculated according to the consistent hashing algorithm, and then an identifier is selected from the server identifier list stored in the first load balancer according to the hash value. The server that processes the current business traffic is determined according to the selected identifier.
[0136] After the first load balancer determines the server that processes the current business traffic, it writes the identifier of the server into a data packet and sends the data packet to the server.
[0137] After receiving the data packet, the server obtains its own identifier, writes the value of the identifier into the TCP packet header, and sends the data packet with the identifier value written to the client.
[0138] After receiving the data packet, the client obtains the identifier according to the header of the data packet and saves the identifier. When the client generates the same service flow, the header of the data packet generating the service flow will include the identifier of the first server, so that the first load balancer can directly determine the server processing the current service flow according to the header of the data packet.
[0139] The load balancing method for business traffic provided in the embodiment of the present application stores the server identifier in the packet header of the data packet and stores the identifier on the client, so that when the load balancer cluster receives the same business traffic again, the received data packet header directly includes the server identifier that processes the business traffic, and there is no need to calculate the hash value of the business traffic again, thereby improving the efficiency of load balancing.
[0140] In some embodiments, step 120 includes:
[0141] Parsing a header of a data packet received by the first load balancer;
[0142] In a case where the packet header includes an identifier of the first server, determining 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 identification list, a server that processes the current service traffic is determined.
[0144] Specifically, when the load balancing server cluster receives the current service traffic not 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 packet, 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 current first server can operate normally. Then, the data packet of the current business traffic can be sent to the first server, and the first server will process the current business traffic again.
[0146] The load balancing method for business traffic provided in the embodiment of the present application determines the server that processes the current business traffic through the data packet header and the server identification list, which can avoid repeated calculation of hash values when the same business traffic is distributed to different load balancers, and can also avoid the load balancer from distributing business traffic to servers that cannot operate normally, thereby improving load balancing efficiency and achieving consistency of business traffic.
[0147] Figure 3 The third flow chart of the load balancing method for business traffic provided in the embodiment of the present application is as follows: Figure 3 As shown, the method includes:
[0148] Step 1: In response to the current service traffic, the client initiates a Synchronize Sequence Numbers (SYN).
[0149] Step 2: Determine that the load balancing server cluster receives the current business traffic for the first time, select a backend server for the current business traffic through a consistent hashing algorithm, and then forward the data packet of the current business traffic to the backend server.
[0150] Step 3: The backend server obtains the backend server identifier, i.e., SID, through the data packet. Taking the backend server's SID = 2 as an example, 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 the SID embedded in the TCP packet header and saves it. When sending a service flow data packet with the same service flow as the current service flow, the SID will be embedded in the packet header.
[0152] During the operation of the load balancing device for service traffic, if the load balancer (load balancer 1) that last distributed the service traffic is upgraded, maintained, or fails, the processing flow is as follows:
[0153] According to the ECMP algorithm of the router, the data packets of the service traffic will be forwarded to another load balancer in the load balancer cluster, for example, forwarded to 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 identification 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 the embodiment of the present application has the following advantages:
[0156] (1) It is a completely stateless method, that is, there is no need to share a centralized or distributed cache between various load balancers, and it does not introduce the overhead of external cache access or the complexity and stability problems caused by distribution, and it can achieve unlimited horizontal expansion.
[0157] (2) The distribution of business traffic is implemented based on the eBPF program, which has extremely low overhead. The backend server that processes the business traffic can be determined through the packet header, without the need to identify the content of the packet, further reducing additional overhead and improving load balancing efficiency.
[0158] The load balancing device for business traffic provided in an embodiment of the present application is described below. The load balancing device for business traffic described below and the load balancing method for business traffic described above can refer to each other.
[0159] The following is a description of the analysis performance testing device provided in an embodiment of the present application. The analysis performance testing device described below and the load balancing method for business traffic described above can be referenced to each other.
[0160] Figure 4 A schematic diagram of the structure of a load balancing device for service traffic provided in an embodiment of the present application, such as Figure 4 As shown, the device is applied to a load balancer cluster constructed based on an extended Berkeley packet filter, and includes a first determination module 410 and a second determination module 420 .
[0161] A first determination module is used to determine a server that processes the current business traffic based on a consistent hashing algorithm when the current business traffic is received for the first time;
[0162] A second determination 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 determine the server that processes the current business traffic based on the data packet received by the first load balancer;
[0163] Among them, 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 server assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, and the first server is the server that has processed the current business traffic.
[0164] Specifically, according to an embodiment of the present application, any multiple modules in the first determination module and the second determination module can be combined into one module for implementation, or any one of the modules can be split into multiple modules.
[0165] Alternatively, at least part of the functionality of one or more of these modules may be combined with at least part of the functionality of other modules and implemented in one module.
[0166] According to an embodiment of the present application, at least one of the first determination module and the second determination 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 a package, an application-specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or can be implemented in any one of the three implementation methods of software, hardware and firmware, or in an appropriate combination of any of them.
[0167] Alternatively, at least one of the first determination module and the second determination module may be at least partially implemented as a computer program module, and when the computer program module is executed, the corresponding function may be performed.
[0168] The load balancing device for business traffic provided in the embodiment of the present application builds a load balancer cluster based on an extended Berkeley packet filter. When the load balancer cluster receives the current business traffic for the first time, it determines the server that processes the current business traffic through a consistent hashing algorithm. When the current business traffic is not received for the first time, the server that processes the current business traffic is determined through local data of the first load balancer or the received data packet. The consistency of the business traffic can be achieved without sharing data among the load balancers in the load balancer cluster. It can also avoid repeated calculation of hash values, improve the load balancing efficiency of the business traffic, and facilitate the maintenance of business traffic sessions.
[0169] In some embodiments, the first determining module is specifically configured to:
[0170] Obtain local data of the first load balancer;
[0171] In a case where the current service traffic is not included in the local data, determining that the first load balancer receives the current service traffic for the first time;
[0172] Determine the hash value of the current business traffic based on the consistent hashing algorithm;
[0173] Determine the server that handles the current business traffic based on the hash value;
[0174] The current business traffic is associated with the server that processes the current business traffic, and the association result is stored in the local data of the first load balancer.
[0175] In some embodiments, the first determining module is specifically configured to:
[0176] Get the data packet of the current business traffic;
[0177] In a case where the header of the data packet does not include an identifier of the first server, determining that the current service traffic is received for the first time;
[0178] Determine a server that processes current service traffic based on a consistent hashing algorithm and a server identification list stored in the first load balancer;
[0179] Among them, the server identification list is constructed based on the identification of the server whose current operating status is normal; the server identification list is stored in each load balancer in the load balancer cluster; the packet header of the data packet is updated based on the identification of the server processing the current business traffic, and the updated data packet is stored in the client sending the business traffic.
[0180] In some embodiments, the second determination module is specifically configured to:
[0181] Parsing local data of the first load balancer;
[0182] In a case where the local data includes the current service traffic, determining that the first load balancer has received the current service traffic within a historical time period;
[0183] The server associated with the current business traffic in the local data is used as the server for processing the current business traffic.
[0184] In some embodiments, the second determination module is specifically configured to:
[0185] Parsing a header of a data packet received by the first load balancer;
[0186] In a case where the packet header includes an identifier of the first server, determining 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 identification list, a server that processes the current service traffic is determined.
[0188] In some embodiments, the load balancing device for service traffic further includes a construction module, and the construction module is used to:
[0189] Build individual load balancers based on extended Berkeley packet filters;
[0190] Build a load balancer cluster based on individual load balancers;
[0191] The service traffic is distributed to each load balancer in the load balancer cluster based on equal-cost routing.
[0192] It should be noted here that the load balancing device for business traffic provided in the embodiment of the present application can implement all the method steps implemented in the above-mentioned load balancing method embodiment for business traffic, and can achieve the same technical effect. The parts and beneficial effects of this embodiment that are the same as those in the method embodiment will not be described in detail here.
[0193] Figure 5 A schematic diagram of the structure of a service flow processing device provided in an embodiment of the present application; Figure 5 As shown, the service traffic processing device includes a client 510, a router 520, a load balancer cluster 530 and a plurality of backend servers 540 connected in sequence;
[0194] Client, used to send business traffic;
[0195] Router, used to distribute business traffic to each load balancer in the load balancer cluster;
[0196] A load balancer cluster, used to execute the above-mentioned load balancing method for business traffic;
[0197] Backend server, used to process business traffic.
[0198] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present 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 through the communication bus 640. The processor 610 may call a computer program in the memory 630 to execute the above method, for example, including:
[0199] When receiving the current business traffic for the first time, determine the server that processes the current business traffic based on the consistent hashing algorithm;
[0200] In the case where the current service traffic is not received for the first time, determining the server that processes the current service traffic based on the local data of the first load balancer; or determining the server that processes the current service traffic based on the data packet received by the first load balancer;
[0201] Among them, 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 server assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, and the first server is the server that has processed the current business traffic.
[0202] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of software function modules and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0203] On the other hand, an embodiment of the present application further provides 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 execute the methods provided in the above embodiments, for example, including:
[0204] When receiving the current business traffic for the first time, determine the server that processes the current business traffic based on the consistent hashing algorithm;
[0205] In the case where the current service traffic is not received for the first time, determining the server that processes the current service traffic based on the local data of the first load balancer; or determining the server that processes the current service traffic based on the data packet received by the first load balancer;
[0206] Among them, 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 server assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, and the first server is the server that has processed the current business traffic.
[0207] On the other hand, an embodiment of the present application further provides a processor-readable storage medium, the processor-readable storage medium storing a computer program, the computer program is used to enable the processor to execute the methods provided in the above embodiments, for example, including:
[0208] When receiving the current business traffic for the first time, determine the server that processes the current business traffic based on the consistent hashing algorithm;
[0209] In the case where the current service traffic is not received for the first time, determining the server that processes the current service traffic based on the local data of the first load balancer; or determining the server that processes the current service traffic based on the data packet received by the first load balancer;
[0210] Among them, 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 server assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, and the first server 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 can be accessed by the processor, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as CD, DVD, BD, HVD, etc.), and semiconductor storage (such as ROM, EPROM, EEPROM, non-volatile memory (NANDFLASH), solid-state drive (SSD)), etc.
[0212] The device embodiments described above are merely illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, i.e., they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.
[0213] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment 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 the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for load balancing of business traffic, characterized in that: Applied to a load balancer cluster built based on an extended Berkeley packet filter, the method comprises: When receiving the current business traffic for the first time, determining a server for processing the current business traffic based on a consistent hashing algorithm; In the case where the current service traffic is not received for the first time, determining the server that processes the current service traffic based on the local data of the first load balancer; or determining the server that processes the current service traffic based on the data packet received by the first load balancer; Among them, 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 server assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, and the first server is the server that has processed the current business traffic.
2. The load balancing method for service traffic according to claim 1, characterized in that: In the case of receiving the current service traffic for the first time, determining a server for processing the current service traffic based on a consistent hashing algorithm includes: Obtaining local data of the first load balancer; In a case where the local data does not include the current service traffic, determining that the first load balancer receives the current service traffic for the first time; Determine a hash value of the current service flow based on a consistent hashing algorithm; Determine a server that processes the current service traffic based on the hash value; The current business traffic is associated with a server that processes the current business traffic, and the association result is stored in local data of the first load balancer.
3. The load balancing method for service traffic according to claim 1, characterized in that: In the case of receiving the current service traffic for the first time, determining a server for processing the current service traffic based on a consistent hashing algorithm includes: Obtaining data packets of the current service flow; In a case where the header of the data packet does not include the identifier of the first server, determining that the current service traffic is received for the first time; Determine a server that processes the current service traffic based on a consistent hashing algorithm and a server identification list stored in the first load balancer; Among them, the server identification list is constructed based on the identification of servers whose current operating status is normal; the server identification list is stored in each load balancer in the load balancer cluster; the packet header of the data packet is updated based on the identification of the server processing the current business traffic, and the updated data packet is stored in the client sending the business traffic.
4. The method for load balancing of service traffic according to claim 2, characterized in that: The step of determining, in a case where the current service traffic is not received for the first time, a server for processing the current service traffic based on local data of the first load balancer includes: Parsing local data of the first load balancer; In a case where the local data includes the current service traffic, determining 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 for processing the current business traffic.
5. The method for load balancing of service traffic according to claim 3, characterized in that: The determining, in a case where the current service traffic is not received for the first time, based on the data packet received by the first load balancer, a server for processing the current service traffic comprises: Parsing a header of a data packet received by the first load balancer; In a case where the packet header includes the identifier of the first server, determining that the load balancer cluster has received the current service traffic within a historical time period; Based on the first server and the server identification list, a server that processes the current service traffic is determined.
6. The method for load balancing service traffic according to any one of claims 1 to 5, characterized in that: The load balancer cluster is built based on the following steps: Build individual load balancers based on extended Berkeley packet filters; Building the load balancer cluster 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: Applies to a load balancer cluster built on top of the extended Berkeley Packet Filter, including: A first determination module is used to determine a server that processes the current business traffic based on a consistent hashing algorithm when receiving the current business traffic for the first time; A second determination 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 determine the server that processes the current business traffic based on the data packet received by the first load balancer; Among them, 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 server assigned by the first load balancer to process the business traffic; the data packet includes the identifier of the first server, and the first server is the server that has processed the current business traffic.
8. The load balancing device for service traffic according to claim 7, characterized in that: The first determining module is specifically used for: Obtaining local data of the first load balancer; In a case where the local data does not include the current service traffic, determining that the first load balancer receives the current service traffic for the first time; Determine a hash value of the current service flow based on a consistent hashing algorithm; Determine a server that processes the current service traffic based on the hash value; The current business traffic is associated with a server that processes the current business traffic, and the association result is stored in 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: Obtaining data packets of the current service flow; In a case where the header of the data packet does not include the identifier of the first server, determining that the current service traffic is received for the first time; Determine a server that processes the current service traffic based on a consistent hashing algorithm and a server identification list stored in the first load balancer; The server identification list is constructed based on the identification of servers whose current running status is normal; the server identification list is stored in each load balancer in the load balancer cluster; The header of the data packet is updated based on the identifier of the server processing the current service traffic, and the updated data packet is stored in the client sending the service traffic.
10. The service flow load balancing device according to any one of claims 7 to 9, characterized in that: The device also includes: Building blocks for building individual load balancers based on the extended Berkeley Packet Filter; Building the load balancer cluster 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 service flow processing device, characterized in that: Includes clients, routers, load balancer clusters, 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 execute the load balancing method for business traffic according to any one of claims 1 to 6; The server is used to process the business 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 service traffic load balancing method according to 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 a processor, the method for load balancing the service traffic as described in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Business server side load balancing method, client side, server side and system
CN104079630A
Method, equipment and system for balancing loads in cluster
CN106790675A
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
