Several implementations of load balancing

First, the basic concept of load balancing

Load balancing refers to an architectural method that distributes requests to multiple application servers to distribute pressure. It exists in a cluster, and when a node hangs, it can automatically no longer distribute requests. to this node.


2. Implementation method

1. Redirect

This method is to send all requests to the front-end computer, and the front-end computer obtains the application server to be allocated through an algorithm, and then responds to the client, and the client redirects it to the application server.

In this way, since every request has to be redirected, the efficiency is not very high.


2. Reverse proxy

In this way, the request is distributed to the application server by using a reverse proxy on the front-end computer, and the client does not need to request again. There are usually two implementation methods, one is to use a switch, and the other is to Implemented with software like nginx

In this way, since there is no need to redirect again, it is more efficient than the first one, but since the request and response are both from the front-end, it is a great test for the front-end.


3. Data link return

In this way, by setting a virtual IP for the application server, and then by modifying the mac address, the request is distributed, and after the application server receives the request, it can directly respond to the client without going through the front-end.

In this way, since the front-end only needs to accept the request and does not need to respond to the data, the efficiency is higher than the second one.


3. Load Balancing Algorithm

1. Polling method

Distribute requests to the back-end servers in turn in turn, and it treats each server in the back-end in a balanced manner, regardless of the actual number of connections to the server and the current system load.


2. Random method

Through the random algorithm of the system, one of the servers is randomly selected for access according to the list size value of the back-end servers. It can be known from the probability and statistics theory that as the number of times the client calls the server increases,

Its actual effect is getting closer and closer to evenly distributing the call volume to each server in the backend, which is the result of polling.


3. Source address hashing

The idea of ​​source address hashing is to obtain a value obtained by obtaining the client's IP address through a hash function, and use this value to perform a modulo operation on the size of the server list. The result is the serial number of the server that the client needs to access. The source address hashing method is used for load balancing. When the client with the same IP address does not change the list of backend servers, it will be mapped to the same backend server for access every time.


4. Weighted Round Robin Method

Different back-end servers may have different machine configurations and current system loads, so their compressive capabilities are also different. Assign a higher weight to a machine with a high configuration and a low load, so that it can process more requests; while a machine with a low configuration and a high load, assign a lower weight to it, reduce its system load, and weighted polling works well deal with this problem, and distribute the requests to the backends in order and according to the weight.


5. Weighted random method

Like the weighted round-robin method, the weighted random method also assigns different weights according to the configuration of the backend machine and the load of the system. The difference is that it requests the backend servers randomly by weight, not sequentially.


6. Minimum number of connections method

The algorithm for the minimum number of connections is more flexible and intelligent. Due to the different configurations of the back-end servers, the processing of requests is faster or slower. It dynamically selects the one with the least current backlog connections according to the current connection situation of the back-end server. One server is used to process the current request, improve the utilization efficiency of back-end services as much as possible, and distribute the responsibility to each server reasonably.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324841281&siteId=291194637