CN119520585A - Session maintenance method, device, equipment, storage medium and program product - Google Patents
Session maintenance method, device, equipment, storage medium and program product Download PDFInfo
- Publication number
- CN119520585A CN119520585A CN202411770891.9A CN202411770891A CN119520585A CN 119520585 A CN119520585 A CN 119520585A CN 202411770891 A CN202411770891 A CN 202411770891A CN 119520585 A CN119520585 A CN 119520585A
- Authority
- CN
- China
- Prior art keywords
- information
- server
- target server
- load balancing
- request message
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/141—Setup of application sessions
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/1001—Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
- H04L67/1004—Server selection for load balancing
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/142—Managing session states for stateless protocols; Signalling session states; State transitions; Keeping-state mechanisms
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer And Data Communications (AREA)
Abstract
The present application relates to a session maintaining method, apparatus, computer device, computer readable storage medium and computer program product. The method is applied to a first load balancer in a load balancing cluster, the load balancing cluster further comprises at least one second load balancer, the method comprises the steps of receiving a client request message distributed by a router, inquiring a target server corresponding to the client request message, generating first session keeping connection information based on the client request message and target server information of the target server, sending the first session keeping connection information to each second load balancer, and sending the client request message to the target server. The method can improve the service quality.
Description
Technical Field
The present application relates to the field of communications technologies, and in particular, to a session maintaining method, apparatus, computer device, computer readable storage medium, and computer program product.
Background
With the development of network technologies, more and more users of network services access a website or application at the same time, in order to improve service availability and response speed, multiple servers are generally used to share tasks of request processing, so as to share loads to improve overall performance and response speed, and ensure that even if one server fails, other servers still can continue to provide services. However, in this case, if the user's prior request is distributed to one server and the subsequent request is distributed to another server, the user session data may be out of sync, resulting in poor user experience or functional failure.
In the conventional technology, the load balancer can realize session maintenance, and when the TCP protocol is used, the load balancer can carry out session maintenance based on the source IP address of the client, and a plurality of requests of the same client IP are distributed to the same server of the back end for processing.
However, with the increasing user base of internet applications, a single load balancer may have difficulty in bearing huge traffic pressure, and once this device fails, the service of the whole system will be affected, even completely interrupted, but if multiple load balancers are deployed in the system, different load balancers may still distribute requests with association relations to different backend servers, so that users encounter poor experiences such as session loss, inconsistent data and the like in the use process, and therefore, the service quality is poor whether the single load balancer or multiple load balancers.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a session maintaining method, apparatus, computer device, computer-readable storage medium, and computer program product that are capable of improving quality of service.
In a first aspect, the present application provides a session maintaining method, where the method is applied to a first load balancer in a load balancing cluster, and the load balancing cluster further includes at least one second load balancer, where the method includes:
Receiving a client request message distributed by a router;
inquiring a target server corresponding to the client request message;
generating first session maintaining connection information based on the client request message and target server information of the target server, and sending the first session maintaining connection information to each second load balancer;
and sending the client request message to the target server.
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:
Under the condition that second session maintaining connection information sent by a second load balancer is received, acquiring first client information corresponding to a client request message, and extracting second client information from the second session maintaining connection information;
under the condition that the first client information is the same as the second client information, inquiring a server to be selected corresponding to the second session maintaining connection information;
and re-selecting the target server from the server to be selected and the target server according to a preset server selection rule.
In one embodiment, according to a preset server selection rule, re-selecting the target server from the to-be-selected server and the target server includes:
Acquiring first server address information of a target server and second server address information of a server to be selected;
under the condition that the first server address information and the second server address information are different, acquiring load balancing priority information;
Under the condition 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, keeping the target server unchanged;
and determining the server to be selected as a target server under the condition that the priority of the second load balancer is higher than that of the first load balancer according to the load balancing priority information.
In one embodiment, obtaining load balancing priority information includes:
acquiring first load balancing address information of a first load balancer and second load balancing address information of a second load balancer;
And determining the priorities 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 priorities of the load balancers are positively or negatively related to the numerical values of the load balancing address information.
In one embodiment, the first load balancer stores a session maintaining connection table, and the querying the target server corresponding to the client request message includes:
And under the condition that the target server corresponding to the client request message is not queried in the session maintaining connection table, detecting the target server corresponding to the client request message according to a preset load balancing strategy.
In one embodiment, the method further comprises:
and updating a locally stored session maintaining connection table based on the second session maintaining connection information when the second session maintaining connection information sent by the second load balancer is received.
In a second aspect, the present application also provides a session maintaining device, where the session maintaining device is applied to a first load balancer in a load balancing cluster, and the load balancing cluster further includes at least one second load balancer, and the device includes:
the receiving module is used for receiving a client request message distributed by the router;
The query module is used for querying a target server corresponding to the client request message;
The generating module is used for generating first session maintaining connection information based on the client request message and target server information of the target server, and sending the first session maintaining connection information to each second load balancer;
And the sending module is used for sending the client request message to the target server.
In a third aspect, the present application also provides a computer device comprising a memory and a processor, the memory storing a computer program, the processor implementing the following steps when executing the computer program:
Receiving a client request message distributed by a router;
inquiring a target server corresponding to the client request message;
generating first session maintaining connection information based on the client request message and target server information of the target server, and sending the first session maintaining connection information to each second load balancer;
and sending the client request message to the target server.
In a fourth aspect, the present application also provides a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of:
Receiving a client request message distributed by a router;
inquiring a target server corresponding to the client request message;
generating first session maintaining connection information based on the client request message and target server information of the target server, and sending the first session maintaining connection information to each second load balancer;
and sending the client request message to the target server.
In a fifth aspect, the application also provides a computer program product comprising a computer program which, when executed by a processor, performs the steps of:
Receiving a client request message distributed by a router;
inquiring a target server corresponding to the client request message;
generating first session maintaining connection information based on the client request message and target server information of the target server, and sending the first session maintaining connection information to each second load balancer;
and sending the client request message to the target server.
According to the session maintaining method, the session maintaining device, the computer equipment, the computer readable storage medium and the computer program product, on one hand, by deploying the load balancing cluster and dispersing the load balancing tasks to a plurality of load balancers, the overall processing capacity and the response speed of the system can be remarkably improved, and even if one or more of the load balancers fail, other members can still continue to work, so that the continuous availability of the service is ensured, and the service quality is improved. On the other hand, the target server corresponding to the client request message is queried through receiving the client request message distributed by the router, the first session maintaining connection information is generated based on the client request message and the target server information of the target server, the first session maintaining connection information is sent to each second load balancer, the client request message is sent to the target server, after any load balancer in the load balancing cluster receives the client request message and determines the target server, the corresponding session maintaining connection information is generated, and the session maintaining connection information is synchronized with other load balancers in the load balancing cluster, so that the session maintaining connection information is kept consistent on each load balancer in the load balancing cluster, and even if the requests of the same user are distributed to different load balancers in the load balancing cluster, the different load balancers distribute the received requests according to the same session maintaining connection information, the requests of the same user can be distributed to the same server, and accordingly bad experiences such as session loss, data inconsistency and the like are avoided, and the service quality is further improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the related art, the drawings that are needed in the description of the embodiments of the present application or the related technologies will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and other related drawings may be obtained according to these drawings without inventive effort to those of ordinary skill in the art.
FIG. 1 is an application environment diagram of a session maintaining method in the related art;
FIG. 2 is an application environment diagram of a session maintenance method in one embodiment;
FIG. 3 is a flow diagram of a session maintenance method in one embodiment;
FIG. 4 is a flow chart of a session maintaining method according to another embodiment;
FIG. 5 is a block diagram of a session maintaining apparatus in one embodiment;
Fig. 6 is an internal structural diagram of a computer device in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
With the development of network technologies, more and more users of network services access a website or application at the same time, in order to improve service availability and response speed, multiple servers are generally used to share tasks of request processing, so as to share loads to improve overall performance and response speed, and ensure that even if one server fails, other servers still can continue to provide services. However, in this case, if the user's prior request is distributed to one server and the subsequent request is distributed to another server, the user session data may be out of sync, resulting in poor user experience or functional failure. In the conventional technology, the load balancer can realize session maintenance, and when the TCP protocol is used, the load balancer can carry out session maintenance based on the source IP address of the client, and a plurality of requests of the same client IP are distributed to the same server of the back end for processing.
For example, the load balancer corresponds to two back-end servers a and B, the client C sends a login request, the load balancer distributes the login request to the server a, and the login is completed, when the client C has a request, if there is no session maintenance function, the load balancer may distribute the request to the server B, but there is no login information of the user on the server B, and the login verification needs to be performed again, if there is a session maintenance function, the load balancer distributes the request with the association relationship to the same back-end server, that is, the request received later is sent to the server a, and the re-login is not needed.
However, as the user base of internet applications continues to grow, a single load balancer may be difficult to withstand the tremendous traffic pressures, and once this device fails, the overall system service will be impacted, even completely interrupted. However, if multiple load balancers are deployed in the system, different load balancers may still distribute the requests with association relationship to different backend servers, which results in poor experiences such as session loss and inconsistent data encountered by the user during the use process.
For example, as shown in fig. 1, assuming that the load balancing cluster 106 includes a load balancing device a, a load balancing device B and a load balancing device C, an equivalent route to the load balancing device a, the load balancing device B and the load balancing device C is set on the router 104, when the client 102 initiates a request to access the load balancing cluster 106, the router 104 may obtain a five-tuple of the request, that is, a source IP (Internet Protocol ) address, a destination IP address, a source port number, a destination port number and a protocol type, perform a hash operation on the five-tuple, and uniformly distribute the request to each load balancing device in the load balancing cluster 106 according to a hash operation result, and further, the load balancing device distributes the received request to a server a108 or a server B110 at a back end according to a configured distribution policy, for example, a poll, a minimum connection number, and the like. In this case, even though each load balancer is configured with session maintenance, assuming that the same client 102 sends out request 1, request 2 and request 3, request 1 arrives at load balancer a, server a108 is selected by the distribution policy, and the subsequent requests arriving at load balancer a by that client 102 are forwarded to server a108 during the session maintenance time, requests 2 and 3 arrive at load balancer C, server B110 is selected by the distribution policy, and the subsequent requests arriving at load balancer C by that client 102 are forwarded to server B110 during the session maintenance time, so that the requests of the same client 102 are still distributed to different server a108 and server B110, the session maintenance function within each load balancer is valid, but the user still encounters bad experiences of lost session, inconsistent data, etc.
Therefore, the quality of service is poor, whether it is a single load balancer or a plurality of load balancers.
In this case, in the related art, the router may perform hash operation according to the triples, that is, the source IP address, the destination IP address, and the protocol type, and for the traffic of the same client of the same source IP address, the traffic is distributed to the same load balancer after the hash operation, so that the session maintaining function is implemented on the same load balancer, and the request of the same source address is always distributed to the same application server. However, this method has a problem of uneven traffic distribution, and 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.
The session maintaining method provided by the embodiment of the application can be applied to an application environment shown in fig. 2. Wherein terminal 202 may communicate with server 204 via router 206 and a load balancing cluster. The data storage system may store data that server 204 needs to process. The data storage system may be integrated on the server 204 or may be located on a cloud or other network server. A client of the service may be deployed on terminal 202. Requests sent by the terminal 202 are first distributed uniformly to the load balancers in the load balancing cluster 208 through the router 206, and each load balancer distributes the received requests to the plurality of servers 204 for processing by adopting a plurality of distribution strategies. The terminal 202 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, internet of things devices and portable wearable devices, and the internet of things devices may be smart speakers, smart televisions, smart air conditioners, smart vehicle devices, projection devices, etc. The portable wearable device may be a smart watch, smart bracelet, headset, or the like. The head-mounted device may be a Virtual Reality (VR) device, an augmented Reality (Augmented Reality, AR) device, smart glasses, or the like. The server 204 may be a server cluster or a distributed system formed by a plurality of physical servers, or may be a cloud server providing cloud computing services.
In an exemplary embodiment, as shown in fig. 3, a session maintaining method is provided, which is taken as an example of applying the method to a first load balancer in the load balancing cluster in fig. 1, and it is to be understood that the first load balancer may refer to any load balancer in the load balancing cluster that receives a client request message, and the load balancing cluster further includes other load balancers besides the first load balancer, and for convenience of explanation, the other load balancers in the load balancing cluster except the first load balancer are determined as a second load balancer, where the second load balancer may receive or not receive the client request message. The method includes the following steps S10 to S40. Wherein:
step S10, receiving a client request message distributed by a router.
The client request message may refer to a data packet sent by the client to the server, and is used for requesting a service or a resource. The client request message may include client information, information about a requested service or resource, and the like.
A load balancing cluster may refer to a set of cooperating load balancers that together take on the task of distributing client request messages to backend servers, i.e. the load balancing cluster is made up of a plurality of load balancers. A load balancer may refer to a device for distributing received client request messages to multiple back-ends to achieve reasonable allocation and optimization of resources. As an example, the load balancer may receive a client request message, and further select an appropriate backend server according to a preset load balancing algorithm, such as polling, least number of connections, hash algorithm, etc., and may also return a response of the backend server to the client, and in some possible embodiments, the load balancer may further detect whether the backend server has a failure, and remove the backend server that has a failure from the load balancing pool.
A router may refer to a network device for forwarding data packets between networks, the router operating at the network layer and having the primary role of forwarding data packets from one network to another according to IP addresses, the router determining the best path for the data packets through a routing table, ensuring that the data can reach the destination efficiently and accurately. In some possible implementations, in the case of multiple equal cost paths (ECMP), the data packets may be distributed to multiple paths, enabling load balancing and redundancy.
The router may learn, in advance, an equivalent route of each load balancer in the load balancing cluster through BGP (Border Gateway Protocol ), so that, after a client initiates a request, the router may extract quintuple information, that is, a source IP (Internet Protocol ) address, a destination IP address, a source port number, a destination port number, and a protocol type, from a client request packet in an ECMP manner, hash the quintuple information extracted from the client request packet, and uniformly distribute, according to a hash result, the client request packet to each load balancer in the load balancing cluster, where the first load balancer may refer to a load balancer capable of receiving a client request packet distributed by the router in the load balancing cluster, that is, after the router distributes the client request packet, the first load balancer may be capable of receiving the client request packet distributed by the router.
Step S20, inquiring a target server corresponding to the client request message.
Illustratively, 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.
In some possible embodiments, after receiving the client request message, whether to enable the session maintaining function can be judged according to the configuration information of the first load balancer and the first client information carried in the client request message, in the case of determining to enable the session maintaining function, the load balancing policy can include extracting the first client information from the client request message, where the first client information can refer to information for identifying a client sending the client request message, including at least one of a client address, a client identification number and the like, further, firstly, inquiring whether the session maintaining connection information corresponding to the first client information exists in a local session maintaining connection table, and in the case that the session maintaining connection information corresponding to the first client information cannot be inquired in the local session maintaining connection table, selecting a corresponding target server for the client request message according to a preset load balancing algorithm, for example, at least one of a polling algorithm, a minimum connection algorithm, a source IP algorithm and the like, inquiring the current session maintaining connection information corresponding to the first client information in the local session maintaining connection table, and determining that the current session maintaining connection information is still in the first session maintaining connection time is the specified as the target server.
Step S30, based on the client request message and the target server information of the target server, generating first session maintaining connection information, and sending the first session maintaining connection information to each second load balancer.
The target server information may refer to information capable of identifying the target server, and includes at least one of an address, an identification number, and the like of the target server. Session hold connection information may refer to information for ensuring that multiple requests of the same client are distributed to the same backend server for a period of time, at least including client identification information of the client that is the request initiator, and server identification information of the server that is the request receiver, session connection time, etc., so that a load balancer or other intermediate device can recognize and maintain consistency of the session. The first session keep-alive information may refer to session keep-alive information selected and generated by the server by the first load balancer. 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 maintenance connection information may 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, stickytime refers to the session maintenance time, the first session maintenance connection information may characterize the request from a-clientip, and the IP address a-IP distributed to server a during the session maintenance time.
As an example, in the case that the target server is determined through selection of a preset load balancing algorithm, the first session keeping connection information may be generated based on the first client information in the client request packet and the target server information of the target server, and the first session keeping connection information is sent to each second load balancing device, so as to realize information synchronization of the first session keeping connection information on each load balancing device in the load balancing cluster. In this way, in the session maintaining time, the client corresponding to the client request message sends the request again, and the request is distributed to the same server after being distributed by any load balancer in the load balancing cluster.
In some possible implementations, the first session maintenance connection information may also be written into a local session maintenance connection table.
As another example, in the case that the target server is determined based on local session maintenance connection table selection, the client request message may be directly sent to the target server, so that the session maintenance connection information does not need to be generated and synchronized again, so as to save communication resources, shorten request processing time, and improve request processing efficiency. In some possible embodiments, the locally recorded session hold start time information may be updated to recalculate the session hold time, and a session hold time reset instruction may be sent to each second load balancer to uniformly reset the session hold times of the load balancing clusters.
Step S40, the client request message is sent to the target server.
For example, the client request message may be sent to the target server after maintaining the connection information with the load-balancing cluster synchronization session.
In some possible embodiments, the client request message may be further sent to the target server after a preset synchronization waiting time, or after receiving a synchronized response of the information returned by each second load balancer based on the first session maintaining connection information. In order to avoid that other load balancers make different load balancing decisions for the same client in the process of information synchronization, thereby causing poor experiences such as session loss, inconsistent data and the like.
In the session maintaining method, on one hand, load balancing tasks are distributed to a plurality of load balancers through deploying the load balancing clusters, so that the overall processing capacity and response speed of the system can be remarkably improved, and even if one or more of the load balancers fail, other members can still continue to work, the continuous availability of service is ensured, and the service quality is improved. On the other hand, the target server corresponding to the client request message is queried through receiving the client request message distributed by the router, the first session maintaining connection information is generated based on the client request message and the target server information of the target server, the first session maintaining connection information is sent to each second load balancer, the client request message is sent to the target server, after any load balancer in the load balancing cluster receives the client request message and determines the target server, the corresponding session maintaining connection information is generated, and the session maintaining connection information is synchronized with other load balancers in the load balancing cluster, so that the session maintaining connection information is kept consistent on each load balancer in the load balancing cluster, and even if the requests of the same user are distributed to different load balancers in the load balancing cluster, the different load balancers distribute the received requests according to the same session maintaining connection information, the requests of the same user can be distributed to the same server, and accordingly bad experiences such as session loss, data inconsistency and the like are avoided, and the service quality is further improved.
In an exemplary embodiment, as shown in fig. 4, 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:
Step S100, under the condition that the second session maintaining connection information sent by the second load balancer is received, obtaining first client information corresponding to the client request message, and extracting the second client information from the second session maintaining connection information.
If the subsequent request of the same client generates and synchronizes the session maintaining connection information, and then sends the subsequent request to the load balancing cluster in the session maintaining time, 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 time between the multiple requests of the same client is shorter, and the multiple requests are routed to different load balancers by the router, before the session maintaining connection information is not yet synchronized, the different load balancers cannot query the corresponding session maintaining connection information from the local session maintaining connection table, so that the corresponding target servers can be selected for the respectively received client request messages based on the preset load balancing algorithm, and the situation that the different load balancers select different target servers for the multiple client request messages generated by the same client may occur, so that the user encounters bad experiences such as session loss, inconsistent data and the like in the use process.
The second session keeping connection information may refer to session keeping connection information selected and generated by any second load balancer by a server. The second session keeping connection information may be the same as or different from the first session keeping 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 messages sent by the same client.
The method includes that after a first load balancer queries a target server corresponding to a client request message, but before the first load balancer sends the client request message to the target server, if second session maintaining connection information sent by any second load balancer is received, the first client information corresponding to the client request message can be extracted from communication information corresponding to the client request message or information carried in the client request message, wherein the first client information is used for identifying a client sending the client request message, and the second client information is extracted from the second session maintaining connection information, and the second client information refers to information of a client needing to be subjected to session maintaining, which is determined by the second load balancer.
Step S200, under the condition that the first client information is the same as the second client information, querying a server to be selected corresponding to the second session maintaining connection information.
The server to be selected may refer to a server selected by the second load balancer that generates the second session maintaining connection information for the request packet received by the server.
The method includes the steps of obtaining first client information and second client information, comparing whether the first client information and the second client information are the same or not after the first client information and the second client information are obtained, if the first client information and the second client information are different, indicating that the first client information and the second client information are load balancing decisions made for different clients, the first client information and the second client information are not interfered with each other, writing second session maintaining connection information into a local session maintaining connection table without re-determining a target server, and if the first client information and the second client information are the same, indicating that the second client information and the second client information are load balancing decisions made for the same client, so that decisions are required to be unified, further extracting server information from the second session maintaining connection information, and determining a to-be-selected server corresponding to the second session maintaining connection information according to the server information extracted from the second session maintaining connection information.
Step S300, re-selecting the target server from the to-be-selected server and the target server according to the preset server selection rule.
The preset server selection rule may refer to a rule for making uniform selection for different servers selected by different load balancers. As an example, the preset server selection rule may be a rule selected based on a fixed parameter of the load balancer, where the fixed parameter may refer to a parameter that does not change during the process of requesting the message transmission by the client, for example, an address, an identification number, etc. of the load balancer, which may be specifically determined according to the actual situation, and this embodiment is not limited thereto.
For example, after determining the candidate server, one may be reselected from the candidate server and the target server as the target server according to a preset server selection rule.
In this embodiment, before the client request message is distributed, a server reselection mechanism is triggered under the condition that connection information of sessions sent by other load balancers is received, one server selected from different load balancers for the client is selected as a target server, and uniform selection is made for different load balancers through preset server selection rules, so that bad experiences of session loss, inconsistent data and the like are avoided, and service quality is further improved.
In an exemplary embodiment, the target server is re-selected from the candidate server and the target server according to a preset server selection rule, including steps S310 to S340. Wherein:
Step S310, obtaining the first server address information of the target server and the second server address information of the server to be selected.
Illustratively, after determining the server to be selected, first server address information of the target server and second server address information of the server to be selected are acquired. The first server address information may refer to a server IP address of the target server, and the second server address information may refer to a server IP address of the server to be selected.
In step S320, in the case where the first server address information and the second server address information are different, the load balancing priority information is acquired.
The load balancing priority information is used for representing the priority level relation between the first load balancing device and each second load balancing device. The priority relationships between the first load balancer and the second load balancers can be determined in advance according to inherent parameters of the load balancers, current practical situations or performance test results, etc., but the embodiment does not limit the priority relationships, but the load balancing priority information remains unchanged in the process of load balancing cluster operation, so that the same results can be obtained when different load balancers respectively perform server unification based on the load balancing priority information. For example, it is assumed that the priority of the load balancer a is higher than that of the 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, so that in the case that the load balancer a selects the server a for the client a and the load balancer B selects the server B for the client a, the server a is determined as the target server based on the preset server selection rule, regardless of the load balancer a or the load balancer B.
The method includes the steps of obtaining first server address information and second server address information, comparing whether the first server address information and the second server address information are consistent, if so, indicating that servers selected by different load balancers for different client request messages sent by the same client are identical, and if not, indicating that servers selected by different load balancers for different client request messages sent by the same client are different, wherein server unification is needed, and obtaining load balancing priority information.
In step S330, the target server is kept unchanged 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.
Illustratively, in the case where the priority of the first load balancer is determined to be higher than the priority of the second load balancer based on the load balancing priority information, the decision of the first load balancer is obeyed, and thus the target server is kept unchanged without changing the target server.
In step S340, in the case where it is determined that the priority of the second load balancer is higher than the priority of the first load balancer according to the load balancing priority information, the server to be selected is determined as the target server.
In an exemplary case where it is determined that the priority of the second load balancer is higher than the priority of the first load balancer based on the load balancing priority information, the decision of the second load balancer is obeyed, and thus the selected server selected by the second load balancer is determined as the target server.
In some possible implementations, the first session maintenance connection information may be updated after the target server changes, and the local session maintenance connection table may be updated in the event that the first session maintenance connection information has been written into the local session maintenance connection table.
In this embodiment, through the preset load balancing priority, when different load balancers independently select the target servers, the same target server can be determined, so that unification of the target servers corresponding to the same client is realized, bad experiences such as session loss and inconsistent data are avoided, and the service quality is further improved.
In an exemplary embodiment, load balancing priority information is acquired, including steps S321 to S323. Wherein:
step S321, acquiring first load balancing address information of the first load balancer and second load balancing address information of the second load balancer.
The first load balancing address information may refer to an IP address of the first load balancing device. The second load balancing address information may refer to an IP address of the second load balancing device. The first load balancing address information is an inherent parameter of the first load balancing device, the first load balancing device can directly acquire the information, and the second load balancing address information carries information in communication information when the first load balancing device receives the second session maintaining connection information. Therefore, the method and the device can be obtained without executing additional operation, and the intrinsic parameters of the load balancer are not changed in the session maintaining process, and the priority of the load balancer is determined based on the load balancing address information, so that the consistency of server selection can be ensured, the operation can be simplified, and the resources are saved.
For example, the first load balancing address information may be extracted from the attribute information of the first load balancing device, and the second load balancing address information may be extracted from the communication information of the second session maintaining connection information.
Step S322, determining the priority of the first load balancer and the second load balancer according to the numerical values of the first load balancer and the second load balancer, and generating load balancing priority information, wherein the priority of the load balancer is positively or negatively related to the numerical value of the load balancing address information.
The first value size of the first load balancing address information and the second value size of the second load balancing address information may 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 may be converted into binary values, so as to compare the magnitude relation of the converted binary values, further, the first value size and the second value size may be compared, a higher priority may be set for a load balancer corresponding to load balancing address information with a larger value size, a higher priority may also be set for a load balancer corresponding to load balancing address information with a smaller value size, and may be specifically determined according to an actual situation, and after determining the priority of each load balancer, the corresponding load balancing priority information may be generated according to a priority ranking result.
In this embodiment, the priority of the load balancer is determined based on the address information of the load balancer, so that the consistency of server selection can be ensured, the operation can be simplified, and resources can be saved.
In an exemplary embodiment, the first load balancer stores a session maintaining connection table, and the querying the target server corresponding to the client request message includes:
And under the condition that the target server corresponding to the client request message is not queried in the session maintaining connection table, detecting the target server corresponding to the client request message according to a preset load balancing strategy.
The session maintaining connection table may refer to a data table for storing session maintaining connection information.
The method includes the steps of firstly inquiring whether session keeping connection information corresponding to first client information exists in a local session keeping connection table, selecting a corresponding target server for a client request message according to at least one of a preset load balancing algorithm, such as a polling algorithm, a minimum connection algorithm and a source IP algorithm when the session keeping connection information corresponding to the first client information cannot be inquired in the local session keeping connection table, and determining a server designated in the session keeping connection information corresponding to the first client information as the target server when the session keeping connection information corresponding to the first client information is inquired in the local session keeping connection table and is still in a session keeping time currently.
In this embodiment, by setting the session maintaining connection table in a distributed manner on each load balancer of the load balancing cluster, and storing the session maintaining connection information in a distributed manner, the synchronicity and consistency of the session maintaining information in the cluster can be ensured, and no special database needs to be deployed additionally, so that the deployment resources of the database are saved, and the communication resources occupied by the load balancer for communicating with the database when inquiring the session maintaining connection information each time.
In an exemplary embodiment, the method further comprises:
and updating a locally stored session maintaining connection table based on the second session maintaining connection information when the second session maintaining connection information sent by the second load balancer is received.
In an exemplary manner, during the operation of the first load balancer, session maintaining connection information sent by other load balancers in the load balancing cluster may be received at any time, and when 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.
In this embodiment, by receiving and storing the second session maintaining connection information, consistency of session maintaining connection information between the first load balancer and other load balancers in the load balancing cluster can be maintained, so as to avoid bad experiences such as session loss, inconsistent data, and the like, and further improve service quality.
It should be understood that, although the steps in the flowcharts related to the above embodiments are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
Based on the same inventive concept, the embodiment of the application also provides a session holding device for realizing the session holding method. The implementation of the solution provided by the device is similar to the implementation described in the above method, so the specific limitation in the embodiments of one or more session holding devices provided below may be referred to the limitation of the session holding method hereinabove, and will not be repeated here.
In an exemplary embodiment, as shown in fig. 5, a session maintaining apparatus is provided, where the apparatus is applied to a first load balancer in a load balancing cluster, and the load balancing cluster further includes at least one second load balancer, and the apparatus includes a receiving module 502, a querying module 504, a generating module 506, and a sending module 508, where:
A receiving module 502, configured to receive a client request packet distributed by a router;
The query module 504 is configured to query a target server corresponding to the client request packet;
A generating module 506, configured to generate first session keeping connection information based on the client request message and target server information of the target server, and send the first session keeping connection information to each second load balancer;
And the sending module 508 is configured to send the client request packet to the target server.
In an exemplary embodiment, the session keeping apparatus further includes a server resetting module, after querying the target server corresponding to the client request message and before sending the client request message to the target server, the server resetting module is configured to:
Under the condition that second session maintaining connection information sent by a second load balancer is received, acquiring first client information corresponding to a client request message, and extracting second client information from the second session maintaining connection information;
under the condition that the first client information is the same as the second client information, inquiring a server to be selected corresponding to the second session maintaining connection information;
and re-selecting the target server from the server to be selected and the target server according to a preset server selection rule.
In an exemplary embodiment, the server reset module is further configured to:
Acquiring first server address information of a target server and second server address information of a server to be selected;
under the condition that the first server address information and the second server address information are different, acquiring load balancing priority information;
Under the condition 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, keeping the target server unchanged;
and determining the server to be selected as a target server under the condition that the priority of the second load balancer is higher than that of the first load balancer according to the load balancing priority information.
In an exemplary embodiment, the server reset module is further configured to:
acquiring first load balancing address information of a first load balancer and second load balancing address information of a second load balancer;
And determining the priorities 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 priorities of the load balancers are positively or negatively related to the numerical values of the load balancing address information.
In one exemplary embodiment, the first load balancer has a session hold connection table stored thereon, and the query module 504 is further configured to:
And under the condition that the target server corresponding to the client request message is not queried in the session maintaining connection table, detecting the target server corresponding to the client request message according to a preset load balancing strategy.
In an exemplary embodiment, the session holding apparatus further includes an update module for:
and updating a locally stored session maintaining connection table based on the second session maintaining connection information when the second session maintaining connection information sent by the second load balancer is received.
The respective modules in the session holding apparatus described above may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one exemplary embodiment, a computer device is provided, which may be a server, the internal structure of which may be as shown in fig. 6. The computer device includes a processor, a memory, an Input/Output interface (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. Wherein the processor of the computer device is configured 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, 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 is for storing object data. The input/output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a session maintenance method.
It will be appreciated by those skilled in the art that the structure shown in FIG. 6 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be applied, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In an embodiment, there is also provided a computer device comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the steps of the method embodiments described above when the computer program is executed.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when executed by a processor, carries out the steps of the method embodiments described above.
In an embodiment, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the steps of the method embodiments described above.
It should be noted that, the user information (including but not limited to user equipment information, user personal information, etc.) and the data (including but not limited to data for analysis, stored data, presented data, etc.) related to the present application are both information and data authorized by the user or sufficiently authorized by each party, and the collection, use and processing of the related data are required to meet the related regulations.
Those skilled in the art will appreciate that implementing all or part of the above-described methods may be accomplished by way of a computer program, which may be stored on a non-transitory computer readable storage medium, that when executed may comprise the steps of the embodiments of the methods described above. Any reference to memory, database, or other medium used in embodiments provided herein may include at least one of non-volatile memory and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high density embedded nonvolatile Memory, resistive random access Memory (RESISTIVE RANDOM ACCESS MEMORY, reRAM), magneto-resistive Memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric Memory (Ferroelectric Random Access Memory, FRAM), phase change Memory (PHASE CHANGE Memory, PCM), graphene Memory, and the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, and the like. By way of illustration, and not limitation, RAM can be in various forms such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The databases referred to in the embodiments provided herein may include at least one of a relational database and a non-relational database. The non-relational database may include, but is not limited to, a blockchain-based distributed database, and the like. The processor referred to in the embodiments provided in the present application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computation, an artificial intelligence (ARTIFICIAL INTELLIGENCE, AI) processor, or the like, but is not limited thereto.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the present application.
The foregoing examples illustrate only a few embodiments of the application, which are described in detail and are not to be construed as limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of the application should be assessed as that of the appended claims.
Claims (10)
1. A session maintenance method, wherein the method is applied to a first load balancer in a load balancing cluster, the load balancing cluster further comprising at least one second load balancer, the method comprising:
Receiving a client request message distributed by a router;
inquiring a target server corresponding to the client request message;
generating first session maintaining connection information based on the client request message and target server information of the target server, and sending the first session maintaining connection information to each second load balancer;
and sending the client request message to the target server.
2. The method of claim 1, further comprising, after querying a target server to which the client request message corresponds and before the sending the client request message to the target server:
under the condition that second session maintaining connection information sent by the second load balancer is received, acquiring first client information corresponding to the client request message, and extracting second client information from the second session maintaining connection information;
Querying a server to be selected corresponding to the second session maintaining connection information under the condition that the first client information is the same as the second client information;
and re-selecting the target server from the server to be selected and the target server according to a preset server selection rule.
3. The method according to claim 2, wherein the re-selecting the target server from the servers to be selected and the target server according to a preset server selection rule includes:
Acquiring first server address information of the target server and second server address information of the server to be selected;
Acquiring load balancing priority information under the condition that the first server address information and the second server address information are different;
Under the condition 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, keeping the target server unchanged;
And determining the server to be selected as a target server under the condition that the priority of the second load balancer is higher than that of the first load balancer according to the load balancing priority information.
4. The method of claim 3, wherein the obtaining load balancing priority information comprises:
Acquiring first load balancing address information of the first load balancing device and second load balancing address information of the second load balancing device;
and determining the priorities 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 priorities of the load balancers are positively or negatively related to the numerical values of the load balancing address information.
5. The method of claim 1, wherein the first load balancer stores a session maintaining connection table, and the querying the target server corresponding to the client request message comprises:
And under the condition that the target server corresponding to the client request message is not queried from the session maintaining connection table, detecting the target server corresponding to the client request message according to a preset load balancing strategy.
6. The method of claim 5, wherein the method further comprises:
and under the condition that second session maintaining connection information sent by the second load balancer is received, updating the locally stored session maintaining connection table based on the second session maintaining connection information.
7. A session maintenance device, wherein the device is applied to a first load balancer in a load balancing cluster, the load balancing cluster further comprises at least one second load balancer, and the device comprises:
the receiving module is used for receiving a client request message distributed by the router;
The query module is used for querying a target server corresponding to the client request message;
the generating module is used for generating first session maintaining connection information based on the client request message and target server information of the target server, and sending the first session maintaining connection information to each second load balancer;
and the sending module is used for sending the client request message to the target server.
8. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 6 when the computer program is executed.
9. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
10. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 6.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202411770891.9A CN119520585A (en) | 2024-12-04 | 2024-12-04 | Session maintenance method, device, equipment, storage medium and program product |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202411770891.9A CN119520585A (en) | 2024-12-04 | 2024-12-04 | Session maintenance method, device, equipment, storage medium and program product |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN119520585A true CN119520585A (en) | 2025-02-25 |
Family
ID=94667245
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202411770891.9A Pending CN119520585A (en) | 2024-12-04 | 2024-12-04 | Session maintenance method, device, equipment, storage medium and program product |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN119520585A (en) |
Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103560907A (en) * | 2013-10-23 | 2014-02-05 | 曙光信息产业(北京)有限公司 | Management method and device for double machine load balancing devices |
| CN106549875A (en) * | 2015-09-18 | 2017-03-29 | 中国移动通信集团浙江有限公司 | A kind of conversation managing method, device and load equalizer |
| US20170134424A1 (en) * | 2013-11-14 | 2017-05-11 | Avi Networks | Network devices using tls tickets for session persistence |
| CN109510770A (en) * | 2018-12-07 | 2019-03-22 | 北京金山云网络技术有限公司 | Information synchronization method, device and processing equipment between load balancing node |
| CN111416852A (en) * | 2020-03-16 | 2020-07-14 | 优刻得科技股份有限公司 | Method for session synchronization among multiple load balancers and load balancer |
| CN116582544A (en) * | 2023-05-26 | 2023-08-11 | 国网江苏省电力有限公司信息通信分公司 | A data packet sending method, device, equipment and storage medium |
-
2024
- 2024-12-04 CN CN202411770891.9A patent/CN119520585A/en active Pending
Patent Citations (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103560907A (en) * | 2013-10-23 | 2014-02-05 | 曙光信息产业(北京)有限公司 | Management method and device for double machine load balancing devices |
| US20170134424A1 (en) * | 2013-11-14 | 2017-05-11 | Avi Networks | Network devices using tls tickets for session persistence |
| CN106549875A (en) * | 2015-09-18 | 2017-03-29 | 中国移动通信集团浙江有限公司 | A kind of conversation managing method, device and load equalizer |
| CN109510770A (en) * | 2018-12-07 | 2019-03-22 | 北京金山云网络技术有限公司 | Information synchronization method, device and processing equipment between load balancing node |
| CN111416852A (en) * | 2020-03-16 | 2020-07-14 | 优刻得科技股份有限公司 | Method for session synchronization among multiple load balancers and load balancer |
| CN116582544A (en) * | 2023-05-26 | 2023-08-11 | 国网江苏省电力有限公司信息通信分公司 | A data packet sending method, device, equipment and storage medium |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| EP3353952B1 (en) | Managing groups of servers | |
| EP2901308B1 (en) | Load distribution in data networks | |
| CN113014611B (en) | Load balancing method and related equipment | |
| EP3596600B1 (en) | Systems and methods for compute node management protocols | |
| WO2019210580A1 (en) | Access request processing method, apparatus, computer device, and storage medium | |
| WO2011137189A1 (en) | System and methods for mapping and searching objects in multidimensional space | |
| US11159625B1 (en) | Efficiently distributing connections to service instances that stream multi-tenant data | |
| CN111352716B (en) | Task request method, device and system based on big data and storage medium | |
| US9667499B2 (en) | Sparsification of pairwise cost information | |
| CN117176796A (en) | Message pushing method, device, computer equipment and storage medium | |
| JP7678892B2 (en) | Geographically Distributed Hybrid Cloud Clusters | |
| CN114157721A (en) | Route distribution method, device, equipment and readable storage medium | |
| CN119520585A (en) | Session maintenance method, device, equipment, storage medium and program product | |
| CN119996366A (en) | A method, device, equipment and storage medium for dynamic elastic expansion of stateful services | |
| CN108124021A (en) | Internet protocol IP address obtains, the method, apparatus and system of website visiting | |
| CN117376358B (en) | Access request processing method and device and computer equipment | |
| CN119766832B (en) | Service request processing method and device, electronic equipment and medium | |
| CN119788538A (en) | Traffic identification method, device and computer equipment | |
| CN112073358B (en) | Protocol conversion processing method and device based on Kubernetes | |
| CN112073449B (en) | Kubernetes-based environment switching processing method and equipment | |
| CN117857315A (en) | Node switching method, device, computer equipment, storage medium and product | |
| CN119788656A (en) | Data transmission method, device, equipment, system, medium and program product | |
| CN120711012A (en) | Cluster management method, device, computer equipment and storage medium | |
| CN120238579A (en) | A model service method, system and storage medium | |
| CN119788537A (en) | Flow identification method, device and computer equipment |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |