Session holding method and device, equipment, storage medium and program product
By deploying multiple load balancers in a load balancing cluster and synchronizing session-keeping connection information, the problem of insufficient processing capacity of a single load balancer and out-synchronization of session data is solved, achieving high availability and high-quality services.
Patent Information
- Application Number
- CN202411770891.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2044-12-04
AI Technical Summary
In a load balancing cluster, a single load balancer cannot withstand huge traffic pressure, and multiple load balancers may cause user session data to be out of sync, resulting in session loss and data inconsistency.
By deploying a load balancing cluster, the load balancing tasks are distributed to multiple load balancers. After the first load balancer receives the client request message, it querys the target server, generates session keeping connection information, and synchronizes with other load balancers to ensure that the session keeping connection information consistent.
It significantly improves the overall processing capacity and response speed of the system, ensures the continuous availability of services, and even if a load balancer fails, other members can continue to work, avoid session loss, data inconsistency and other problems, and improve service quality.
Smart Images

Figure CN119520585A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a session maintenance method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art
[0002] With the rapid development of network technology, the number of network service users is increasing. When multiple users access a website or application at the same time, in order to improve the availability and response speed of the service, multiple servers are usually used to share the task of request processing, so as to share the load and improve the overall performance and response speed, and ensure that even if a server fails, other servers can continue to provide services. However, in this case, if the user's previous request is assigned to one server, and the subsequent request is assigned to another server, it may cause the user session data to be out of sync, resulting in a poor user experience or functional failure.
[0003] In traditional technology, the load balancer can achieve session persistence. When using the TCP protocol, the load balancer can maintain the session based on the client's source IP address and distribute multiple requests from the same client IP to the same server on the backend for processing.
[0004] However, as the user base of Internet applications continues to grow, a single load balancer may not be able to withstand the huge 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 back-end servers, causing users to encounter poor experiences such as session loss and data inconsistency during use. Therefore, whether it is a single load balancer or multiple load balancers, the service quality is poor. Summary of the invention
[0005] Based on this, it is necessary to provide a session maintenance method, apparatus, computer device, computer-readable storage medium and computer program product that can improve service quality in response to the above technical problems.
[0006] In a first aspect, the present application provides a session maintenance method, which is applied to a first load balancer in a load balancing cluster, where the load balancing cluster also includes at least one second load balancer; the method includes:
[0007] Receive client request messages distributed by routers;
[0008] Query the target server corresponding to the client request message;
[0009] Generate first session connection information based on the client request message and target server information of the target server, and send the first session connection information 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] When receiving the second session maintaining connection information sent by the second load balancer, obtaining the first client information corresponding to the client request message, and extracting the second client information from the second session maintaining connection information;
[0013] When the first client information is the same as the second client information, querying a candidate server corresponding to the second session connection information;
[0014] Reselect the target server from the candidate servers and the target server according to the preset server selection rule.
[0015] In one embodiment, reselecting a target server from the candidate servers and the target server according to a preset server selection rule includes:
[0016] Obtaining first server address information of the target server and second server address information of the server to be selected;
[0017] When the first server address information and the second server address information are different, obtaining load balancing priority information;
[0018] When it is determined according to the load balancing priority information that the priority of the first load balancer is higher than the priority of the second load balancer, the target server is kept unchanged;
[0019] When it is determined according to the load balancing priority information that the priority of the second load balancer is higher than the priority of the first load balancer, the server to be selected is determined as the target server.
[0020] In one embodiment, obtaining load balancing priority information includes:
[0021] Obtaining first load balancing address information of the first load balancer and second load balancing address information of the second load balancer;
[0022] According to the numerical values of the first load balancing address information and the second load balancing address information, the priorities of the first load balancer and the second load balancer are determined, and load balancing priority information is generated, wherein the priority of the load balancer is positively correlated or negatively correlated with the numerical value of the load balancing address information.
[0023] In one embodiment, a session persistence connection table is stored on the first load balancer; querying a target server corresponding to a client request message includes:
[0024] When the target server corresponding to the client request message is not found in the session maintenance connection table, the target server corresponding to the client request message is detected according to a preset load balancing strategy.
[0025] In one embodiment, the method further comprises:
[0026] When the second session maintaining connection information sent by the second load balancer is received, the locally stored session maintaining connection table is updated based on the second session maintaining connection information.
[0027] In a second aspect, the present application further provides a session maintaining device, which is applied to a first load balancer in a load balancing cluster, and the load balancing cluster also includes at least one second load balancer; the device includes:
[0028] A receiving module, used for receiving client request messages distributed by the router;
[0029] A query module, used to query the target server corresponding to the client request message;
[0030] A generating module, configured to generate first session maintaining connection information based on the client request message and the target server information of the target server, and send the first session maintaining connection information to each second load balancer;
[0031] The sending module is used to send the client request message to the target server.
[0032] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0033] Receive client request messages distributed by routers;
[0034] Query the target server corresponding to the client request message;
[0035] Generate first session connection information based on the client request message and target server information of the target server, and send the first session connection information to each second load balancer;
[0036] Send the client request message to the target server.
[0037] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the following steps are implemented:
[0038] Receive client request messages distributed by routers;
[0039] Query the target server corresponding to the client request message;
[0040] Generate first session connection information based on the client request message and target server information of the target server, and send the first session connection information to each second load balancer;
[0041] Send the client request message to the target server.
[0042] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0043] Receive client request messages distributed by routers;
[0044] Query the target server corresponding to the client request message;
[0045] Generate first session connection information based on the client request message and target server information of the target server, and send the first session connection information to each second load balancer;
[0046] Send the client request message to the target server.
[0047] The above-mentioned session maintenance method, apparatus, computer device, computer-readable storage medium and computer program product, on the one hand, by deploying a load balancing cluster and distributing the load balancing tasks to multiple load balancers, can significantly improve the overall processing capability and response speed of the system. Even if one or several load balancers fail, other members can still continue to work, thereby ensuring the continuous availability of the service and improving the service quality. On the other hand, by receiving the client request message distributed by the router, querying the target server corresponding to the client request message, generating the first session connection maintenance information based on the client request message and the target server information of the target server, and sending the first session connection maintenance information to each second load balancer, and sending the client request message to the target server, it is achieved that after any load balancer in the load balancing cluster receives the client request message and determines the target server, the corresponding session connection maintenance information is generated, and the session connection maintenance information is synchronized with other load balancers in the load balancing cluster, so that the session connection maintenance information is consistent on each load balancer in the load balancing cluster. In this way, even if the request of the same user is distributed to different load balancers in the load balancing cluster, different load balancers distribute the received requests according to the same session connection maintenance information, so that the request of the same user can be distributed to the same server, thereby avoiding poor experiences such as session loss and data inconsistency, and further improving service quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0049] Figure 1 It is an application environment diagram of the session maintenance method in the related art;
[0050] Figure 2 A diagram of an application environment of a session maintaining method in an embodiment;
[0051] Figure 3 A schematic diagram of a flow chart of a session maintaining method in an embodiment;
[0052] Figure 4 A flow chart of a session maintaining method in another embodiment;
[0053] Figure 5 A structural block diagram of a session maintaining device in one embodiment;
[0054] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0056] With the rapid development of network technology, there are more and more users of network services. When multiple users access a website or application at the same time, in order to improve the availability and response speed of the service, multiple servers are usually used to share the task of request processing, so as to share the load and improve the overall performance and response speed, and ensure that even if a server fails, other servers can continue to provide services. However, in this case, if the user's previous request is assigned to one server, and the subsequent request is assigned to another server, it may cause the user session data to be out of sync, resulting in poor user experience or functional failure. In traditional technology, the load balancer can achieve session persistence. When using the TCP protocol, the load balancer can maintain the session based on the client's source IP address, and distribute multiple requests from the same client IP to the same server on the backend for processing.
[0057] For example, the 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. At this time, client C has another request. If there is no session persistence function, the load balancer may distribute this request to server B, but server B does not have the user's login information, and re-login verification is required; if there is a session persistence function, the load balancer will distribute related requests to the same backend server, that is, the request received later will be sent to server A, and there is no need to re-login.
[0058] However, as the user base of Internet applications continues to grow, a single load balancer may not be able to withstand the huge 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, causing users to experience poor experiences such as session loss and data inconsistency during use.
[0059] For example, Figure 1As shown, assuming that the load balancing cluster 106 includes load balancers A, B and C, and equal-cost routes to load balancers A, B and C are set on the router 104, when the client 102 initiates a request to access the load balancing cluster 106, the router 104 can obtain the five-tuple of the request through the ECMP (Equal-Cost Multi-Path) method, that is, the source IP (Internet Protocol) address, the destination IP address, the source port number, the destination port number and the protocol type, perform a hash operation on the five-tuple, and evenly distribute the request to each load balancer in the load balancing cluster 106 according to the hash operation result; then, the load balancer distributes the received request to the back-end server A108 or server B110 according to the configured distribution strategy, such as polling, minimum number of connections, etc. In this case, even if each load balancer is configured with session persistence, assuming that the same client 102 sends requests 1, 2, and 3, request 1 arrives at load balancer A, and server A108 is selected through the distribution policy, and subsequent requests from the client 102 that arrive at load balancer A will be forwarded to server A108 within the session persistence time; requests 2 and 3 arrive at load balancer C, and server B110 is selected through the distribution policy, and subsequent requests from the client 102 that arrive at load balancer C will be forwarded to server B110 within the session persistence time; in this way, the requests of the same client 102 will still be distributed to different servers A108 and server B110, and the session persistence function in each load balancer is valid, but for users, they will still encounter poor experiences such as session loss and data inconsistency.
[0060] Therefore, whether it is a single load balancer or multiple load balancers, the service quality is poor.
[0061] In this case, in the related technology, the router can perform hash operations based on the triple, that is, the source IP address, the destination IP address and the protocol type. After the hash operation, the traffic of the same client with the same source IP address will be distributed to the same load balancer, and the session retention function will be implemented on the same load balancer, so that the requests with the same source address will always be distributed to the same application server. However, this method has the problem of uneven traffic distribution. When the traffic of the same source IP address is large, the traffic of the source IP address is always distributed to the same load balancer and cannot be shared by other load balancers.
[0062] The session maintenance method provided in the embodiment of the present application can be applied to Figure 2In the application environment shown. Among them, 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 it can be placed on the cloud or other network servers. A client of the service can be deployed on the terminal 202. The request sent by the terminal 202 first passes through the router 206 and is evenly distributed to each load balancer in the load balancing cluster 208. Each load balancer adopts a variety of distribution strategies to distribute the received requests to multiple servers 204 for processing. Among them, the terminal 202 can be, but is not limited to, various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. Head-mounted devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The server 204 may be a server cluster or a distributed system composed of multiple physical servers, or may be a cloud server providing cloud computing services.
[0063] In an exemplary embodiment, Figure 3 As shown, a session maintenance method is provided, which is applied to Figure 1 The first load balancer in the load balancing cluster in the example is used for explanation. It can be understood that the first load balancer can refer to any load balancer in the load balancing cluster that receives the client request message. In addition to the first load balancer, the load balancing cluster also includes other load balancers. For the sake of convenience, the other load balancers in the load balancing cluster except the first load balancer are determined as the second load balancer. The second load balancer may receive or not receive the client request message. The method includes the following steps S10 to S40. Among them:
[0064] Step S10: receiving a client request message distributed by a router.
[0065] The client request message may refer to a data packet sent by the client to the server to request a service or resource. The client request message may include client information, information about the requested service or resource, and the like.
[0066] A load balancing cluster may refer to a group of load balancers working together, which jointly undertake the task of distributing client request messages to backend servers, that is, the load balancing cluster is composed of multiple load balancers. A load balancer may refer to a device used to distribute received client request messages to multiple backend servers to achieve reasonable allocation and optimization of resources. As an example, a load balancer may receive a client request message, and then select a suitable backend server according to a preset load balancing algorithm, such as polling, minimum number of connections, hash algorithm, etc., and may also return the response of the backend server to the client. In some feasible implementations, the load balancer may also detect whether there is a fault in the backend server and remove the faulty backend server from the load balancing pool.
[0067] A router may refer to a network device used to forward data packets between networks. A router works at the network layer. Its main responsibility is to forward data packets from one network to another based on IP addresses. The router uses a routing table to determine the best path for data packets to ensure that data can reach the destination efficiently and accurately. In some feasible implementations, in the case of multiple equal-cost paths (ECMP), data packets can be distributed to multiple paths to achieve load balancing and redundancy.
[0068] Exemplarily, the router can learn the equivalent routes of each load balancer in the load balancing cluster in advance through BGP (Border Gateway Protocol). In this way, after the client initiates a request, the router can extract five-tuple information from the client request message through ECMP, that is, the source IP (Internet Protocol) address, the destination IP address, the source port number, the destination port number and the protocol type, perform a hash operation on the five-tuple information extracted from the client request message, and evenly distribute the client request message to each load balancer in the load balancing cluster according to the hash operation result; the first load balancer can refer to a 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, querying the target server corresponding to the client request message.
[0070] Exemplarily, after receiving the client request message, the first load balancer may select a corresponding target server for the client request message according to a pre-configured load balancing policy.
[0071] In some feasible implementations, after receiving the client request message, it can be determined whether to enable the session persistence function according to the configuration information of the first load balancer and the first client information carried in the client request message; in the case where it is determined that the session persistence function 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 that sends the client request message, including at least one of a client address and a client identification number; further, first querying whether there is session persistence connection information corresponding to the first client information in the local session persistence connection table; in the case where the session persistence connection information corresponding to the first client information cannot be queried in the local session persistence connection table, selecting a corresponding target server for the client request message according to a preset load balancing algorithm, such as at least one of a polling algorithm, a minimum connection algorithm, a source IP algorithm, etc.; in the case where the session persistence connection information corresponding to the first client information is queried in the local session persistence connection table and the current session 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: Generate first session connection information based on the client request message and the target server information of the target server, and send the first session connection information to each second load balancer.
[0073] The target server information may refer to information that can identify the target server, including at least one of the address and identification number of the target server. The session connection information may refer to information used to ensure that multiple requests from the same client within a period of time are distributed to the same backend server, including at least the client identification information of the client as the request initiator and the server identification information of the server as the request receiver, and may also include the session connection time, so that the load balancer or other intermediate devices can identify and maintain the consistency of the session. The first session connection information may refer to the session connection information generated by the first load balancer for server selection. For example, assuming that the request initiator of the client request message is client A and the target server is server A, the first session connection information may be (A-clientip, A-ip, stickytime), wherein 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 connection time. The first session connection information may represent that the request from A-clientip is distributed to the IP address A-ip of server A within the session connection time.
[0074] As an example, when the target server is selected and determined by a preset load balancing algorithm, the first session maintenance connection information can be generated based on the first client information in the client request message and the target server information of the target server, and the first session maintenance connection information is sent to each second load balancer to achieve information synchronization of the first session maintenance connection information on each load balancer in the load balancing cluster. In this way, within the session maintenance time, the client corresponding to the client request message sends a request again, and after being distributed by any load balancer in the load balancing cluster, it will be distributed to the same server.
[0075] In some feasible implementations, the first session maintaining connection information may also be written into a local session maintaining connection table.
[0076] As another example, when the target server is selected and determined based on the local session persistence connection table, the client request message can be directly sent to the target server without regenerating and synchronizing the session persistence connection information, so as to save communication resources, shorten the request processing time, and improve the request processing efficiency. In some feasible implementations, the locally recorded session persistence start time information can be updated to recalculate the session persistence time, and a session persistence time reset instruction can be sent to each second load balancer to uniformly reset the session persistence time of the load balancing cluster.
[0077] Step S40: sending the client request message to the target server.
[0078] Exemplarily, after synchronizing the session connection information with the load balancing cluster, the client request message may be sent to the target server.
[0079] In some feasible implementations, the client request message may be sent to the target server after a preset synchronization waiting time or after receiving a synchronization response from each second load balancer based on the first session connection maintenance information, so as to avoid other load balancers making different load balancing decisions for the same client during the information synchronization process, thereby causing a bad 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 and distributing the load balancing tasks to multiple load balancers, the overall processing capability and response speed of the system can be significantly improved. Even if one or several load balancers fail, other members can still continue to work, ensuring the continuous availability of the service and improving the service quality. On the other hand, by receiving the client request message distributed by the router, querying the target server corresponding to the client request message, generating the first session connection maintenance information based on the client request message and the target server information of the target server, and sending the first session connection maintenance information to each second load balancer, and sending the client request message to the target server, it is achieved that after any load balancer in the load balancing cluster receives the client request message and determines the target server, the corresponding session connection maintenance information is generated, and the session connection maintenance information is synchronized with other load balancers in the load balancing cluster, so that the session connection maintenance information is consistent on each load balancer in the load balancing cluster. In this way, even if the request of the same user is distributed to different load balancers in the load balancing cluster, different load balancers distribute the received requests according to the same session connection maintenance information, so that the request of the same user can be distributed to the same server, thereby avoiding poor experiences such as session loss and data inconsistency, and further improving service quality.
[0081] In an exemplary embodiment, Figure 4 As shown, after querying the target server corresponding to the client request message and before sending the client request message to the target server, it also includes steps S100 to S300. Among them:
[0082] Step S100: upon receiving the second session maintaining connection information sent by the second load balancer, obtaining the first client information corresponding to the client request message, and extracting the second client information from the second session maintaining connection information.
[0083] It should be noted that if a subsequent request from the same client is sent to the load balancing cluster within the session retention time after its previous request generates and synchronizes the session retention information, then any load balancer in the load balancing cluster will send the subsequent request to the same server as the previous request for processing. However, if the interval between multiple requests from the same client is short, and multiple requests are routed to different load balancers by the router, before the session retention information has time to be synchronized, different load balancers cannot query the corresponding session retention information from the local session retention table, and therefore will select the corresponding target server for each received client request message based on the preset load balancing algorithm. In this case, different load balancers may select different target servers for multiple client request messages from the same client, causing users to experience poor experiences such as session loss and data inconsistency during use.
[0084] The second session maintaining connection information may refer to the session maintaining connection information generated by any second load balancer performing server selection. The second session maintaining connection information may be the same as or different from the first session maintaining connection information, that is, different load balancers may make the same or different load balancing decisions and select the same or different servers for processing the client request message sent by the same client.
[0085] Exemplarily, 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 the second session maintenance connection information sent by any second load balancer is received, the first client information corresponding to the client request message can be extracted 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 sends the client request message; and the second client information is extracted from the second session maintenance connection information, wherein the second client information refers to the information of the client that needs to maintain the session determined by the second load balancer.
[0086] Step S200: when the first client information is the same as the second client information, query the candidate server corresponding to the second session connection information.
[0087] The server to be selected may refer to a server selected by the second load balancer that generates the second session connection information for the request message received by it.
[0088] Exemplarily, after obtaining the first client information and the second client information, compare whether the first client information and the second client information are the same; if the two 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 connection maintenance information can be written into the local session connection maintenance table; if the two are the same, it means that the two are load balancing decisions made by different load balancers for the same client, so it is necessary to unify the decisions, therefore, further extract the server information from the second session connection maintenance information, and determine the candidate server corresponding to the second session connection maintenance information based on the server information extracted from the second session connection maintenance information.
[0089] Step S300: reselect a target server from the candidate servers and the target server according to a preset server selection rule.
[0090] The preset server selection rule may refer to a rule for making a unified selection of different servers selected by different load balancers. As an example, the preset server selection rule may be a rule for selecting based on fixed parameters of the load balancer, wherein the fixed parameters may refer to parameters that will not change during the transmission of the client request message, such as the address and identification number of the load balancer, etc., which may be determined based on actual conditions, and this embodiment does not limit this.
[0091] Exemplarily, after the candidate server is determined, one of the candidate servers and the target server may be reselected as the target server according to a preset server selection rule.
[0092] In this embodiment, by receiving session connection maintenance information sent by other load balancers before distributing the client request message, the server reselection mechanism is triggered, and one server is selected as the target server from the servers selected for the client by different load balancers. By presetting the server selection rules, a unified selection is made for different load balancers, thereby avoiding poor experiences such as session loss and data inconsistency, and further improving the service quality.
[0093] In an exemplary embodiment, according to a preset server selection rule, reselecting a target server from the candidate servers and the target server includes steps S310 to S340. In which:
[0094] Step S310, obtaining first server address information of a target server and second server address information of a server to be selected.
[0095] Exemplarily, after determining the server to be selected, first obtain the first server address information of the target server and the second server address information of the server to be selected, wherein the first server address information may refer to the server IP address of the target server and the second server address information may refer to the server IP address of the server to be selected.
[0096] Step S320: When the first server address information and the second server address information are different, obtain load balancing priority information.
[0097] Among them, the load balancing priority information is used to characterize the priority relationship between the first load balancer and each second load balancer. The priority relationship between the first load balancer and each second load balancer can be determined in advance based on the inherent parameters of the load balancer, the current actual situation or the performance test results, etc. This embodiment does not limit this, but the load balancing priority information remains unchanged during the operation of the load balancing cluster to ensure that different load balancers can obtain the same results when they unify servers based on the load balancing priority information. For example, assuming that the priority of load balancer A is higher than that of 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, in this way, when load balancer A selects server A for client A and load balancer B selects server B for client A, whether it is load balancer A or load balancer B, based on the preset server selection rule, server A will be determined as the target server.
[0098] Exemplarily, after obtaining the first server address information and the second server address information, you can first compare whether the first server address information and the second server address information are consistent; if the two are consistent, it means that different load balancers select the same server for different client request messages sent by the same client, and there is no need to change the originally determined target server; if the two are inconsistent, it means that different load balancers select different servers for different client request messages sent by the same client, and the servers need to be unified, and the load balancing priority information can be obtained.
[0099] Step S330: When it is determined according to the load balancing priority information that the priority of the first load balancer is higher than the priority of the second load balancer, the target server is kept unchanged.
[0100] Exemplarily, when it is determined that the priority of the first load balancer is higher than the priority of the second load balancer according to the load balancing priority information, the decision of the first load balancer is obeyed, so there is no need to change the target server, and the target server remains unchanged.
[0101] Step S340: When it is determined according to the load balancing priority information that the priority of the second load balancer is higher than the priority of the first load balancer, the server to be selected is determined as the target server.
[0102] Exemplarily, when it is determined according to the load balancing priority information that the priority of the second load balancer is higher than that of the first load balancer, the decision of the second load balancer is obeyed, and thus the candidate server selected by the second load balancer is determined as the target server.
[0103] In some feasible implementations, after the target server is changed, the first session persistence information may be updated. If the first session persistence information has been written into the local session persistence table, the local session persistence table may be updated.
[0104] In this embodiment, by pre-setting the load balancing priority, it can be ensured that when different load balancers select the target server separately, they can determine the same target server, thereby achieving the unification of the target server corresponding to the same client, avoiding poor experiences 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. In which:
[0106] Step S321, obtaining first load balancing address information of the first load balancer and second load balancing address information of the second load balancer.
[0107] Among them, the first load balancing address information may refer to the IP address of the first load balancer. The second load balancing address information may 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, and the first load balancer can directly obtain it. The second load balancing address information is information carried in the communication information when the first load balancer receives the second session connection maintenance information. Therefore, both can be obtained without performing additional operations, and they are inherent parameters of the load balancer and will not change during the session maintenance process. Determining the priority of the load balancer based on the load balancing address information can not only ensure the consistency of server selection, but also simplify operations and save resources.
[0108] Exemplarily, the first load balancing address information may be extracted from the attribute information of the first load balancer, and the second load balancing address information may be extracted from the communication information of the second session holding connection information.
[0109] Step S322, determining the priority of the first load balancer and the second load balancer according to 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 correlated or negatively correlated with the numerical value of the load balancing address information.
[0110] Exemplarily, 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 example, the first load balancing address information and the second load balancing address information can be converted into binary values to compare the size relationship of the converted binary values; further, by comparing the first numerical value and the second numerical value, a higher priority can be set for the load balancer corresponding to the load balancing address information with a larger numerical value, and a higher priority can be set for the load balancer corresponding to the load balancing address information with a smaller numerical value. The specific priority can be determined according to actual conditions, and this embodiment is not limited to 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 the address information of the load balancer, which can not only ensure the consistency of server selection, but also simplify operations and save resources.
[0112] In an exemplary embodiment, a session persistence connection table is stored on the first load balancer; querying a target server corresponding to a client request message includes:
[0113] When the target server corresponding to the client request message is not found in the session maintenance connection table, the target server corresponding to the client request message is detected according to a preset load balancing strategy.
[0114] The session maintaining connection table may refer to a data table used to store session maintaining connection information.
[0115] Exemplarily, first query whether there is session persistence connection information corresponding to the first client information in the local session persistence connection table; if the session persistence connection information corresponding to the first client information cannot be queried in the local session persistence connection table, select a corresponding target server for the client request message according to a preset load balancing algorithm, such as at least one of a polling algorithm, a minimum connection algorithm, a source IP algorithm, etc.; if the session persistence connection information corresponding to the first client information is queried in the local session persistence connection table, and the current session is still within the session persistence time, determine the server specified in the session persistence connection information corresponding to the first client information as the target server.
[0116] In this embodiment, by distributing the session persistence connection table on each load balancer in the load balancing cluster and distributing the storage of session persistence connection information, the synchronization and consistency of the session persistence information within the cluster can be guaranteed without the need to deploy a dedicated database, thereby saving database deployment resources and the communication resources occupied by the load balancer for communicating with the database each time it queries the session persistence connection information.
[0117] In an exemplary embodiment, the method further comprises:
[0118] When the second session maintaining connection information sent by the second load balancer is received, the locally stored session maintaining connection table is updated based on the second session maintaining connection information.
[0119] Exemplarily, during the operation of the first load balancer, it can receive session persistence connection information sent by other load balancers in the load balancing cluster at any time. When receiving second session persistence connection information sent by the second load balancer, it updates the locally stored session persistence connection table based on the second session persistence connection information.
[0120] In this embodiment, by receiving and storing the second session connection information, the consistency of the session connection information between the first load balancer and other load balancers in the load balancing cluster can be maintained, thereby avoiding poor experiences such as session loss and data inconsistency, and further improving service quality.
[0121] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0122] Based on the same inventive concept, the embodiment of the present application also provides a session holding device for implementing the above-mentioned session holding method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in one or more session holding device embodiments provided below can refer to the limitations on the session holding method above, and will not be repeated here.
[0123] In an exemplary embodiment, Figure 5 As shown, a session maintaining device is provided, which is applied to a first load balancer in a load balancing cluster, and the load balancing cluster also includes at least one second load balancer. The device includes: a receiving module 502, a query module 504, a generating module 506 and a sending module 508, wherein:
[0124] The receiving module 502 is used to receive the client request message distributed by the router;
[0125] A query module 504 is used to query a target server corresponding to a client request message;
[0126] A generating module 506, configured to generate first session maintaining connection information based on the client request message and the target server information of the target server, and send the first session maintaining connection information to each second load balancer;
[0127] The sending module 508 is used to send the client request message to the target server.
[0128] In an exemplary embodiment, the session maintaining device further includes a server resetting module, which is used to: after querying the target server corresponding to the client request message and before sending the client request message to the target server:
[0129] When receiving the second session maintaining connection information sent by the second load balancer, obtaining the first client information corresponding to the client request message, and extracting the second client information from the second session maintaining connection information;
[0130] When the first client information is the same as the second client information, querying a candidate server corresponding to the second session connection information;
[0131] Reselect the target server from the candidate servers and the target server according to the preset server selection rule.
[0132] In an exemplary embodiment, the server reset module is further configured to:
[0133] Obtaining first server address information of the target server and second server address information of the server to be selected;
[0134] When the first server address information and the second server address information are different, obtaining load balancing priority information;
[0135] When it is determined according to the load balancing priority information that the priority of the first load balancer is higher than the priority of the second load balancer, the target server is kept unchanged;
[0136] When it is determined according to the load balancing priority information that the priority of the second load balancer is higher than the priority of the first load balancer, the server to be selected is determined as the target server.
[0137] In an exemplary embodiment, the server reset module is further configured to:
[0138] Obtaining first load balancing address information of the first load balancer and second load balancing address information of the second load balancer;
[0139] According to the numerical values of the first load balancing address information and the second load balancing address information, the priorities of the first load balancer and the second load balancer are determined, and load balancing priority information is generated, wherein the priority of the load balancer is positively correlated or negatively correlated with the numerical value of the load balancing address information.
[0140] In an exemplary embodiment, a session persistence connection table is stored on the first load balancer; the query module 504 is further used to:
[0141] When the target server corresponding to the client request message is not found in the session maintenance connection table, the target server corresponding to the client request message is detected according to a preset load balancing strategy.
[0142] In an exemplary embodiment, the session maintaining device further includes an updating module, and the updating module is used to:
[0143] When the second session maintaining connection information sent by the second load balancer is received, the locally stored session maintaining connection table is updated based on the second session maintaining connection information.
[0144] Each module in the above session holding device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0145] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 6As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store object data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a session maintenance method is implemented.
[0146] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0147] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0148] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0149] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[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, stored data, displayed data, 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 relevant data must comply with relevant regulations.
[0151] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present 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. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0152] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, 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 only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A session maintenance method, characterized in that: The method is applied to a first load balancer in a load balancing cluster, wherein the load balancing cluster further includes at least one second load balancer; the method includes: Receive client request messages distributed by routers; Query the target server corresponding to the client request message; Generate first session hold connection information based on the client request message and the target server information of the target server, and send the first session hold connection information to each of the second load balancers; The client request message is sent to the target server.
2. The method according to claim 1, characterized in that 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: Upon receiving the second session maintaining connection information sent by the second load balancer, obtaining the first client information corresponding to the client request message, and extracting the second client information from the second session maintaining connection information; When the first client information is the same as the second client information, querying a candidate server corresponding to the second session connection information; According to a preset server selection rule, a target server is reselected from the candidate servers and the target server.
3. The method according to claim 2, characterized in that The reselecting the target server from the candidate servers and the target server according to the preset server selection rule includes: Acquire the first server address information of the target server and the second server address information of the server to be selected; When the first server address information and the second server address information are different, obtaining load balancing priority information; When it is determined according to the load balancing priority information that the priority of the first load balancer is higher than the priority of the second load balancer, keeping the target server unchanged; When it is determined, according to the load balancing priority information, that the priority of the second load balancer is higher than the priority of the first load balancer, the server to be selected is determined as the target server.
4. The method according to claim 3, characterized in that The obtaining of load balancing priority information includes: Obtaining first load balancing address information of the first load balancer and second load balancing address information of the second load balancer; According to the numerical values of the first load balancing address information and the second load balancing address information, the priorities of the first load balancer and the second load balancer are determined, and load balancing priority information is generated, wherein the priority of the load balancer is positively correlated or negatively correlated with the numerical value of the load balancing address information.
5. The method according to claim 1, characterized in that: The first load balancer stores a session persistence connection table; The querying of the target server corresponding to the client request message includes: When the target server corresponding to the client request message is not found in the session persistence connection table, the target server corresponding to the client request message is detected according to a preset load balancing strategy.
6. The method according to claim 5, characterized in that The method further comprises: When the second session maintaining connection information sent by the second load balancer is received, the locally stored session maintaining connection table is updated based on the second session maintaining connection information.
7. A session maintaining device, characterized in that: The device is applied to a first load balancer in a load balancing cluster, and the load balancing cluster also includes at least one second load balancer; the device includes: A receiving module, used for receiving client request messages distributed by the router; A query module, used to query the target server corresponding to the client request message; A generating module, configured to generate first session maintaining connection information based on the client request message and the target server information of the target server, and send the first session maintaining connection information to each of the second load balancers; A sending module is used to send the client request message to the target server.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Method, device and system for connecting and switching server
CN101714949A
Management method and device for double machine load balancing devices
CN103560907A
Session management method and device and load balancer
CN106549875A
Information synchronization method and apparatus between load equalization nodes, and processing device
CN109510770A
Method of session synchronization between plurality of load balancers and load balancers
CN111416852A