Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Comparison of three load balancing methods in LVS

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "the comparison of three load balancing methods of LVS". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. What is LVS?

First of all, let's briefly introduce what LVS (Linux Virtual Server) is. In fact, it is a Cluster technology, using IP load balancing technology and content-based request distribution technology. The scheduler has a good throughput, it transfers requests to different servers evenly, and the scheduler automatically shields the failure of the server, thus forming a group of servers into a high-performance and highly available virtual server. The structure of the whole server cluster is transparent to customers, and there is no need to modify client-side and server-side programs.

For this reason, the transparency, scalability, high availability and manageability of the system need to be considered in the design. Generally speaking, the LVS cluster has a three-tier structure, and its architecture is shown in the figure:

Architecture of LVS Cluster

2. The main components of LVS are:

The load scheduler (load balancer/ Director), which is the front-end machine outside the entire cluster, is responsible for sending the customer's request to a set of servers for execution, and the customer thinks the service comes from an IP address (we can call it a virtual IP address).

Server pool (server pool/ Realserver) is a group of servers that actually execute customer requests. The services performed are generally WEB, MAIL, FTP, DNS, and so on.

Shared storage (shared storage), which provides a shared storage area for the server pool, which makes it easy for the server pool to have the same content and provide the same services.

3. LVS load balancing method:

◆ Virtual Server via Network Address Translation NAT (VS/NAT)

VS/NAT is the easiest way, and all RealServer need to point their own gateway to Director. The client can be any operating system, but in this way, the amount of RealServer that a Director can drive is limited. In the VS/NAT way, the Director can also be used as a RealServer. The architecture of VS/NAT is shown in the figure.

The architecture of VS/NAT

◆ Virtual Server via IP Tunneling (VS/TUN)

IP tunneling (IP tunneling) is a technology that encapsulates one IP message in another IP message, which enables data packets destined for one IP address to be encapsulated and forwarded to another IP address. IP tunneling technology is also known as IP encapsulation technology (IP encapsulation). IP tunnels are mainly used for mobile hosts and virtual private networks (Virtual Private Network), where tunnels are statically established. There is an IP address at one end of the tunnel and a unique IP address at the other end.

Its connection scheduling and management are the same as those in VS/NAT, except that its packet forwarding method is different. According to the load of each server, the scheduler dynamically selects a server, encapsulates the request message in another IP message, and then forwards the encapsulated IP message to the selected server. After receiving the message, the server first unencapsulates the message with the original destination address of VIP. The server finds that the VIP address is configured on the local IP tunnel device, so it processes the request, and then returns the response message directly to the customer according to the routing table.

The architecture of VS/TUN

The workflow of VS/TUN:

◆ Virtual Server via Direct Routing (VS/DR)

The VS/DR method is realized by rewriting the MAC address part of the request message. Director and RealServer must physically have a network card connected through an uninterrupted local area network. The VIP bound to the RealServer is configured on the network device of the respective Non-ARP, such as lo or tunl, and the VIP address of the Director is visible to the outside, while the VIP of the RealServer is not visible to the outside. The address of a RealServer can be either an internal address or a real address.

The architecture of VS/DR

The workflow of VS/DR:

The workflow of VS/DR is shown in the figure: its connection scheduling and management are the same as those in VS/NAT and VS/TUN, and its message forwarding method is different, routing the message directly to the target server. In VS/DR, the scheduler dynamically selects a server according to the load of each server, neither modifies nor encapsulates the IP message, but changes the MAC address of the data frame to the MAC address of the selected server, and then sends the modified data frame on the local area network with the server group. Because the MAC address of the data frame is the selected server, the server is sure to receive the data frame from which the IP message can be obtained. When the server discovers that the destination address VIP of the message is on the local network device, the server processes the message and then returns the response message directly to the customer according to the routing table.

4. Comparison of three load balancing methods:

◆ Virtual Server via NAT

The advantage of VS/NAT is that the server can run any operating system that supports TCP/IP, it only needs an IP address configured on the scheduler, and the server group can use a private IP address. The disadvantage is that its scalability is limited, when the number of server nodes rises to 20:00, the scheduler itself may become a new bottleneck of the system, because in VS/NAT request and response messages need to go through the load scheduler. The average delay of rewriting packets measured on the host of the Pentium166 processor is 60us, and the delay is shorter on the processors with higher performance. Assuming that the average length of TCP packets is 536 Bytes, the maximum throughput of the scheduler is 8.93 MBytes/s. Let's assume that the throughput of each server is 800KBytes/s, and such a scheduler can drive 10 servers. (note: this is the data measured a long time ago)

The cluster system based on VS/NAT can meet the performance requirements of many servers. If the load scheduler becomes a new bottleneck in the system, there are three ways to solve this problem: hybrid approach, VS/TUN, and VS/DR. In the DNS hybrid cluster system, there are several VS/NAT negative schedulers, each with its own server cluster, and these load schedulers form a simple domain name through RR-DNS.

But VS/TUN and VS/DR are better ways to improve system throughput.

For those network services that transmit the IP address or port number in the message data, it is necessary to write the corresponding application module to convert the IP address or port number in the message data. This will bring the workload of implementation, and the overhead of the application module checking packets will reduce the throughput of the system.

◆ Virtual Server via IP Tunneling

In the cluster system of VS/TUN, the load scheduler only dispatches the request to different back-end servers, and the back-end server returns the answered data directly to the user. In this way, the load scheduler can handle a large number of requests, it can even schedule more than 100 servers (servers of the same size), and it will not become the bottleneck of the system. Even if the load scheduler has only the full-duplex network card of 100Mbps, the maximum throughput of the whole system can exceed 1Gbps. Therefore, VS/TUN can greatly increase the number of servers scheduled by the load scheduler. VS/TUN scheduler can schedule hundreds of servers, but it itself will not become the bottleneck of the system, and can be used to build high-performance super servers. VS/TUN technology requires that all servers support the "IP Tunneling" or "IP Encapsulation" protocols. Currently, VS/TUN 's back-end servers mainly run the Linux operating system, and we have not tested other operating systems. Because "IP Tunneling" is becoming the standard protocol for each operating system, VS/TUN should be suitable for back-end servers running other operating systems.

◆ Virtual Server via Direct Routing

Like the VS/TUN method, the VS/DR scheduler only handles client-to-server connections, and response data can be returned directly from a separate network route to the client. This can greatly improve the scalability of the LVS cluster system. Compared with VS/TUN, this method does not have the cost of IP tunnel, but requires that the load scheduler and the actual server have a network card connected to the same physical network segment, the server network device (or device alias) does not respond to ARP, or can redirect the message to the local Socket port.

The advantages and disadvantages of the three LVS load balancing technologies are summarized as follows:

Image.png

Note: the estimation of the maximum number of servers that the above three methods can support is based on the assumption that the scheduler uses a 100m network card, the hardware configuration of the scheduler is the same as that of the back-end server, and it is for general Web services. With higher hardware configurations (such as gigabit network cards and faster processors) as the scheduler, the number of servers that the scheduler can schedule increases accordingly. When the application is different, the number of servers will change accordingly. Therefore, the above data estimates are mainly for the quantitative comparison of the scalability of the three methods.

5. Lvs load scheduling algorithm in the kernel connection scheduling algorithm, IPVS has implemented the following eight scheduling algorithms:

◆ round-robin scheduling (Round ­Robin Schedul ing)

Round robin scheduling (Round Robin Scheduling) algorithm is to schedule requests to different servers in turn, that is, each scheduling executes I = (item1) mod n, and selects the first server. The advantage of the algorithm is its simplicity, it does not need to record the status of all current connections, so it is a stateless scheduling.

◆ two-weighted round robin scheduling (Weighted Round ­Robin Scheduling)

The weighted round robin scheduling (Weighted Round ­Robin Scheduling) algorithm can solve the situation of different performance between servers. It uses the corresponding weight to represent the processing performance of the server, and the default weight of the server is 1. Assuming that the weight of server An is 1 and the weight of B is 2, it means that the processing performance of server B is twice that of A.

The weighted round-robin scheduling algorithm allocates requests to each server according to the weight and the rotation mode. The server with high weight receives the connection first, the server with high weight handles more connections than the server with low weight, and the server with the same weight handles the same number of connections.

◆ three minimum connection scheduling (Least ­Connect ion Schedul ing)

The minimum connection scheduling (Least ­Connect ion Scheduling) algorithm assigns new connection requests to the server with the smallest number of connections currently. Minimum connection scheduling is a dynamic scheduling algorithm, which estimates the load of the server by the number of active connections. The scheduler needs to record the number of connections established by each server. When a request is dispatched to a server, the number of connections is increased by 1; when the connection is aborted or timed out, the number of connections is reduced by one.

◆ four-weighted minimum connection scheduling (Weighted Least ­Connectio n Scheduling)

The weighted minimum connection tuning (Weighted Least ­Connectio n Scheduling) algorithm is a superset of minimum connection scheduling, and each server uses the corresponding weights to represent its processing performance. The default weight of the server is 1, and the system administrator can set the weight of the server dynamically. Weighted minimum connection scheduling makes the number of established connections of the server proportional to its weight as much as possible when scheduling new connections.

◆ 5 minimum links based on locality (Locality ­Based Least Connections Schedulin g)

Locality-based minimum link scheduling (Locality ­Based Least Connections Scheduling, hereinafter referred to as LBLC) algorithm is a load balancing scheduling for the target IP address of the request message. At present, it is mainly used in the Cache cluster system, because the target IP address of the customer request message is changed in the Cache cluster. It is assumed that any back-end server can handle any request. The design goal of the algorithm is to schedule requests from the same destination IP address to the same server under the condition that the load of the server is basically balanced, so as to improve the access locality and main memory Cache hit rate of each server, thus the processing capacity of the whole cluster system.

The LBLC scheduling algorithm first finds out the server closest to the target IP address according to the target IP address of the request, and sends the request to the server if the server is available and not overloaded; if the server does not exist, or if the server is overloaded and has half of its working load, then use the principle of "least links" to select an available server and send the request to the server.

Locality-based minimum links for ◆ six-band replication (Locality ­Based Least Connectio ns with Replication Scheduling)

Locality ­Based Least Connectio ns with Replication Scheduling (hereinafter referred to as LBLCR) algorithm with replication is also a load balancing algorithm for target IP addresses, which is mainly used in Cache cluster systems.

It differs from the LBLC algorithm in that it maintains a mapping from a destination IP address to a set of servers, while the LBLC algorithm maintains a mapping from a destination IP address to a server. For service requests from a "hot" site, a Cache server may be too busy to process these requests. At this time, the LBLC scheduling algorithm will select a Cache server from all Cache servers according to the "minimum connection" principle, map the "hot" site to the Cache server, and soon the Cache server will be overloaded, and the above process will be repeated to select a new Cache server.

This may cause the image of the "hot" site to appear on all Cache servers, reducing the efficiency of the Cache server. The LBLCR scheduling algorithm maps the "gate station" point to a set of Cache servers (server collection). When the request load of the "hot" site increases, the Cache server in the collection will be increased to handle the growing load; when the request load of the "hot" site decreases, the number of Cache servers in the collection will be reduced. In this way, the image of the popular site cannot appear on all Cache servers, thus providing the efficiency of the Cache cluster system.

The LBLCR algorithm first finds the server group corresponding to the target IP address according to the requested target IP address; selects a server from the server group according to the "minimum connection" principle, and sends the request to the server if the server is not overloaded; if the server is overloaded, it selects a server from the whole cluster according to the "minimum connection" principle, joins the server group, and sends the request to the server. At the same time, when the server group has not been modified for some time, the busiest server is removed from the server group to reduce the degree of replication.

◆ Seven destination address Hash scheduling (Destinat ion Hashing Scheduling)

The destination address hash scheduling (Destinat ion Hashing Scheduling) algorithm is also a load balancing for target IP addresses, but it is a static mapping algorithm that maps a target IP address to a server through a Hash function. The target address hash scheduling algorithm first finds the corresponding server from the statically assigned hash table as a hash key (Hash Key) according to the requested target IP address, and sends the request to the server if the server is available and not overloaded, otherwise it returns empty.

◆ eight source address hash scheduling (Source Hashing Scheduling)

The source address hash scheduling (Source Hashing Scheduling) algorithm is just the opposite of the destination address hash scheduling algorithm. According to the requested source IP address, it acts as a hash key (Hash Key) to find the corresponding server from the statically assigned hash table. If the server is available and not overloaded, the request is sent to the server, otherwise it returns empty. It uses the same hash function as the target address hash scheduling algorithm. Its algorithm flow is basically similar to that of the destination address hash scheduling algorithm, except that the requested destination IP address is replaced with the requested source IP address, so it is not described here. In practical application, source address hash scheduling and destination address hash scheduling can be used together in the firewall cluster, and they can ensure the only entrance and exit of the whole system.

This is the end of the content of "comparison of three load balancing methods of LVS". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report