Session maintenance method, apparatus, device, storage medium, and program product
By using a load balancing cluster and a mechanism to keep session connection information synchronized, the problem of inconsistent sessions between load balancers is solved, achieving efficient distribution of user requests and improved service quality.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA TELECOM CLOUD TECH CO LTD
- Filing Date
- 2024-12-04
- Publication Date
- 2026-05-01
AI Technical Summary
A single load balancer cannot withstand huge traffic pressure, and inconsistent sessions between multiple load balancers can lead to poor user experience, such as lost sessions and inconsistent data, resulting in poor service quality.
Deploy a load balancing cluster, receive client request packets through the first load balancer, generate session persistence information, and synchronize with other load balancers to ensure that the same user request is distributed to the same server. Use preset server selection rules and load balancing priority mechanism to unify load balancing decisions.
It improves the overall processing capacity and response speed of the system, ensures the continuous availability of services, avoids session loss and data inconsistency, and enhances service quality.
Smart Images

Figure CN119520585B_ABST
Abstract
Description
Session persistence methods, apparatus, devices, storage media, and program products Technical Field
[0001] This application relates to the field of communication technology, and in particular to a session holding method, apparatus, computer device, computer-readable storage medium, and computer program product. Background Technology
[0002] With the rapid development of network technology, the number of users of network services is increasing. When multiple users access a website or application simultaneously, multiple servers are typically used to distribute the request processing tasks to improve service availability and response speed. This distributes the load, improves overall performance and response speed, and ensures that even if one server fails, the others can continue to provide services. However, in this scenario, if a user's earlier request is assigned to one server, while a later request is assigned to another, it may lead to asynchronous user session data, resulting in a poor user experience or functional failure.
[0003] In traditional technologies, load balancers can achieve session persistence. When using the TCP protocol, load balancers can maintain sessions based on the client's source IP address, distributing multiple requests from the same client IP to the same backend server for processing.
[0004] However, as the user base of internet applications continues to grow, a single load balancer may be unable to withstand the enormous traffic pressure. Once this device fails, the service of the entire system will be affected, or even completely interrupted. However, if multiple load balancers are deployed in the system, different load balancers may still distribute related requests to different backend servers, resulting in poor user experience such as session loss and data inconsistency. Therefore, the service quality is poor regardless of whether there is a single load balancer or multiple load balancers. Summary of the Invention
[0005] Therefore, it is necessary to provide a session persistence method, apparatus, computer device, computer-readable storage medium, and computer program product that can improve service quality in response to the above-mentioned technical problems.
[0006] In a first aspect, this application provides a session persistence method, which is applied to a first load balancer in a load balancing cluster, the load balancing cluster further including at least one second load balancer; the method includes:
[0007] Receive client request messages distributed by the router;
[0008] Query the target server corresponding to the client request message;
[0009] Based on the client request message and the target server information of the target server, the first session keep-alive information is generated and sent to each second load balancer;
[0010] Send the client request message to the target server.
[0011] In one embodiment, after querying the target server corresponding to the client request message, and before sending the client request message to the target server, the method further includes:
[0012] Upon receiving the second session keep-alive information sent by the second load balancer, obtain the first client information corresponding to the client request message, and extract the second client information from the second session keep-alive information;
[0013] If the information of the first client is the same as that of the second client, query the candidate server corresponding to the second session keep-alive information;
[0014] Based on the preset server selection rules, a new target server is selected from the candidate servers and the target server.
[0015] In one embodiment, according to a preset server selection rule, a target server is reselected from the candidate servers and the target server, including:
[0016] Obtain the first server address information of the target server, and the second server address information of the candidate servers;
[0017] If the first server address information and the second server address information are different, obtain the load balancing priority information;
[0018] If, based on the load balancing priority information, the priority of the first load balancer is determined to be higher than that of the second load balancer, the target server remains unchanged.
[0019] If, based on the load balancing priority information, the priority of the second load balancer is determined to be higher than that of the first load balancer, the candidate server is selected as the target server.
[0020] In one embodiment, obtaining load balancing priority information includes:
[0021] Obtain the first load balancer address information of the first load balancer and the second load balancer address information of the second load balancer;
[0022] Based on the numerical values of the first load balancer address information and the second load balancer address information, the priorities of the first load balancer and the second load balancer are determined, and load balancer priority information is generated. The priority of the load balancer is positively or negatively correlated with the numerical value of the load balancer address information.
[0023] In one embodiment, the first load balancer stores a session persistence table; querying the target server corresponding to a client request message includes:
[0024] If the target server corresponding to the client request message is not found in the session persistence table, the target server corresponding to the client request message is detected according to the preset load balancing strategy.
[0025] In one embodiment, the method further includes:
[0026] Upon receiving the second session keep-alive information from the second load balancer, the locally stored session keep-alive table is updated based on the second session keep-alive information.
[0027] Secondly, this application also provides a session persistence device, which is applied to a first load balancer in a load balancing cluster, the load balancing cluster further including at least one second load balancer; the device includes:
[0028] The receiving module is used to receive client request messages distributed by the router;
[0029] The query module is used to query the target server corresponding to the client's request message;
[0030] The generation module is used to generate first session keep-alive information based on the client request message and the target server information of the target server, and send the first session keep-alive information to each second load balancer.
[0031] The sending module is used to send client request messages to the target server.
[0032] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0033] Receive client request messages distributed by the router;
[0034] Query the target server corresponding to the client request message;
[0035] Based on the client request message and the target server information of the target server, the first session keep-alive information is generated and sent to each second load balancer;
[0036] Send the client request message to the target server.
[0037] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0038] Receive client request messages distributed by the router;
[0039] Query the target server corresponding to the client request message;
[0040] Based on the client request message and the target server information of the target server, the first session keep-alive information is generated and sent to each second load balancer;
[0041] Send the client request message to the target server.
[0042] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0043] Receive client request messages distributed by the router;
[0044] Query the target server corresponding to the client request message;
[0045] Based on the client request message and the target server information of the target server, the first session keep-alive information is generated and sent to each second load balancer;
[0046] Send the client request message to the target server.
[0047] The aforementioned session persistence methods, apparatus, computer equipment, computer-readable storage media, and computer program products, on the one hand, can significantly improve the overall processing capacity and response speed of the system by deploying a load balancing cluster and distributing load balancing tasks across multiple load balancers. Even if one or more load balancers fail, the other members can still continue to work, ensuring the continuous availability of services and improving service quality. On the other hand, by receiving client request packets distributed by the router, querying the target server corresponding to the client request packet, and generating first session persistence information based on the client request packet and the target server information, the first session persistence information is sent to each of the second load balancers. This ensures that after any load balancer in the load balancing cluster receives a client request packet and determines the target server, it generates corresponding session persistence information and synchronizes this information with other load balancers in the cluster. This ensures that the session persistence information remains consistent across all load balancers in the cluster. Therefore, even if the same user's request is distributed to different load balancers in the cluster, the different load balancers distribute the received request according to the same session persistence information. This allows the same user's request to be distributed to the same server, avoiding session loss, data inconsistency, and other poor user experiences, further improving service quality. Attached Figure Description
[0048] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0049] Figure 1 shows the application environment of session persistence methods in related technologies;
[0050] Figure 2 is an application environment diagram of the session persistence method in one embodiment;
[0051] Figure 3 is a flowchart illustrating a session persistence method in one embodiment;
[0052] Figure 4 is a flowchart illustrating the session persistence method in another embodiment;
[0053] Figure 5 is a structural block diagram of a session holding device in one embodiment;
[0054] Figure 6 is an internal structure diagram of a computer device in one embodiment. Detailed Implementation
[0055] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0056] With the rapid development of network technology, the number of users of network services is increasing. When multiple users access a website or application simultaneously, multiple servers are typically used to distribute the request processing tasks to improve service availability and response speed. This distributes the load, improving overall performance and response speed, while ensuring that even if one server fails, other servers can continue to provide services. However, in this scenario, if a user's earlier request is assigned to one server, but a later request is assigned to another, it may lead to asynchronous user session data, resulting in a poor user experience or functional failure. In traditional technologies, load balancers can achieve session persistence. When using the TCP protocol, a load balancer can maintain sessions based on the client's source IP address, distributing multiple requests from the same client IP to the same backend server for processing.
[0057] For example, a load balancer corresponds to two backend servers A and B. Client C sends a login request, and the load balancer distributes the login request to server A, completing the login. Then, client C has another request. Without session persistence, the load balancer might distribute this request to server B, but server B does not have the user's login information, requiring re-login verification. With session persistence, the load balancer will distribute related requests to the same backend server, meaning the later-received request will be sent to server A, thus eliminating the need for re-login.
[0058] However, as the user base of internet applications continues to grow, a single load balancer may struggle to handle the immense traffic pressure. If this device fails, the entire system's service will be affected, or even completely interrupted. Conversely, deploying multiple load balancers in the system may result in related requests being distributed to different backend servers, leading to poor user experiences such as session loss and data inconsistency.
[0059] For example, as shown in Figure 1, assuming the load balancing cluster 106 includes load balancer A, load balancer B, and load balancer C, and router 104 is configured with equal-cost routes to load balancer A, load balancer B, and load balancer C, when client 102 initiates a request to access load balancing cluster 106, router 104 can obtain the request's five-tuple (source IP address, destination IP address, source port number, destination port number, and protocol type) using ECMP (Equal-Cost Multi-Path). It then performs a hash operation on the five-tuple and distributes the request evenly to each load balancer in load balancing cluster 106 based on the hash result. Subsequently, the load balancers distribute the received requests to backend server A108 or server B110 according to their configured distribution strategies, such as round-robin or least connections. In this scenario, even if each load balancer is configured with session persistence, assuming the same client 102 sends requests 1, 2, and 3, request 1 arrives at load balancer A and is selected as server A108 by the distribution policy. Subsequent requests from client 102 to load balancer A will be forwarded to server A108 within the session persistence period. Requests 2 and 3 arrive at load balancer C and are selected as server B110 by the distribution policy. Subsequent requests from client 102 to load balancer C will also be forwarded to server B110 within the session persistence period. Thus, the same client 102's requests will still be distributed to different servers A108 and B110. The session persistence function within each load balancer is effective, but users will still experience poor user experience such as session loss and data inconsistency.
[0060] Therefore, the service quality is poor regardless of whether there is a single load balancer or multiple load balancers.
[0061] In this scenario, related technologies suggest that routers can perform hash calculations based on the triplet (source IP address, destination IP address, and protocol type). Traffic from the same client with the same source IP address will be distributed to the same load balancer after the hash calculation. Session persistence is then implemented on this same load balancer, ensuring that requests from the same source address are consistently routed to the same application server. However, this approach suffers from uneven traffic distribution. When traffic from the same source IP address is high, that traffic is consistently distributed to the same load balancer, preventing other load balancers from sharing the load.
[0062] The session persistence method provided in this application embodiment can be applied to the application environment shown in Figure 2. The terminal 202 can communicate with the server 204 through the router 206 and the load balancing cluster. The data storage system can store the data that the server 204 needs to process. The data storage system can be integrated on the server 204 or placed on the cloud or other network servers. Clients for the service can be deployed on the terminal 202. Requests sent by the terminal 202 are first evenly distributed to the load balancers in the load balancing cluster 208 via the router 206. Each load balancer uses multiple distribution strategies to distribute the received requests to multiple servers 204 for processing. The terminal 202 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, projection devices, etc. Portable wearable devices can include smartwatches, smart bracelets, head-mounted devices, etc. Headset devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. Server 204 can be a server cluster or distributed system consisting of multiple physical servers, or it can be a cloud server providing cloud computing services.
[0063] In an exemplary embodiment, as shown in FIG3, a session persistence method is provided. Taking the application of this method to the first load balancer in the load balancing cluster shown in FIG1 as an example, it can be understood that the first load balancer can refer to any load balancer in the load balancing cluster that receives a client request packet. The load balancing cluster includes other load balancers besides the first load balancer. For ease of explanation, the other load balancers in the load balancing cluster besides the first load balancer are defined as the second load balancer. The second load balancer may or may not have received the client request packet. The method includes the following steps S10 to S40. Wherein:
[0064] Step S10: Receive the client request message distributed by the router.
[0065] A client request message refers to a data packet sent by a client to a server to request a service or resource. A client request message may contain client information, information about the requested service or resource, etc.
[0066] A load balancing cluster refers to a group of load balancers working together to distribute client request packets to backend servers. In other words, the cluster consists of multiple load balancers. A load balancer is a device used to distribute received client request packets to multiple backend servers to achieve reasonable resource allocation and optimization. As an example, a load balancer can receive client request packets and then select appropriate backend servers based on a preset load balancing algorithm, such as round-robin, least connections, or hash algorithms. It can also return the responses from the backend servers to the client. In some feasible implementations, the load balancer can also detect whether backend servers are faulty and remove faulty backend servers from the load balancing pool.
[0067] A router is a network device used to forward data packets between networks. Operating at the network layer, its primary responsibility is to forward data packets from one network to another based on IP addresses. Routers use routing tables to determine the optimal path for data packets, ensuring that data reaches its destination efficiently and accurately. In some feasible implementations, with multiple equal-cost paths (ECMP), data packets can be distributed across multiple paths to achieve load balancing and redundancy.
[0068] For example, the router can learn the equivalent routes of each load balancer in the load balancing cluster in advance through BGP (Border Gateway Protocol). Then, after the client initiates a request, the router can extract the five-tuple information from the client request message through ECMP, namely, the source IP (Internet Protocol) address, destination IP address, source port number, destination port number, and protocol type. The router then performs a hash operation on the five-tuple information extracted from the client request message and distributes the client request message evenly to each load balancer in the load balancing cluster according to the hash operation result. The first load balancer can refer to the load balancer in the load balancing cluster that can receive the client request message distributed by the router. That is, after the router distributes the client request message, the first load balancer can receive the client request message distributed by the router.
[0069] Step S20: Query the target server corresponding to the client request message.
[0070] For example, after receiving a client request message, the first load balancer can select the corresponding target server for the client request message according to the pre-configured load balancing strategy.
[0071] In some feasible implementations, after receiving a client request message, it can be first determined whether to enable session persistence based on the configuration information of the first load balancer and the first client information carried in the client request message. If it is determined that session persistence is enabled, the load balancing strategy may include: extracting the first client information from the client request message, where the first client information may refer to information used to identify the client sending the client request message, including at least one of the following: client address, client identifier, etc.; then, firstly querying the local session persistence connection table to see if there is session persistence connection information corresponding to the first client information; if the session persistence connection information corresponding to the first client information cannot be found in the local session persistence connection table, selecting the corresponding target server for the client request message according to a preset load balancing algorithm, such as at least one of the following: round-robin algorithm, least connections algorithm, source IP algorithm, etc.; if the session persistence connection information corresponding to the first client information is found in the local session persistence connection table and is still within the session persistence time, determining the server specified in the session persistence connection information corresponding to the first client information as the target server.
[0072] Step S30: Based on the client request message and the target server information of the target server, generate the first session keep-alive information and send the first session keep-alive information to each second load balancer.
[0073] The target server information can refer to information that identifies the target server, including at least one of the following: the target server's address, identifier, etc. Session persistence information can refer to information used to ensure that multiple requests from the same client within a certain period are distributed to the same backend server. This includes at least the client identifier information of the client initiating the request and the server identifier information of the server receiving the request. It may also include the session connection time, so that the load balancer or other intermediate devices can identify and maintain session consistency. The first session persistence information can refer to the session persistence information selected and generated by the first load balancer. For example, assuming the request initiator of the client request message is client A and the target server is server A, the first session persistence information can be (A-clientip, A-ip, stickytime), where A-clientip refers to the IP address of client A, A-ip refers to the IP address of server A, and stickytime refers to the session persistence time. The first session persistence information can indicate that the request from A-clientip is distributed to the IP address A-ip of server A within the session persistence time.
[0074] As an example, when the target server is selected using a preset load balancing algorithm, first session persistence information can be generated based on the first client information in the client request message and the target server information. This first session persistence information is then sent to each of the second load balancers, achieving information synchronization of the first session persistence information across all load balancers in the load balancing cluster. Thus, during the session persistence period, if the client corresponding to the client request message sends a request again, it will be distributed to the same server after being distributed by any load balancer in the load balancing cluster.
[0075] In some feasible implementations, the first session persistence information can also be written into a local session persistence table.
[0076] As another example, when the target server is selected based on the local session persistence table, the client request message can be sent directly to the target server without regenerating and synchronizing session persistence information, thus saving communication resources, shortening request processing time, and improving request processing efficiency. In some feasible implementations, the locally recorded session persistence start time information can be updated to recalculate the session persistence time. Furthermore, a session persistence time reset command can be sent to each secondary load balancer to uniformly reset the session persistence time of the load balancing cluster.
[0077] Step S40: Send the client request message to the target server.
[0078] For example, after synchronizing session keep-alive information with the load balancing cluster, client request messages can be sent to the target server.
[0079] In some feasible implementations, the client request message can be sent to the target server only after a preset synchronization waiting time, or after receiving a synchronization response from each of the second load balancers based on the first session keep-alive information. This is to avoid situations where other load balancers make different load balancing decisions for the same client during the information synchronization process, leading to poor user experience such as session loss and data inconsistency.
[0080] In the above session persistence method, on the one hand, by deploying a load balancing cluster, the load balancing task is distributed to multiple load balancers, which can significantly improve the overall processing capacity and response speed of the system. Even if one or more load balancers fail, the other members can still continue to work, ensuring the continuous availability of the service and improving the quality of service. On the other hand, by receiving client request packets distributed by the router, querying the target server corresponding to the client request packet, and generating first session persistence information based on the client request packet and the target server information, the first session persistence information is sent to each of the second load balancers. This ensures that after any load balancer in the load balancing cluster receives a client request packet and determines the target server, it generates corresponding session persistence information and synchronizes this information with other load balancers in the cluster. This ensures that the session persistence information remains consistent across all load balancers in the cluster. Therefore, even if the same user's request is distributed to different load balancers in the cluster, the different load balancers distribute the received request according to the same session persistence information. This allows the same user's request to be distributed to the same server, avoiding session loss, data inconsistency, and other poor user experiences, further improving service quality.
[0081] In an exemplary embodiment, as shown in FIG4, after querying the target server corresponding to the client request message and before sending the client request message to the target server, steps S100 to S300 are further included. Wherein:
[0082] Step S100: Upon receiving the second session keep-alive information sent by the second load balancer, obtain the first client information corresponding to the client request message, and extract the second client information from the second session keep-alive information.
[0083] It's important to note that if a later request from the same client is sent to the load balancing cluster after the earlier request has generated and synchronized session persistence information, and within the session persistence period, any load balancer in the cluster will send the later request to the same server as the earlier request for processing. However, if the interval between multiple requests from the same client is short, and these requests are routed to different load balancers by the router, before the session persistence information has been synchronized, the different load balancers cannot find the corresponding session persistence information in their local session persistence tables. Therefore, they will select the corresponding target server for each client request packet based on the preset load balancing algorithm. This may result in different load balancers selecting different target servers for multiple client request packets from the same client, leading to poor user experience such as session loss and data inconsistency.
[0084] The second session keep-alive information can refer to the session keep-alive information selected and generated by any second load balancer. The second session keep-alive information can be the same as or different from the first session keep-alive information. That is, different load balancers can make the same or different load balancing decisions and select the same or different servers to process client request messages sent by the same client.
[0085] For example, after the first load balancer queries the target server corresponding to the client request message, but before the first load balancer sends the client request message to the target server, if it receives second session persistence information sent by any second load balancer, it can extract the first client information corresponding to the client request message from the communication information corresponding to the client request message or the information carried in the client request message, wherein the first client information is used to identify the client that sent the client request message; and extract the second client information from the second session persistence information, wherein the second client information refers to the information of the client that the second load balancer determines needs to maintain the session.
[0086] Step S200: If the first client information and the second client information are the same, query the candidate server corresponding to the second session keep-alive information.
[0087] The candidate server can refer to the server selected by the second load balancer that generates the second session keep-alive information for the request message it receives.
[0088] For example, after obtaining the first client information and the second client information, the first client information and the second client information are compared to see if they are the same. If they are different, it means that the two are load balancing decisions made for different clients and do not interfere with each other. There is no need to redetermine the target server, and the second session keep-alive information can be written into the local session keep-alive table. If they are the same, it means that the two are load balancing decisions made by different load balancers for the same client. Therefore, the decision needs to be unified. Therefore, server information is further extracted from the second session keep-alive information. Based on the server information extracted from the second session keep-alive information, the candidate server corresponding to the second session keep-alive information is determined.
[0089] Step S300: According to the preset server selection rules, reselect the target server from the candidate servers and the target server.
[0090] The preset server selection rule refers to the rule used to uniformly select different servers from different load balancers. As an example, the preset server selection rule can be a rule based on fixed parameters of the load balancer. The fixed parameters can be parameters that will not change during the transmission of client request messages, such as the load balancer's address, identifier, etc. The specific parameters can be determined according to the actual situation, and this embodiment does not impose any restrictions on them.
[0091] For example, after determining the candidate server, a new target server can be selected from the candidate server and the target server according to the preset server selection rules.
[0092] In this embodiment, if session keep-alive information is received from other load balancers before the client request message is distributed, a server reselection mechanism is triggered. One of the servers selected by different load balancers for the client is selected as the target server. By using preset server selection rules, a unified selection is made for different load balancers, thereby avoiding poor user experience such as session loss and data inconsistency, and further improving service quality.
[0093] In an exemplary embodiment, a target server is reselected from candidate servers and target servers according to a preset server selection rule, including steps S310 to S340. Wherein:
[0094] Step S310: Obtain the first server address information of the target server and the second server address information of the candidate server.
[0095] For example, after determining the candidate servers, the first server address information of the target server and the second server address information of the candidate servers are obtained. The first server address information can refer to the server IP address of the target server, and the second server address information can refer to the server IP address of the candidate server.
[0096] Step S320: If the first server address information and the second server address information are different, obtain the load balancing priority information.
[0097] The load balancing priority information is used to characterize the priority relationship between the first load balancer and each of the second load balancers. The priority relationship between the first load balancer and each of the second load balancers can be determined in advance based on the inherent parameters of the load balancers, the current actual situation, or performance test results. This embodiment does not impose any restrictions on this, but the load balancing priority information remains unchanged during the operation of the load balancing cluster to ensure that the same result is obtained when different load balancers perform server unification based on the load balancing priority information. For example, assuming that load balancer A has a higher priority than load balancer B, and the preset server selection rule is to determine the server selected by the load balancer with the highest priority as the target server, then when load balancer A selects server A for client A, and load balancer B selects server B for client A, regardless of whether load balancer A or load balancer B selects server A, based on the preset server selection rule, server A will be determined as the target server.
[0098] For example, after obtaining the first server address information and the second server address information, it is possible to first compare whether the first server address information and the second server address information are consistent. If they are consistent, it means that different load balancers select the same server for different client request packets sent to the same client, and there is no need to change the originally determined target server. If they are inconsistent, it means that different load balancers select different servers for different client request packets sent to the same client, and server unification is required. Load balancing priority information can be obtained.
[0099] Step S330: If the priority of the first load balancer is determined to be higher than that of the second load balancer based on the load balancing priority information, the target server remains unchanged.
[0100] For example, if the priority of the first load balancer is determined to be higher than that of the second load balancer based on the load balancing priority information, the decision of the first load balancer shall be followed, and therefore the target server shall remain unchanged without any change.
[0101] Step S340: If the priority of the second load balancer is determined to be higher than that of the first load balancer based on the load balancing priority information, the candidate server is determined as the target server.
[0102] For example, if the priority of the second load balancer is determined to be higher than that of the first load balancer based on the load balancing priority information, the decision of the second load balancer shall be followed, and the candidate server selected by the second load balancer shall be determined as the target server.
[0103] In some feasible implementations, after the target server changes, the first session keep-alive information can be updated. If the first session keep-alive information has already been written into the local session keep-alive table, the local session keep-alive table can be updated.
[0104] In this embodiment, by setting a pre-defined load balancing priority, it can be ensured that when different load balancers select target servers individually, they can determine the same target server, thereby achieving the unification of the target server for the same client, avoiding poor user experience such as session loss and data inconsistency, and further improving service quality.
[0105] In an exemplary embodiment, obtaining load balancing priority information includes steps S321 to S323. Wherein:
[0106] Step S321: Obtain the first load balancing address information of the first load balancer and the second load balancing address information of the second load balancer.
[0107] The first load balancing address information can refer to the IP address of the first load balancer. The second load balancing address information can refer to the IP address of the second load balancer. The first load balancing address information is an inherent parameter of the first load balancer, which it can directly obtain. The second load balancing address information is carried in the communication information when the first load balancer receives the second session persistence information. Therefore, neither can be obtained without additional operations, and since they are inherent parameters of the load balancer, they will not change during the session persistence process. Determining the load balancer priority based on the load balancing address information can ensure consistency in server selection, simplify operations, and save resources.
[0108] For example, the first load balancer address information can be extracted from the attribute information of the first load balancer, and the second load balancer address information can be extracted from the communication information of the second session keep-alive information.
[0109] Step S322: Determine the priorities of the first load balancer and the second load balancer based on the numerical values of the first load balancer address information and the second load balancer address information, and generate load balancer priority information, wherein the priority of the load balancer is positively or negatively correlated with the numerical values of the load balancer address information.
[0110] For example, the first numerical value of the first load balancing address information and the second numerical value of the second load balancing address information can be detected according to a unified numerical calculation algorithm or a unified numerical statistical method. For instance, both the first and second load balancing address information can be converted into binary values, and then the size relationship of the converted binary values can be compared. Furthermore, by comparing the first and second numerical values, a higher priority can be set for the load balancer corresponding to the load balancing address information with the larger numerical value, or a higher priority can be set for the load balancer corresponding to the load balancing address information with the smaller numerical value. The specific choice can be determined according to the actual situation, and this embodiment does not impose any restrictions on this. After determining the priority of each load balancer, the corresponding load balancing priority information can be generated according to the priority sorting result.
[0111] In this embodiment, the priority of the load balancer is determined based on its address information, which can not only ensure the consistency of server selection, but also simplify the operation and save resources.
[0112] In one exemplary embodiment, the first load balancer stores a session persistence table; querying the target server corresponding to a client request message includes:
[0113] If the target server corresponding to the client request message is not found in the session persistence table, the target server corresponding to the client request message is detected according to the preset load balancing strategy.
[0114] The session persistence table can refer to a data table used to store session persistence information.
[0115] For example, firstly, the system checks if there is session persistence information corresponding to the first client information in the local session persistence table; if no session persistence information corresponding to the first client information is found in the local session persistence table, the system selects the corresponding target server for the client request packet according to at least one of the preset load balancing algorithms, such as round-robin algorithm, least connections algorithm, and source IP algorithm; if session persistence information corresponding to the first client information is found in the local session persistence table and the session persistence period is still in effect, the server specified in the session persistence information corresponding to the first client information is determined as the target server.
[0116] In this embodiment, by distributing session persistence tables on each load balancer in the load balancing cluster and distributively storing session persistence information, the synchronization and consistency of session persistence information within the cluster can be guaranteed. Furthermore, there is no need to deploy a dedicated database, saving database deployment resources and communication resources used by the load balancer to communicate with the database each time it queries session persistence information.
[0117] In one exemplary embodiment, the method further includes:
[0118] Upon receiving the second session keep-alive information from the second load balancer, the locally stored session keep-alive table is updated based on the second session keep-alive information.
[0119] For example, during the operation of the first load balancer, it can receive session persistence information sent by other load balancers in the load balancer cluster at any time. Upon receiving the second session persistence information sent by the second load balancer, it updates the locally stored session persistence table based on the second session persistence information.
[0120] In this embodiment, by receiving and storing the second session keep-alive information, the consistency of the session keep-alive information between the first load balancer and other load balancers in the load balancer cluster can be maintained, thereby avoiding poor experience such as session loss and data inconsistency, and further improving service quality.
[0121] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0122] Based on the same inventive concept, this application also provides a session persistence apparatus for implementing the session persistence method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more session persistence apparatus embodiments provided below can be found in the limitations of the session persistence method described above, and will not be repeated here.
[0123] In an exemplary embodiment, as shown in FIG5, a session persistence device is provided. This device is applied to a first load balancer in a load balancing cluster, which further includes at least one second load balancer. The device includes: a receiving module 502, a querying module 504, a generating module 506, and a sending module 508, wherein:
[0124] The receiving module 502 is used to receive client request messages distributed by the router;
[0125] Query module 504 is used to query the target server corresponding to the client request message;
[0126] The generation module 506 is used to generate first session keep-alive information based on the client request message and the target server information of the target server, and send the first session keep-alive information to each second load balancer.
[0127] The sending module 508 is used to send client request messages to the target server.
[0128] In one exemplary embodiment, the session persistence device further includes a server reset module, which, after querying the target server corresponding to the client request message and before sending the client request message to the target server, is configured to:
[0129] Upon receiving the second session keep-alive information sent by the second load balancer, obtain the first client information corresponding to the client request message, and extract the second client information from the second session keep-alive information;
[0130] If the information of the first client is the same as that of the second client, query the candidate server corresponding to the second session keep-alive information;
[0131] Based on the preset server selection rules, a new target server is selected from the candidate servers and the target server.
[0132] In one exemplary embodiment, the server reset module is further configured to:
[0133] Obtain the first server address information of the target server, and the second server address information of the candidate servers;
[0134] If the first server address information and the second server address information are different, obtain the load balancing priority information;
[0135] If, based on the load balancing priority information, the priority of the first load balancer is determined to be higher than that of the second load balancer, the target server remains unchanged.
[0136] If, based on the load balancing priority information, the priority of the second load balancer is determined to be higher than that of the first load balancer, the candidate server is selected as the target server.
[0137] In one exemplary embodiment, the server reset module is further configured to:
[0138] Obtain the first load balancer address information of the first load balancer and the second load balancer address information of the second load balancer;
[0139] Based on the numerical values of the first load balancer address information and the second load balancer address information, the priorities of the first load balancer and the second load balancer are determined, and load balancer priority information is generated. The priority of the load balancer is positively or negatively correlated with the numerical value of the load balancer address information.
[0140] In one exemplary embodiment, a session persistence table is stored on the first load balancer; the query module 504 is further configured to:
[0141] If the target server corresponding to the client request message is not found in the session persistence table, the target server corresponding to the client request message is detected according to the preset load balancing strategy.
[0142] In one exemplary embodiment, the session persistence device further includes an update module, which is used to:
[0143] Upon receiving the second session keep-alive information from the second load balancer, the locally stored session keep-alive table is updated based on the second session keep-alive information.
[0144] The modules in the aforementioned session holding device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can invoke and execute the operations corresponding to each module.
[0145] In an exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram is shown in Figure 6. The computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is connected to the system bus via the I / O interfaces. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes non-volatile storage media and internal memory. The non-volatile storage media stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database of the computer device stores object data. The I / O interfaces of the computer device are used for exchanging information between the processor and external devices. The communication interface of the computer device is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a session persistence method.
[0146] Those skilled in the art will understand that the structure shown in Figure 6 is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0147] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0148] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0149] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0150] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0151] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, database, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0152] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0153] The above embodiments are merely illustrative of several implementation methods of this application, and their descriptions are relatively specific and detailed. However, they should not be construed as limiting the scope of this application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A session persistence method, characterized in that, The method is applied to a first load balancer in a load balancing cluster, the load balancing cluster further including at least one second load balancer; the method includes: receiving a client request packet distributed by a router; querying the target server corresponding to the client request packet; generating first session persistence information based on the client request packet and the target server information of the target server, and sending the first session persistence information to each of the second load balancers; sending the client request packet to the target server; after querying the target server corresponding to the client request packet, and before sending the client request packet to the target server, the method further includes: upon receiving second session persistence information sent by the second load balancer, obtaining first client information corresponding to the client request packet, and extracting second client information from the second session persistence information; if the first client information and the second client information are the same, querying the candidate server corresponding to the second session persistence information; and reselecting a target server from the candidate servers and the target server according to a preset server selection rule.
2. The method according to claim 1, characterized in that, The step of reselecting a target server from the candidate servers and the target server according to a preset server selection rule includes: obtaining first server address information of the target server and second server address information of the candidate servers; obtaining load balancing priority information when the first server address information and the second server address information are different; keeping the target server unchanged when the priority of the first load balancer is determined to be higher than the priority of the second load balancer according to the load balancing priority information; and determining the candidate server as the target server when the priority of the second load balancer is determined to be higher than the priority of the first load balancer according to the load balancing priority information.
3. The method according to claim 2, characterized in that, The step of obtaining load balancing priority information includes: obtaining the first load balancing address information of the first load balancer and the second load balancing address information of the second load balancer; determining the priority of the first load balancer and the second load balancer based on the numerical values of the first load balancing address information and the second load balancing address information, and generating load balancing priority information, wherein the priority of the load balancer is positively or negatively correlated with the numerical value of the load balancing address information.
4. The method according to claim 1, characterized in that, The first load balancer stores a session persistence table; The step of querying the target server corresponding to the client request message includes: if the target server corresponding to the client request message is not found in the session keep-alive table, detecting the target server corresponding to the client request message according to a preset load balancing strategy.
5. The method according to claim 4, characterized in that, The method further includes: upon receiving second session persistence information sent by the second load balancer, updating the locally stored session persistence table based on the second session persistence information.
6. A conversation holding device, characterized in that, The device is applied to a first load balancer in a load balancing cluster, the load balancing cluster further including at least one second load balancer; the device includes: a receiving module for receiving client request packets distributed by a router; a query module for querying the target server corresponding to the client request packet; a generating module for generating first session persistence information based on the client request packet and the target server information of the target server, and sending the first session persistence information to each of the second load balancers; a sending module for sending the client request packet to the target server; and a server reset module, which, after querying the target server corresponding to the client request packet and before sending the client request packet to the target server, is configured to, upon receiving second session persistence information sent by the second load balancer, obtain first client information corresponding to the client request packet and extract second client information from the second session persistence information; if the first client information and the second client information are the same, query the candidate server corresponding to the second session persistence information; and reselect a target server from the candidate servers and the target server according to a preset server selection rule.
7. The apparatus according to claim 6, characterized in that, The server reset module is further configured to: obtain first server address information of the target server and second server address information of the candidate server; obtain load balancing priority information when the first server address information and the second server address information are different; keep the target server unchanged when the priority of the first load balancer is determined to be higher than the priority of the second load balancer according to the load balancing priority information; and determine the candidate server as the target server when the priority of the second load balancer is determined to be higher than the priority of the first load balancer according to the load balancing priority information.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 5.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Session management method and device and load balancer
CN106549875A