Disclosure of Invention
In order to solve the problems in the prior art, embodiments of the present invention provide a method for synchronizing connection information and a load balancing system. The technical scheme is as follows:
in a first aspect, a method for synchronizing connection information is provided, where the method is applied to a DPVS load balancing system based on a user mode protocol stack, where the load balancing system includes a main load balancer and a standby load balancer corresponding to the main load balancer, and the main/standby load balancer uses a user mode network protocol stack, and the method includes:
when the information synchronization condition of the target connection is met, the target service core of the main load balancer stores the target connection information of the target connection in a global cache of the main load balancer;
the management core of the main load balancer acquires the target connection information from the global cache and sends the target connection information to a target standby load balancer corresponding to the main load balancer;
the management core of the target standby load balancer acquires the target connection information and stores the target connection information in a target cache corresponding to a target service core of the target standby load balancer;
and the target service core of the target standby load balancer acquires the target connection information from the target cache and stores the target connection information in a connection tracking table of the target service core of the target standby load balancer.
Optionally, when an information synchronization condition of a target connection is satisfied, the target service core of the main load balancer stores, in the global cache of the main load balancer, target connection information of the target connection, including:
when the target connection is newly established or the timeout duration of the target connection is reset, the target service core of the main load balancer judges whether the connection state of the target connection is a preset synchronizable state;
and if the connection state of the target connection is a preset synchronizable state, the target service core of the main load balancer stores the target connection information of the target connection in a global cache of the main load balancer.
Optionally, the sending, by the management core of the main load balancer, the target connection information to a target standby load balancer corresponding to the main load balancer includes:
and if the difference value between the timeout duration and the existence duration of the target connection information is greater than the preset synchronizable duration, the management core of the main load balancer sends the target connection information to a target standby load balancer corresponding to the main load balancer.
Optionally, the load balancing system includes a plurality of load balancing packets, each of the load balancing packets includes a main load balancer and at least one standby load balancer, and the main load balancer and the standby load balancer in the same load balancing packet correspond to the same packet identifier;
the acquiring, by the management core of the target standby load balancer, the target connection information, and storing the target connection information in a target cache corresponding to a target service core of the target standby load balancer includes:
if the packet identifier corresponding to the target connection information is the same as the packet identifier of the target standby load balancer, the management core of the target standby load balancer acquires the target connection information;
the management core of the target standby load balancer calculates a target service core of the target standby load balancer according to the port information in the target connection information;
and the management core of the target standby load balancer stores the target connection information in a target cache corresponding to the target service core of the target standby load balancer.
Optionally, the step of storing, by the target service core of the target standby load balancer, the target connection information in a connection tracking table of the target service core of the target standby load balancer includes:
checking the target service of the target standby load balancer to find out whether the historical connection information of the target connection exists in the connection tracking table;
if the connection tracking table exists, the target service core of the target standby load balancer updates the historical connection information stored in the connection tracking table according to the target connection information;
and if the target service core does not exist, adding the target connection information into the connection tracking table by the target service core of the target standby load balancer.
Optionally, the adding, by the target service core of the target standby load balancer, the target connection information in the target connection tracking table includes:
the target service core of the target standby load balancer judges whether the real server pointed by the target connection information is a real server configured on the target standby load balancer;
if so, adding the target connection information in the target connection tracking table by a target service core of the target standby load balancer, and otherwise, judging whether the target real server exists;
and if the target connection information exists, adding the target connection information into the target connection tracking table by the target service core of the target standby load balancer.
Optionally, the sending, by the management core of the primary load balancer, the target connection information to the target backup load balancer includes:
and the management core of the main load balancer sends the target connection information to all the standby load balancers corresponding to the main load balancer in a multicast mode.
Optionally, the global cache and the cache corresponding to the service core of the standby load balancer are ring-shaped non-lock caches.
In a second aspect, a load balancing system is provided, where the system includes a main load balancer and a standby load balancer corresponding to the main load balancer, and the main/standby load balancer uses a user mode network protocol stack, where:
the target service core of the main load balancer is used for storing the target connection information of the target connection in the global cache of the main load balancer when the information synchronization condition of the target connection is met;
the management core of the main load balancer is used for acquiring the target connection information from the global cache and sending the target connection information to a target standby load balancer corresponding to the main load balancer;
the management core of the target standby load balancer is used for acquiring the target connection information and storing the target connection information in a target cache corresponding to a target service core of the target standby load balancer;
and the target service core of the target standby load balancer is used for acquiring the target connection information from the target cache and storing the target connection information in a connection tracking table of the target service core of the target standby load balancer.
Optionally, the target service core of the primary load balancer is specifically configured to:
when the target connection is newly established or the timeout duration of the target connection is reset, judging whether the connection state of the target connection is a preset synchronizable state or not;
and if the connection state of the target connection is a preset synchronizable state, storing the target connection information of the target connection in a global cache of the main load balancer.
Optionally, the management core of the primary load balancer is specifically configured to:
and if the difference value between the timeout duration and the existing duration of the target connection information is greater than the preset synchronizable duration, sending the target connection information to a target standby load balancer corresponding to the main load balancer.
Optionally, the system includes a plurality of load balancing packets, each of the load balancing packets includes a main load balancer and at least one standby load balancer, and the main load balancer and the standby load balancer in the same load balancing packet correspond to the same packet identifier;
the management core of the target standby load balancer is specifically configured to:
if the packet identifier corresponding to the target connection information is the same as the packet identifier of the target standby load balancer, acquiring the target connection information;
calculating a target service core of the target standby load balancer according to port information in the target connection information;
and storing the target connection information in a target cache corresponding to a target service core of the target standby load balancer.
Optionally, the target service core of the target backup load balancer is specifically configured to:
searching whether historical connection information of the target connection exists in the connection tracking table;
if the connection tracking table exists, updating the historical connection information stored in the connection tracking table according to the target connection information;
and if the target connection information does not exist, adding the target connection information into the connection tracking table.
Optionally, the target service core of the target backup load balancer is specifically configured to:
judging whether the real server pointed by the target connection information is a real server configured on the target standby load balancer or not;
if yes, adding the target connection information in the target connection tracking table, otherwise, judging whether the target real server exists;
and if so, adding the target connection information in the target connection tracking table.
Optionally, the management core of the primary load balancer is specifically configured to:
and sending the target connection information to all the standby load equalizers corresponding to the main load equalizer in a multicast mode.
Optionally, the global cache and the cache corresponding to the service core of the standby load balancer are ring-shaped non-lock caches.
The technical scheme provided by the embodiment of the invention has the following beneficial effects:
in the embodiment of the invention, when the information synchronization condition of the target connection is met, the target service core of the main load balancer stores the target connection information of the target connection in the global cache of the main load balancer; a management core of the main load balancer acquires target connection information from the global cache and sends the target connection information to a target standby load balancer corresponding to the main load balancer; a management core of the target standby load balancer acquires target connection information and stores the target connection information in a target cache corresponding to a target service core of the target standby load balancer; and the target service core of the target standby load balancer acquires the target connection information from the target cache and stores the target connection information in a connection tracking table of the target service core of the target standby load balancer. Therefore, for the load balancer based on the user mode network protocol stack, the function that the main load balancer synchronizes the connection information to the standby load balancer is achieved, and the problem that the client request fails after the standby load balancer is switched to the Master state is solved. Meanwhile, the connection information is uniformly transmitted in a multicast mode, so that the transmission efficiency of the connection information can be improved. And moreover, the preset synchronizable state and the preset synchronizable duration are set, so that the performance loss of the main load balancer can be reduced and the read-write load of the standby load balancer can be reduced in the synchronization process of the connection information.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
The embodiment of the invention provides a method for synchronizing connection information, which is applied to a DPVS (distributed private load service) load balancing system based on a user mode protocol stack, wherein the load balancing system comprises a main load balancer and a standby load balancer corresponding to the main load balancer, the main load balancer can correspond to one or more standby load balancers (see figure 1), and the main/standby load balancers can be any network equipment which has a load balancing function and adopts the user mode network protocol stack to process service requests, such as DPVS (distributed private load service) of a fourth layer load balancer. The functions and supported services of the standby load balancer can be completely the same as those of the main load balancer, and the standby load balancer is used for replacing the main load balancer to distribute service requests from different clients to different RSs when the main load balancer breaks down. Specifically, service requests of different clients can reach a main load balancer in the load balancing system, the main load balancer distributes the service requests of the different clients to different RSs through a certain scheduling algorithm, and meanwhile, the main load balancer can synchronize connection information of the service requests to a corresponding standby load balancer, so that when the main load balancer breaks down, the standby load balancer can take over the main load balancer to continue to distribute the service requests based on the synchronized connection information. The main/standby load balancer may include a processor, a memory, and a transceiver, wherein the processor may be configured to perform the processing of synchronizing connection information in the following procedures, the memory may be configured to store data required during the processing and data generated during the processing, and the transceiver may be configured to receive and transmit related data during the processing.
The process flow shown in fig. 2 will be described in detail below with reference to the specific embodiments, and the contents may be as follows:
step 201, when the information synchronization condition of the target connection is satisfied, the target service core of the main load balancer stores the target connection information of the target connection in the global cache of the main load balancer.
In implementation, before executing the method for synchronizing connection information, an ipv sadm tool needs to be installed on the main/standby load balancer, a synchronization daemon on the main load balancer is started through an ipv sadm-start-daemon master command to start a synchronization function, and a synchronization daemon on the standby load balancer is started through an ipv sadm-start-daemon command to start a synchronization function. After the synchronization daemon on the main load balancer is started, the main load balancer can allocate a global cache to store the connection information to be synchronized on each service core of the main load balancer; the primary load balancer may also create a send Socket (Socket) to send connection information to the standby load balancer. After the synchronization daemon on the standby load balancer is started, the standby load balancer may create a receiving Socket (Socket) to receive connection information sent by the main load balancer. Each piece of connection information may include the following information: network Protocol (Protocol), client IP address (CIP), client port (CPort), virtual IP address (VIP), virtual port (VPort), real server IP address (RIP), real server port (RPort), connection Flags (Flags), connection status (State), etc.
Furthermore, each service core of the main load balancer needs to distribute and process a large number of service requests, and connection information of connections corresponding to the service requests changes frequently, and each service core of the main load balancer can record corresponding connection information in respective connection tracking table in time and store connection information required to be synchronized in a global cache of the main load balancer in time. If the current connection information (which may be referred to as target connection information) of the target connection can satisfy the preset information synchronization condition, it represents that the target connection information needs to be synchronized, and at this time, a service core (which may be referred to as a target service core) on the main load balancer managing the target connection may store the target connection information in a global cache of the main load balancer.
Optionally, the information synchronization condition may be that a new connection is established or a timeout duration is reset, and the information synchronization condition is in a preset synchronizable state, and correspondingly, the specific processing instep 201 may be as follows: when a new target connection is established or the timeout duration of the target connection is reset, the target service core of the main load balancer judges whether the connection state of the target connection is a preset synchronizable state; and if the connection state of the target connection is a preset synchronizable state, the target service core of the main load balancer stores the target connection information of the target connection in the global cache of the main load balancer.
In implementation, since a highly loaded primary load balancer may need to send a large amount of connection information to a standby load balancer, this will reduce the performance of the primary load balancer. In order to reduce the performance loss of the main load balancer caused by the synchronization processing of the connection information, a synchronizable state (which may be referred to as a preset synchronizable state) of the connection information may be set on the main load balancer in advance, and the main load balancer is specified to store only the connection information in the preset synchronizable state in the global cache. Specifically, when the target connection is a newly-established connection, the target service core of the main load balancer newly adds connection information of the target connection in the connection tracking table of the target service core of the main load balancer; when the timeout duration of the target connection is reset, it indicates that the connection state of the existing connection is changed, the target service core of the main load balancer updates the connection information of the target connection in the connection tracking table of the target service core of the main load balancer, the target service core of the main load balancer can judge whether the connection state of the target connection is a preset synchronizable state when the target service core of the main load balancer is newly added or updates the connection information of the target connection in the connection tracking table, and when the connection state of the target connection is the preset synchronizable state, the target service core of the main load balancer can store the target connection information of the target connection in the global cache of the main load balancer, so that the management core of the main load balancer obtains the target connection information from the global cache and sends the target connection information to the target load balancer. For example, the target connection may be a TCP (Transmission Control Protocol) connection, and for the TCP connection, the preset synchronizable state may be an ESTABLISHED state, a FIN _ WAIT state, a CLOSE _ WAIT state, and a TIME _ WAIT state, and it can be understood that when connection information of the target connection changes and the connection state recorded in the target connection information is any one of the above 5 connection states, the target connection information needs to be synchronized, and the target service core of the main load balancer needs to store the target connection information in the global cache of the main load balancer.
It should be noted that before the target service core of the main load balancer determines whether the connection state of the target connection is the preset synchronizable state, the following processing may be performed: firstly, the target service core of the main load balancer judges whether the target service core is a provider of connection information, for example, the target service core of the main load balancer can judge according to an internal variable master _ state of the target service core of the main load balancer, if the value of the master _ state is 0, the target service core of the main load balancer is not the provider of the connection information, and at this time, the connection information needs to be discarded; if the value of master _ state is not 0, the target service core of the main load balancer is the provider of the connection information, and at this time, the related operation of synchronizing the connection information can be continued. Then, the target service core of the primary load balancer may further determine whether the target connection information has another owner, for example, the target service core may determine according to a value of a parameter control in the target connection information, and if the value of the parameter control is 0, the target connection information has no owner; if the value of the control is 1, the target connection information has an owner, and the target connection information is accurate connection information with server port information (e.g., port information of a real server), at this time, the target service core of the main load equalizer may recursively call the function dp _ vs _ sync _ con to search for inaccurate connection information without the server port information, so as to write the target connection information and the corresponding inaccurate connection information into the global cache.
Step 202, the management core of the main load balancer obtains the target connection information from the global cache, and sends the target connection information to the target standby load balancer corresponding to the main load balancer.
In an implementation, the management core of the main load balancer may periodically obtain connection information that needs to be synchronized from the global cache, and the management core of the main load balancer may encapsulate all the connection information stored in the global cache in one or more data packets, and send the connection information that needs to be synchronized to the corresponding standby load balancer through a send (Transmit) thread. In this way, after the target service core of the main load balancer stores the target connection information in the global cache, the management core of the main load balancer may obtain the target connection information from the global cache, and then may send the target connection information to the target standby load balancer corresponding to the main load balancer.
Optionally, in order to ensure that the connection information synchronized to the standby load balancer is not deleted within a certain time period and remains valid, correspondingly, the specific processing instep 202 may be as follows: and if the difference value between the timeout duration and the existing duration of the target connection information is greater than the preset synchronizable duration, the management core of the main load balancer sends the target connection information to the target standby load balancer corresponding to the main load balancer.
In implementation, if the time interval from generation of the target connection information to the current time (which may be referred to as the existence duration of the target connection information) is long, after the target connection information is sent to the target load balancer, the existence duration of the target connection information is equal to the current timeout duration of the target connection, the target connection information is deleted by the target load balancer, at this time, the target connection information is connection information invalid for the target load balancer, the main load balancer sends the target connection information to the target load balancer, only the read-write load of the target load balancer is increased, therefore, a synchronizable duration (which may be referred to as a preset synchronizable duration) may be preset on the main load balancer, and the main load balancer is specified to send only the connection information, in which the difference between the current timeout duration of the target connection information and the existence duration of the target connection information is greater than the preset synchronizable duration, to the target load balancer corresponding to the main load balancer The equalizer can reduce the quantity of connection information required to be synchronized, and reduce the load of the main load equalizer and the target standby load equalizer. The value of the preset synchronizable time duration may be set according to actual needs, for example, the preset synchronizable time duration may be set to be half of the Timeout time duration (Timeout/2), which is not limited in the present invention.
It should be noted that before the management core of the main load balancer determines that the difference between the current timeout duration of the target connection and the existence duration of the target connection information is greater than the preset synchronizable duration, the following processing may be performed: the method comprises the steps that whether a synchronization function is started by a main load balancer or not is checked, if the synchronization function is started, a management core of the main load balancer can also check whether a communication path is established with a standby load balancer or not, if the communication path is established, the management core of the main load balancer can continuously check whether a cache space of a sending thread is enough or not, and if the cache space of the sending thread is enough, the management core of the main load balancer can smoothly acquire target connection information from a global cache. It can be understood that if the main load balancer has any one of the situations that the synchronization function is not started, the communication path is not established, and the cache space of the sending thread is insufficient, the management core of the main load balancer cannot successfully send the target connection information to the target standby load balancer, and the target standby load balancer cannot acquire the target connection information, so that when the main load balancer fails and the target standby load balancer switches to the Master state, the target connection is disconnected or the target standby load balancer cannot forward the service request from the client corresponding to the target connection to the same RS.
Optionally, the main load balancer may correspond to multiple backup load balancers, and in order to save server resources, correspondingly, the management core of the main load balancer may send the target connection information to all backup load balancers corresponding to the main load balancer in a multicast manner.
In implementation, after the management core of the main load balancer obtains the target connection information from the global cache of the main load balancer, the target connection information may be sent to all the standby load balancers corresponding to the main load balancer in a UDP (User Datagram Protocol) multicast manner. It should be noted that, when creating a sending socket, the main load balancer may set a multicast address to create a multicast group, and when creating a receiving socket, the standby load balancer may join the multicast group. It can be understood that all the standby load balancers joining the multicast group can receive the multicast data sent by the main load balancer.
Step 203, the management core of the target standby load balancer acquires the target connection information and stores the target connection information in the target cache corresponding to the target service core of the target standby load balancer.
In implementation, the target standby load balancer may Receive, through a Receive thread, target connection information from the main load balancer, and further may calculate a target service core for processing the target connection information according to a specified scheduling algorithm, and then a management core of the target standby load balancer may obtain the target connection information and store the target connection information in a cache (which may be referred to as a target cache) corresponding to the target service core. The scheduling algorithm may be a round robin algorithm (RR), a weighted round robin algorithm (WRR), a weighted minimum concatenation algorithm (WLC), a concatenated hash algorithm (CONHASH), and the like, which is not limited in this disclosure.
Optionally, the load balancing system may include a plurality of load balancing packets, each load balancing packet includes a main load balancer and at least one standby load balancer, and accordingly, the specific processing instep 203 may be as follows: if the packet identifier corresponding to the target connection information is the same as the packet identifier of the target standby load balancer, the management core of the target standby load balancer acquires the target connection information; the management core of the target standby load balancer calculates a target service core of the target standby load balancer according to the port information in the target connection information; and the management core of the target standby load balancer stores the target connection information in a target cache corresponding to the target service core of the target standby load balancer.
In an implementation, the load balancing system may include a plurality of load balancing packets, each load balancing packet including a primary load balancer and at least one backup load balancer (see fig. 3), the primary load balancer and the backup load balancer within the same load balancing packet corresponding to the same packet identifier. When the synchronization function is started, the same packet identifier (SyncID, which may be referred to as synchronization ID) may be configured for the main load balancer and the standby load balancer in the same load balancing packet, and the corresponding relationship between the main load balancer and the standby load balancer is determined by the packet identifier. In this way, when sending connection information to the standby load balancer, the management core of the main load balancer may encapsulate the target connection information and the packet identifier of the main load balancer in one data packet, and send the data packet to the target standby load balancer through the sending thread. Furthermore, when the target standby load balancer receives the target connection information, it may check whether a packet identifier in the data packet is the same as a packet identifier of the target standby load balancer, if the packet identifier is different from the packet identifier of the target standby load balancer, the target standby load balancer discards the data packet, if the packet identifier is the same as the packet identifier of the target standby load balancer, the management core of the target standby load balancer acquires the target connection information and calculates which service core in the target standby load balancer processes the target connection information, where the management core of the target standby load balancer may calculate, according to the client port recorded in the target connection information, a core identifier (lcore id, cid) that a service core for processing the target connection is a target service core in the target standby load balancer, and then the management core of the target standby load balancer stores the target connection information in a target cache corresponding to the core identifier. It should be noted that each service core of the target backup load balancer has a core identifier, and each service core may be bound to a corresponding cache, and the corresponding relationship between the service core and the cache in the target backup load balancer is determined by the core identifier. The kernel identifier corresponding to the target connection information may be calculated by using the following function: key ═ (ntohs) (sync _ conn- > cport)% sync _ worker _ cpu _ num; cid _ cpu _ mapping [ key ].
It should be noted that, before the management core of the target standby load balancer stores the target connection information in the target cache, the following processing may be performed: the method comprises the steps that whether a synchronous function is started or not is checked, if the synchronous function is started, a management core of a target standby load balancer needs to check whether a communication channel is established with a main load balancer or not, if the communication channel is established, the management core of the target standby load balancer needs to check whether the length of received connection information is normal or not, if the length of the received connection information is normal, the management core of the target standby load balancer needs to check whether a packet identifier corresponding to target connection information is the same as that of the standby load balancer or not, and if the packet identifiers are the same, the management core of the target standby load balancer can smoothly acquire the target connection information. It can be understood that if the target backup load balancer has any one of the situations that the synchronization function is not started, the communication path is not established, the length of the connection information is not normal, and the packet identifier is different, the management core of the target backup load balancer cannot acquire the target connection information, so that after the main load balancer fails and the target backup load balancer switches to the Master state, the target connection is disconnected or the target backup load balancer cannot forward the service request from the client corresponding to the target connection to the same RS.
And step 204, the target service core of the target standby load balancer acquires the target connection information from the target cache, and stores the target connection information in a connection tracking table of the target service core of the target standby load balancer.
In implementation, the service core of the standby load balancer may continuously monitor the corresponding cache and timely acquire the connection information stored in the cache. After the management core of the target standby load balancer stores the target connection information into the target cache corresponding to the target service core of the target standby load balancer, the target service core of the target standby load balancer may obtain the target connection information from the target cache, and may store the target connection information in the connection tracking table of the target service core of the target standby load balancer.
It should be noted that before the target service core of the target standby load balancer obtains the target connection information from the target cache, the following processing may be performed: the target service core of the target standby load balancer checks whether the target service core is a management core, if not, the target service core of the target standby load balancer needs to check whether the cache of the receiving thread is empty, if not, the target service core of the target standby load balancer needs to check whether the storage space of the target cache is sufficient, and if the storage space of the target cache is sufficient, the target service core of the target standby load balancer can obtain the target connection information from the target cache. It can be understood that if the target service core of the target backup load balancer detects that the target service core is a management core, the cache of the receiving thread is empty, or the storage space of the target cache is insufficient, the target service core of the backup load balancer discards the target connection information.
Optionally, since the connection tracking table of the target service core may already store the historical connection information of the target connection, at this time, the historical connection information of the target connection may be updated according to the target connection information of the target connection, and correspondingly, the specific processing instep 204 may be as follows: target service of the target standby load balancer checks to find whether historical connection information of target connection exists in the connection tracking table; if the target service core of the target standby load balancer exists, updating historical connection information stored in the connection tracking table according to the target connection information; and if the target service core does not exist, adding target connection information into the connection tracking table by the target service core of the target standby load balancer.
In implementation, the target service core of the target standby load balancer may call the function dp _ vs _ conn _ get to search whether there is historical connection information of the target connection in the connection tracking table, and if there is historical connection information of the target connection in the connection tracking table of the target service core of the target standby load balancer, the target service core of the target standby load balancer may update the historical connection information stored in the connection tracking table according to the target connection information. The updated content may include a connection flag, a connection status, a timeout duration, and the like of the target connection. If the connection tracking table of the target service core of the target backup load balancer does not have the historical connection information of the target connection, the target service core of the target backup load balancer can add the target connection information into the connection tracking table.
It should be noted that before the target service of the target backup load balancer checks and finds whether the historical connection information of the target connection exists in the connection tracking table, the following processing may be performed: judging whether the target connection information is the connection information of the DPVS _ CONN _ F _ TEMPLATE type, if not, performing subsequent synchronous processing on the target connection information by a target service core calling function dp _ vs _ CONN _ get of the target load balancer, and if so, performing subsequent synchronous processing on the target connection information by a target service core calling function dp _ vs _ sync _ ct _ in of the target load balancer.
Optionally, if historical connection information of the target connection does not exist in the connection tracking table of the target service core of the target backup load balancer, target connection information may be newly established in the connection tracking table. In order to ensure that a subsequent service request from a system client can be sent to the same RS, it is necessary to check whether an RS to which the target connection information points exists in the target backup load balancer, and accordingly, a specific process of adding the target connection information to the target connection tracking table by the target service core of the target backup load balancer may be as follows: the target service core of the target standby load balancer judges whether the real server pointed by the target connection information is a real server configured on the target standby load balancer; if yes, adding target connection information into a target connection tracking table by a target service core of the target standby load balancer, otherwise, judging whether a target real server exists by the target service core of the target standby load balancer; and if so, adding target connection information into the target connection tracking table by the target service core of the target standby load balancer.
In implementation, when the target connection information is synchronously processed, situations that the RS pointed by the target connection information is abnormal, so that the RS in the server cluster is removed, or the RS pointed by the target backup load balancer is not configured, and the like may occur, at this time, the target connection information is invalid connection information for the target backup load balancer, in order to reduce loads of the main load balancer and the target backup load balancer, after a target service core of the target backup load balancer acquires the target connection information from a target cache, it may be determined whether the RS pointed by the target connection information is the RS configured on the target backup load balancer, and if so, the target service core of the target backup load balancer may add the target connection information in a target connection tracking table; if not, the target service core of the target backup load balancer may search whether the RS exists in the server cluster (for example, calling the function dp _ vs _ find _ dest to search for the RS), and if so, it indicates that the target backup load balancer does not configure the RS but the RS is available, and at this time, the target service core of the target backup load balancer may also add target connection information in the target connection tracking table. It can be understood that, if there is no RS pointed to by the target connection information in the server cluster, it indicates that the RS has been removed from the server cluster due to an exception, and the target service core of the target standby load balancer may discard the target connection information and may return an exception response to the management core of the target standby load balancer.
It is worth mentioning that if the historical connection information of the target connection does not exist in the connection tracking table of the target service core of the target standby load balancer, the target service core of the target standby load balancer can also judge whether the target connection information has other owners, and if the target service core of the target standby load balancer has other owners, the target service core of the target standby load balancer can call a function dp _ vs _ ct _ in _ get to search whether the connection tracking table has inaccurate connection information corresponding to the target connection information; if the inaccurate connection information corresponding to the target connection information is found, it indicates that the RS pointed by the target connection information is available, and at this time, the target service core of the target backup load balancer may also add the target connection information in the target connection tracking table.
Optionally, the global cache of the main load balancer and the cache of the standby load balancer are both ring-shaped non-lock caches.
In implementation, each of the global cache of the primary load balancer and each of the caches of the backup load balancers may be a ring-shaped lock-free cache (e.g., ring cache ring in DPVS), and the ring-shaped lock-free cache is a large enough memory pre-allocated as needed and can be dynamically adjusted to avoid data loss due to insufficient storage space. The annular lock-free cache can support multiple producers, and by adopting the annular lock-free cache, all service cores in the main load balancer can store connection information in the global cache without occupying lock resources. The annular lock-free cache can also provide borderless byte stream service, and after connection information is taken out from the global cache of the main load equalizer and each cache of the standby load equalizer by adopting the annular lock-free cache, when the connection information is subsequently stored, the storage position of other connection information does not need to be moved, so that the read-write efficiency can be improved.
In the embodiment of the invention, when the information synchronization condition of the target connection is met, the target service core of the main load balancer stores the target connection information of the target connection in the global cache of the main load balancer; a management core of the main load balancer acquires target connection information from the global cache and sends the target connection information to a target standby load balancer corresponding to the main load balancer; a management core of the target standby load balancer acquires target connection information and stores the target connection information in a target cache corresponding to a target service core of the target standby load balancer; and the target service core of the target standby load balancer acquires the target connection information from the target cache and stores the target connection information in a connection tracking table of the target service core of the target standby load balancer. Therefore, for the load balancer based on the user mode network protocol stack, the function that the main load balancer synchronizes the connection information to the standby load balancer is achieved, and the problem that the client request fails after the standby load balancer is switched to the Master state is solved. Meanwhile, the connection information is uniformly transmitted in a multicast mode, so that the transmission efficiency of the connection information can be improved. And moreover, the preset synchronizable state and the preset synchronizable duration are set, so that the performance loss of the main load balancer can be reduced and the read-write load of the standby load balancer can be reduced in the synchronization process of the connection information.
Based on the same technical concept, an embodiment of the present invention further provides a load balancing system (see fig. 4), where the system includes a main load balancer and a standby load balancer corresponding to the main load balancer, and the main/standby load balancer uses a user mode network protocol stack, where:
the target service core of the main load balancer is used for storing the target connection information of the target connection in the global cache of the main load balancer when the information synchronization condition of the target connection is met;
the management core of the main load balancer is used for acquiring the target connection information from the global cache and sending the target connection information to a target standby load balancer corresponding to the main load balancer;
the management core of the target standby load balancer is used for acquiring the target connection information and storing the target connection information in a target cache corresponding to a target service core of the target standby load balancer;
and the target service core of the target standby load balancer is used for acquiring the target connection information from the target cache and storing the target connection information in a connection tracking table of the target service core of the target standby load balancer.
Optionally, the target service core of the primary load balancer is specifically configured to:
when the target connection is newly established or the timeout duration of the target connection is reset, judging whether the connection state of the target connection is a preset synchronizable state or not;
and if the connection state of the target connection is a preset synchronizable state, storing the target connection information of the target connection in a global cache of the main load balancer.
Optionally, the management core of the primary load balancer is specifically configured to:
and if the difference value between the timeout duration and the existing duration of the target connection information is greater than the preset synchronizable duration, sending the target connection information to a target standby load balancer corresponding to the main load balancer.
Optionally, the system includes a plurality of load balancing packets, each of the load balancing packets includes a main load balancer and at least one standby load balancer, and the main load balancer and the standby load balancer in the same load balancing packet correspond to the same packet identifier;
the management core of the target standby load balancer is specifically configured to:
if the packet identifier corresponding to the target connection information is the same as the packet identifier of the target standby load balancer, acquiring the target connection information;
calculating a target service core of the target standby load balancer according to port information in the target connection information;
and storing the target connection information in a target cache corresponding to a target service core of the target standby load balancer.
Optionally, the target service core of the target backup load balancer is specifically configured to:
searching whether historical connection information of the target connection exists in the connection tracking table;
if the connection tracking table exists, updating the historical connection information stored in the connection tracking table according to the target connection information;
and if the target connection information does not exist, adding the target connection information into the connection tracking table.
Optionally, the target service core of the target backup load balancer is specifically configured to:
judging whether the real server pointed by the target connection information is a real server configured on the target standby load balancer or not;
if yes, adding the target connection information in the target connection tracking table, otherwise, judging whether the target real server exists;
and if so, adding the target connection information in the target connection tracking table.
Optionally, the management core of the primary load balancer is specifically configured to:
and sending the target connection information to all the standby load equalizers corresponding to the main load equalizer in a multicast mode.
Optionally, the global cache and the cache corresponding to the service core of the standby load balancer are ring-shaped non-lock caches.
In the embodiment of the invention, when the information synchronization condition of the target connection is met, the target service core of the main load balancer stores the target connection information of the target connection in the global cache of the main load balancer; a management core of the main load balancer acquires target connection information from the global cache and sends the target connection information to a target standby load balancer corresponding to the main load balancer; a management core of the target standby load balancer acquires target connection information and stores the target connection information in a target cache corresponding to a target service core of the target standby load balancer; and the target service core of the target standby load balancer acquires the target connection information from the target cache and stores the target connection information in a connection tracking table of the target service core of the target standby load balancer. Therefore, for the load balancer based on the user mode network protocol stack, the function that the main load balancer synchronizes the connection information to the standby load balancer is achieved, and the problem that the client request fails after the standby load balancer is switched to the Master state is solved. Meanwhile, the connection information is uniformly transmitted in a multicast mode, so that the transmission efficiency of the connection information can be improved. And moreover, the preset synchronizable state and the preset synchronizable duration are set, so that the performance loss of the main load balancer can be reduced and the read-write load of the standby load balancer can be reduced in the synchronization process of the connection information.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.