What is
load balancing
Load balancing refers to dividing the amount of tasks that must be completed among multiple computers so that more work can be completed at the same time, and all users can be served quickly.
Load balancing can be implemented through hardware, software, or a combination of both. Generally, load balancing is the main reason for grouping computer servers.
On the Internet, companies with large traffic usually use load balancing. There are several ways to load balance network traffic. For Web services, one method is to forward each request to each different host address in the DNS table. Generally, if two servers need to balance the workload, the third server is needed to determine which server the work is assigned to. Since load balancing requires multiple servers, it is usually used in conjunction with failover and backup services. In some methods, servers are distributed in different geographic locations.
One of the most important applications of load balancing is to use multiple servers to provide a single service. This solution is sometimes called a server farm. Generally, load balancing is mainly applied to Web sites, large Internet Relay Chat networks, high-traffic file download sites, NNTP (Network News Transfer Protocol) services, and DNS services. Now load balancers also start to support database services, which are called database load balancers.
For Internet services, the load balancer is usually a software program that listens to an external port through which Internet users can access the service, and the software as the load balancer forwards the user’s request to the back-end intranet server. The internal network server returns the requested response to the load balancer, and the load balancer sends the response to the user. This hides the internal network structure from Internet users and prevents users from directly accessing the background (intranet) server, making the server more secure , Which can prevent attacks on the core network stack and services running on other ports.
When all backend servers fail, some load balancers will provide some special functions to handle this situation. For example, forwarding the request to a backup load balancer, displaying a message about service interruption, etc. The load balancer allows the IT team to significantly improve fault tolerance. It can automatically provide a large amount of capacity to handle any increase or decrease in application traffic.
Principles of
load balancing
Load Balancing NAT (Network Address Translation) is simply to convert one IP address to another IP address, which is generally used for translation between unregistered internal addresses and legal, registered Internet IP addresses. It is suitable for situations where the Internet IP address is tight and the outside of the network does not want to know the internal network structure.
This kind of load balancing is the basis of the bandwidth aggregation technology of current multi-WAN routers. Take Xinxiang router as an example:
The multi-WAN router implements the industry’s advanced dynamic load balancing mechanism. The multi-WAN port dynamic load balancing technology can dynamically allocate intranet data traffic when multiple lines are used, dynamically realize the function of bandwidth aggregation, and adopt a unique three A load balancing mechanism:
1. Session: All enabled WAN ports work in a way of sharing sessions equally.
If the first session is connected through the WAN1 port, the next session will automatically select WAN2 to flow out, and the third session will select WAN3 to flow out (assuming all WAN ports are enabled)
This method is suitable for bundling multiple lines with the same bandwidth.
2. This method is suitable for multiple lines with different bandwidths to work better together. For example, the WAN1 port is connected to a 512K ADSL, and the WAN2 port is connected to a 2M fiber. In this case, we can set the ratio to 1:4, so that the bandwidth of the two lines can be fully utilized.
3. Traffic: According to the data flow distribution load, the system automatically selects the WAN port with the smallest flow as the outlet.
This method is suitable for mixed use of multiple lines when the line is unstable. When a certain line is temporarily blocked or the line is unstable, the traffic will be automatically distributed to another stable line. However, this method is not recommended when multiple lines are stable.
With these three kinds of load balancing, the router can flexibly deal with the complex situation of multiple line mixing, supporting multiple line mixing, supporting multiple protocols, and being able to meet multiple complex applications.
Advantages of load balancing
First, network load balancing can spread incoming requests to up to 32 servers, that is, up to 32 servers can be used to share external network request services. Network load balancing technology ensures that the server can respond quickly even under heavy load;
Second, network load balancing only needs to provide one IP address (or domain name) to the outside;
Third, when one or several servers in network load balancing are unavailable, the service will not be interrupted. When network load balancing automatically detects that the server is unavailable, it can quickly reassign client communications among the remaining servers. This protection measure can help you provide uninterrupted services for key business programs, and can increase the number of network load balancing servers according to the increase in network traffic;
Fourth, network load balancing can be implemented on ordinary computers.
Continuity of load balancing
An important issue that the load balancer needs to deal with is: how to save user sessions? If the session information is stored in the background server, the user's next request may be allocated to a different background server, and the user session cannot continue at this time. The load balancer can cache user sessions and then distribute user requests to different backend servers. But this will bring load problems to the load balancer.
One solution is to send all requests in a user session to the same backend server. That is persistence or stickiness. The disadvantage of this method is that it cannot tolerate failover. If the background server fails, the session it provides will not be available, and any sessions that depend on it will be lost. This problem is usually related to the data center. Although Web Service is non-connection-oriented, the back-end database is inherently connection-oriented.
The second plan is to assign the server that provides the service based on the user name and client IP, or it can be randomly assigned. Because customers may connect to the Internet through DHCP, NAT or Web proxy, their IP addresses may change frequently, which makes the quality of service of this solution impossible to guarantee. Random allocation is stored and saved by the load balancer. If the load balancer is replaced or fails, this information may be lost; in addition (load balancer) when the load is high, in order to ensure that the allocation table space will not be exhausted, the timeout allocation information must be deleted. The random allocation method also requires the client to maintain the session state. If the client's browser disables the cookie function, it will cause problems. A good load balancer uses a variety of persistent (session persistence) techniques to avoid failures when some of them are unavailable.
Another solution is to save each session information in a database. Because this program will increase the load of the database, this program is not good for performance improvement. The database is best used to store session data with a relatively long session time. In order to avoid a single point of failure of the database and improve its scalability, the database is usually replicated to multiple servers, and requests are distributed to the database server through a load balancer. The state server technology in Microsoft ASP.net is an example of a typical session database. All servers in the cluster save their session information to the state server, and they can query the state server for session data.
Usually the client browser can save the user's each session information. For example, use browser cookies, encrypt data and add a timestamp to ensure security; URL rewriting. Storing session information on the client is usually the preferred solution, because the load balancer can flexibly choose the backend server to process user requests. However, this method is not suitable for some more complex e-commerce, because the session data in e-commerce is large, and the server needs to reprocess the session information frequently; at the same time, URL rewriting has security problems because users can change the session stream data ; Encrypted client cookies have always been controversial in terms of security, unless all sessions are through HTTPS, but HTTPS is vulnerable to man-in-the-middle attacks.
Load balancing applications
Load balancing is very useful for redundancy of communication links. For example, a company may have multiple Internet access lines to ensure that a certain one can still access the Internet normally.
The architecture of failover means that one connection is used normally, and the other connection is used as a backup. It will be enabled when the first one fails.
Using a load balancer, two (multiple) connections can all be put into use. There is a device or program that monitors the connectivity of all connections in real time, and routes the packets being sent. Using multiple connections at the same time can increase bandwidth.
Many telecommunications companies have multiple lines available in their internal networks or connected to external networks (other telecommunications networks). To avoid network congestion on a certain link, minimize the cost of connecting to other networks, or improve network reliability, they use load balancing to transfer traffic from one link to another.
Another use of load balancing is to monitor network activity. Load balancers can be used to split huge network traffic into several sub-streams and use network analyzers, each of which reads part of the original data. This is very useful for monitoring 10GbE, STM64 high-speed networks, where complex data processing is almost impossible due to the large amount of data.