Analysis of 6 kinds of load balancing algorithms, Ngnix 5 kinds of algorithms.

Source: Internet
Author: User

Analysis of 6 kinds of load balancing algorithms, Ngnix 5 kinds of algorithms.
?
Floating Snatch
Hundred 03-21 10:06
Concern
Content Guide
Its actual effect is getting closer to the average allocation of calls to each server on the backend, which is the result of polling. The idea of the source address hash is to obtain the client's IP address, through the hash function to calculate a value, with this value to the size of the server list to take a modulo operation, the result is the customer service side to access the server serial number. The client with the same IP address, which is load balanced with the source address hash, maps to the same back-end server for access every time when the back-end server list is not changed. Different back-end servers may not have the same machine configuration and current system load, so they have varying compression capabilities. Specifies the polling probability, proportional to the weight and access ratios, for situations where the performance of the backend server is uneven. 3.max_fails: The number of times that a request failed is allowed defaults to 1. When the maximum number of times is exceeded, returns the time that the Proxy_next_upstream module defines the error 4.fail_timeout:max_fails after the failure.

?
Several common load-balancing algorithms
1. Polling method
The request is distributed sequentially to the back-end server, which treats each server on the backend in a balanced manner, regardless of the actual number of connections and current system load on the server.
2. Stochastic method
The random algorithm of the system, according to the list size value of the back-end server to randomly select one of the servers to access. The probability statistic theory can be used to know that as the number of clients invoking the server increases,
Its actual effect is getting closer to the average allocation of calls to each server on the backend, which is the result of polling.
3. Source Address Hash method
The idea of the source address hash is to obtain the client's IP address, through the hash function to calculate a value, with this value to the size of the server list to take a modulo operation, the result is the customer service side to access the server serial number. The client with the same IP address, which is load balanced with the source address hash, maps to the same back-end server for access every time when the back-end server list is not changed.
4. Weighted round-robin method
Different back-end servers may not have the same machine configuration and current system load, so they have varying compression capabilities. Configure a high, low-load machine with higher weights to handle more requests, and configure low, high-load machines, assign them lower weights, lower their system load, and weighted polling handles the problem well and assigns the order of requests to the backend by weight.
5. Weighted Stochastic method
As with the weighted polling method, the weighted stochastic method is also based on the configuration of the backend machine, and the load of the system is assigned different weights. The difference is that it is randomly requested by weight on the backend server, rather than in order.
6. Minimum connection number method
The minimum number of connections algorithm is more flexible and intelligent, because the configuration of the backend server is not the same, the processing of the request is fast and slow, it is based on the current connection of the backend server, dynamically select the current
A server that has the fewest backlog of connections to handle current requests and, as much as possible, improves the efficiency of back-end services and is responsible for properly diverting to each server.
5 Kinds of load balancing algorithms for Nginx
1. Polling (default)
Each request is assigned to a different back-end server in chronological order, and can be automatically rejected if the backend server is down.
2, Weight
Specifies the polling probability, proportional to the weight and access ratios, for situations where the performance of the backend server is uneven.
For example:
Upstream Bakend {server 192.168.0.14 weight=10; server 192.168.0.15 weight=10;}
3, Ip_hash
Each request is allocated according to the hash result of the access IP, so that each visitor has fixed access to a back-end server that resolves the session issue.
For example:
Upstream Bakend {ip_hash; server 192.168.0.14:88; server 192.168.0.15:80;}
4. Fair (third party)
The response time of the back-end server is allocated to the request, and the response time is short of priority allocation.
Upstream backend {server server1; server server2; fair;}
5. Url_hash (Third Party)
Assign requests by the hash result of the access URL so that each URL is directed to the same back-end server, which is more efficient when the backend server is cached.
Example: Add a hash statement in upstream, the server statement can not write weight and other parameters, Hash_method is the use of the hash algorithm.
Upstream backend {server squid1:3128; server squid2:3128; hash $request _uri; Hash_method Crc32;}
Tips
Upstream bakend{#定义负载均衡设备的Ip及设备状态 ip_hash; server 127.0.0.1:9090 down; server 127.0.0.1:8080 weight=2; server 127.0.0.1:6060; Server 127.0.0.1:7070 backup; }
In servers that need to use load balancing, add
Proxy_pass http://bakend/;
The status of each device is set to:
1.down indicates that the server is temporarily not participating in the load
2.weight by default, the larger the 1.weight, the greater the load weight.
3.max_fails: The number of times that a request failed is allowed defaults to 1. Returns the error defined by the Proxy_next_upstream module when the maximum number of times is exceeded
4.fail_timeout:max_fails the time of the pause after the failure.
5.backup: When all other non-backup machines are down or busy, request the backup machine. So the pressure on this machine is the lightest.
Nginx supports multiple sets of load balancing at the same time, which is used for unused servers.
Client_body_in_file_only: Set to ON, you can speak the client post data logged to the file to do Debug.
Client_body_temp_path: Set the directory for the log files, you can set up to 3 levels of directories.
Location: Match URLs to redirect or new proxies, load balancer

Analysis of 6 kinds of load balancing algorithms, Ngnix 5 kinds of algorithms.

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.