8 minutes 5 points so that you completely understand the load balancing

Load Balancing

Load balancing is a high availability a key component architecture, mainly used to improve performance and availability through load balancing to distribute traffic to multiple servers, simultaneous multi-server can eliminate this part of the single point of failure .

Of course, the load balancer itself is a single point of failure risks can be considered later in the article said load balancing stateful failover or other programs to eliminate single points of failure increase availability.

Do not use a load-balanced Web architecture in general would look like this:

v2-f45fa96d2222fd48ec6b51961954e713_hd.png


No load balancing architecture

In this instance inside, users connect directly via yourdomain.com Web Server, if a Web Server hung up the entire system can not be used, that is, we often say that the system of single points of failure , the same if a large number of users simultaneously access this a server, then those users are likely to encounter problems or simply slow load times can not be connected.

This part of the single point of failure can be mitigated by introducing at least another load balancer and Web Server. In general all the back-end servers provide the same content to users regardless of which server will receive access to the same content. And because you have multiple servers while providing services, but also increased the load capacity of the system to improve performance.

What types of traffic load balancing can handle

As the general programmers access to load balancing may be mostly deal with HTTP, HTTPS traffic, but actually load balancing can also handle TCP and UDP traffic (such as access to the database cluster, DNS, etc.).

v2-485a5451d9ee4715806884fcee833f52_hd.png

Load Balancing Algorithm

Load balancing algorithm used to determine the flow should be distributed to which health on the server, a few common algorithm is as follows:

Robin Round - rotation (Round Robin) means that the server will be sequentially selected, such as a load balancer will first request a server assigned to the first, then the next request is assigned to a second server, so that dispensing continues distribution after completion of the first round back to the beginning assigned to a server (operating system scheduling algorithm refresher). It's more suitable for all server processing power and the same amount of processing each business about the same time.

Connections Least - Least Connections (Least Connections) This means that the load balancing algorithm will select the currently connected server minimum.

Hash IP - In this algorithm, the load balancer according to the source IP requests to determine which server distributed points. This method ensures that a particular user will always access the same server.

There are some other not too common algorithms, such as Url hash, Random and so on.

Health Check (health checks)

In a load-balancing algorithm we have a premise that traffic will only be allocated to health on the server, load balancer server how to judge now whether healthy?

In order to monitor server health, general health checks will be connected to the server via the protocol and port configuration to try to ensure that the server is listening. If a server health check fails, that server can not respond to normal requests, it will be automatically removed pond, the traffic will not be assigned to this server until it is broken by the health check.

This can refer to specific principles of healthy Ali cloud document checks on load balancing

v2-6d70a504dc991d34897143afd7632109_hd.png

How to deal with load balancing state

We all know that based user authentication session there will be some of the information session on the server, but the introduction of the system load balance when it will be some problems.

For example electricity supplier site, when a login request the user U transmitted is distributed to the server S1 and record the session information in the server, and when the user wants to submit shopping requested This request is distributed to the server S2, but the server S2 U did not save the user's session information.

To solve this problem and one is that before you can use IP hash algorithm, the algorithm based on the server IP corresponding to distribute traffic, so you can ensure the same user traffic will have access to the same server. Another application layer is Sticky session , Chinese should be called sticky sessions , the load balancer will then set a cookie with the cookie session will be assigned to the same server.

Load balancing hot standby (Hot standby)

As mentioned at the beginning, the load balancer itself is a single point of failure problems, which solution is a hot standby (a large basic method is to improve the availability of redundancy).

Redundancy Dual In order to solve the load balancer single point of failure, the introduction of a second load balancer, when the master node GG switch to the standby node. The Internet to find a comparison image gif:

v2-46bd018234cdb17127e455684c4a7f67_hd.png

Before I graduate design architecture with a hot standby, to achieve the nginx is to achieve high availability on cold backup, hot backup, hot standby through keepalived,


to sum up

This article considered for a number of preliminary conclusions and understanding of load balancing, more for those who want to have a comprehensive understanding of the preliminary friend of load balancing.


At last

Welcome to share with everyone, like the point of a praise yo remember the article, thanks for the support!


Guess you like

Origin blog.51cto.com/14442094/2438386