Ten LVS cluster scheduling algorithms and load balancing theory, lvs Load Balancing

Source: Internet
Author: User

Ten LVS cluster scheduling algorithms and load balancing theory, lvs Load Balancing

I. Concept of LVS

  • LVS (Linux Virtual Server): Linux Virtual Server;
  • LVS is a server Load balancer device that does not provide any services. When a user requests a Server Load balancer, LVS forwards the customer's requirements to the backend to provide services, therefore, backend services are called real servers;
  • LVS is divided into two sections. The previous section is called ipvsadm (a command line tool for managing cluster services) and the later section is called ipvs (kernel module );
  • [Note] LVS and iptables cannot be used at the same time;

Ii. LVS type

  • LB (Load Balancing): Load Balancing Cluster
    Feature: To increase capability
  • HA (High Availability): High-Availability cluster
    Feature: Provides service availability (up to 99.999% online in a year)
    Calculation method: online time/(online time/troubleshooting time)
  • HP ([HPC] High Performance): High-Performance cluster
    Feature: Provides service performance

Iii. LVS composition structure (Load Balancing implementation solution)

  • DNS domain name rotation Resolution Method
  • Client-based access Scheduling Method
  • Scheduling Method Based on application layer system load
  • IP address-Based Scheduling Method
    Among the IP-based load scheduling algorithms, IP Server Load balancer is the most efficient.

Iv. Ten LVS Scheduling Algorithms

1. static scheduling:

① Rr (Round Robin): Round Robin scheduling, called Scheduling
The principle of the round robin scheduling algorithm is to allocate user requests to internal servers in turn each time, starting from 1 until N (number of internal servers), and then re-start the loop. The advantage of the algorithm is its conciseness. It does not need to record the status of all current connections, so it is a stateless scheduling.
[Note: The processing capability of each server is not considered here]

② Wrr: weight, weighted (scheduling between hosts based on the ratio of weights)
The processing capability varies depending on the configuration and installed business applications of each server. Therefore, we assign different weights to each server based on different processing capabilities of the server so that it can accept service requests with corresponding weights.

③ Sh: source hashing, source address hash
This mainly enables session binding and retains the previously created session information.
The source address Hash scheduling algorithm is opposite to the target address Hash scheduling algorithm. It serves as the Hash Key based on the source IP address of the request) find the corresponding server from the static allocation hash. If the server is available and is not overloaded, send the request to the server; otherwise, return null. It uses the same hash function as the target address hash scheduling algorithm. Its algorithm flow is basically similar to the target address hash scheduling algorithm. In addition to switching the target IP address of the request to the source IP address of the request, it is not described here.

④ Dh: Destination hashing: Destination Address hash
Send requests from the same IP address to the same server.
The target address Hash scheduling algorithm is also a load balancing algorithm for the target IP address. It is a static ing algorithm that uses a Hash function to map a target IP address to a server. The target address Hash scheduling algorithm first uses the target IP address of the request as the Hash Key to find the corresponding server from the static allocation Hash list, if the server is available and is not overloaded, send the request to the server. Otherwise, null is returned.

2. Dynamic Scheduling

① Lc (Least-Connection): minimum Connection
The least connection scheduling algorithm allocates new connection requests to servers with the least number of connections currently. The minimum connection scheduling algorithm is a short dynamic scheduling algorithm, it estimates the Server Load balancer by the number of active connections on the server. The scheduler needs to record the number of established connections on each server. When a request is scheduled to a server, the number of connections increases by 1. When the connection is terminated or times out, the number of connections is reduced by one. In system implementation, when the server's weight is 0, indicates that the server is unavailable and not scheduled.
Simple Algorithm: active X 256 + inactive (who is small, who is chosen)

② Wlc (Weighted Least-Connection Scheduling): Weighted Least join
The weighted least-connection scheduling algorithm is a superset of least-connection scheduling. Each server uses the corresponding weights to indicate its processing performance. The default server weight is 1, and the system administrator can dynamically set server permissions. The weighted least connection scheduling tries its best to make the number of established connections of the server proportional to its weight when scheduling new connections.
Simple Algorithm: (active * 256 + inactive)/weight [(active connections + 1)/divided by weight] (who is small, who is chosen)

③ Sed (Shortest Expected Delay): Minimum Expected latency
Wlc-based algorithms
Simple Algorithm: (active + 1) * 256/weight [(active connections + 1) * 256/divided by weight]

④ Nq (never queue): never queues (improved sed)
No queue is required. If the number of connections of a realserver is equal to 0, it is directly allocated. sed is not required.

⑤ LBLC (Locality-Based Least Connection): local-Based Least join
The locality-based least connection algorithm is used for load balancing and scheduling of the target IP address of the Request Message. It is not used in the Cache cluster system because the IP address of the customer request packet in the Cache cluster is changed, if any backend server can process any request, the algorithm is designed to schedule requests with the same target IP address to the same server when the server load is basically balanced, to improve the access locality and master memory Cache hit rate of a server, so as to adjust the processing capability of the entire cluster system.
Based on the local least connection scheduling algorithm, find the RealServer recently used by the target IP address of the request. If the Real Server is available and is not overloaded, send the request to the Server; if the server does not exist, or the server is overloaded and has half of the workload, use the "minimum link" principle to select an available server and send the request to the server.

⑥ LBLCR (Locality-Based Least Connections withReplication): local Least link with replication
The local least link-Based Scheduling Algorithm with replication is also a load balancing algorithm for the target IP address. The algorithm finds the server group corresponding to the target IP address based on the request's target IP address, select a server from the server group based on the "minimum connection" principle. If the server is not overloaded, send the request to the server. If the server is overloaded, select a server from the cluster according to the "minimum connection" principle, add the server to the server group, and send requests to the server. At the same time, when the server group has not been modified for a period of time, delete the busiest server from the server group to reduce the degree of replication.

V. How to Implement load balancing in IPVS

NAT: address translation (similar to DNAT)
1. The cluster point and director must work in the same IP address network.
2. RIP is usually a private address and is only used for communication between nodes in each cluster.
3. Ctor is located between the client and the real server and is responsible for handling all inbound and outbound channels.
4. The realserver must run the DIP command on the gateway.
5. director supports port ing.
6. realserver can use any operating system (OS)
7. In large-scale application scenarios, director is easy to become a system bottleneck.

DR: Direct routing (and used as the source address)
1. Each cluster node and director must be in the same physical network;
2. RIP can use public addresses for portable remote management and monitoring;
3. director is only responsible for processing inbound requests, while the shadow packets are directly sent to the client by the realserver.
4. The realserver cannot direct the gateway to the DIP, but directly to the front-end gateway;
5. director does not support port ing.
6. Most operating systems can be used in realserver

TUN: Tunnel
1. cluster nodes can span the Internet
2. RIP must be a public IP address.
3. director is only responsible for processing inbound requests, while the shadow packets are directly sent to the client by the realserver.
4. The realserver gateway cannot point to director
5. Only OS with the short-lived tunnel function can be used for realserver.
6. Port ing is not supported.

Vi. Frequently Used ipvsadm commands

1. Manage cluster services

Add:-A-t | u | f service-address [-sscheduler]-t: tcp cluster service-u: udp cluster-f: FWM firewall tag modification: -E Delete:-D-t | u | f service-address

For example:# ipvsadm -A -t 172.16.100.1:80 -s rr

2. Manage RS in cluster services

Add:-a -t|u|f service-address -rserver-address [-g|i|m] *[-w weight]*

-T | u | f service-address: a pre-defined Cluster service
-R server-address: RS address. You can use port ing in the NAT model.
[-G | I | m]LVS type
-G: DR
-I: TUN
-M: NAT
[-W weight]Define server weight

3. Modify:-e
4. Delete:-d -t|u|f service-address -r server-address

Example: # ipvsadm-a-t 172.16.100.1: 80-r 192.168.10.8-m example: # ipvsadm-a-t 172.16.100.1: 80-r 192.168.10.9-m

5. View

-L | l [options]-n: Host address and port number displayed in digital format -- stats: Statistical Information -- rate: rate -- timeout: display the timeout value of tcp, tcpfin, and udp sessions -- daemon -- sort: sort with the Protocol, address, and port. The default value is ascending-c: display the current ipvs connection status

6. Delete all cluster services:

-C: Clear ipvs rules

7. Save rules

-S: (save with output redirection) Format: '# using SADM-s>/path/to/somefile'

8. Load previous rules:

-R format: '# ipvsadm-R </path/to/somefile'

View Original

Original works can be reproduced. During reprinting, you must mark the original source, author information, and this statement in hyperlink form. Otherwise, you will be held legally responsible.

Hot recommendations

  • LNMP environment setup-Nginx

  • Configure the local YUM source in RHEL6.5

  • Installing and using Zabbix in Ubuntu

  • Troubleshooting of MySQL dual-master hot standby

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.