Common algorithms for load Balancing

Source: Internet
Author: User

1. Random algorithm:

the load balancing method randomly assigns the load to each available server, selects a server by the random number generation algorithm, and sends the connection to it. the same request will fall to machine A, a will fall on machine B, the cache will be frequently eliminated, so that the cache hit rate is low.

2. Polling algorithm:

The polling algorithm assigns each new connection request to the next server in order, eventually splitting all requests to all servers. Polling algorithms work well in most cases, but if a load-balanced device is not completely equal in terms of processing speed, connection speed, and memory, the effect will be bad. Of course, the cache hit is not high.

3. weighted Polling algorithm:

The number of connections accepted by each machine is assigned by weight ratio. This is an improvement to the ordinary polling algorithm, such as you can set: The third machine is capable of processing twice times the first machine, then the load balancer will allocate twice times the number of connections to the 3rd machine.

4. Dynamic Polling algorithm:

Similar to weighted polling, however, weight values are based on ongoing monitoring of individual servers and are constantly updated. This is a dynamic load balancing algorithm that allocates connections based on the real-time performance analysis of the server, such as the current number of connections per node or the fastest response time for a node.

5, the fastest response algorithm:

The Balancer records the network response time of itself to each cluster node and assigns the next incoming connection request to the node with the shortest response time;

6. Minimum connection algorithm:

The Balancer records all active connections and sends the next new request to the node that currently contains the least number of connections.

7. Hash hashing algorithm:

Hashing is also called hash method (hash), through the single-shot non-reversible hash function, according to some rules to send the network request to the cluster node, the same source address of the packet sent to the same server. Later on the same request, the same server group, the calculated hash result is the same, so as to achieve the effect of hash distribution.

Choosing different equalization algorithms according to different equilibrium requirements

Of course: for hash hashing algorithms we

Calculate the Idx_key=hash (QUERY_KEY+SERVER_IDX) of all servers, where the Idx_key maximum server_idx is the IDX required.

Assuming the start of 3 backend servers, the request with the flag string req = "ABCD" to flag, the server with S1, S2, S3 to flag, then, by the combination of Req + Sx to calculate the signature can be a value for each server:

(req = "ABCD" + S1) = K1
(req = "ABCD" + S2) = K2
(req = "ABCD" + S3) = K3
The method of calculation can use CRC, you can also use MD5, the purpose of getting a * hash * number, so in K1,K2,K3 must have a maximum value, assuming that K2, then the request req can be thrown to S2, so that later on the same request, the same server group, The calculated result must be K2 maximum, so as to achieve the effect of hash distribution.
The clever place is that when adding or deleting a server, does not cause the cache of the existing server to fail large, assuming that a new server S4, then the S1,S2,S3 calculation of the K values are exactly the same, then the S4 can be calculated to get a new value K4, if the algorithm of K calculation is enough hash, Then the original calculation to S1,S2,S3 request, theoretically there will be 1/4 of the request for the new calculation K4 than the original K, then the 1/4 request will be transferred to S4, so that the new S4 server will bear 1/4 of the request, the original S1,S2,S3 will only bear the original 3/4.

Highest cache Hit rate and minimal server impact due to new and deleted (considering server outages)

Common algorithms for load Balancing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.