Features and Comparisons of Software-Level Load Balancers (LVS/HAProxy/Nginx)

The trend of website development now uses network load balancing to use different technologies according to different stages as the scale of the website increases:

One is through hardware. Common hardware includes more expensive commercial load balancers such as NetScaler, F5, Radware, and Array. Its advantage is that there is a professional maintenance team to maintain these services. The disadvantage is the cost It is too large, so it is not needed for small-scale network services; the other is a Linux-based open source free load balancing software strategy similar to LVS/HAProxy and Nginx, which are all implemented at the software level. , so the cost is very low, so I also recommend that you use the second scheme to implement the load balancing requirements of your own website.

Recently, the project of my friend Liu Xin (Purple Rain and Hexue) has been successfully launched, and the PV has reached 100 million/day traffic. The front end uses a load balancer/reverse proxy with HAProxy+Keepalived dual-machine. The entire website is very Stability; this makes me more firm about the reasonable design of the website architecture that I talked to the old boys before: that is, Nginx/HAProxy+Keepalived is the front-end load balancer of the Web, and the MySQL database architecture of the back-end adopts one master and multiple slaves. , The read-write separation method adopts the LVS+Keepalived method .

Here I also have one point to make clear to you: Many friends are worried about the stability of software-level load balancing under the impact of high concurrent traffic. The fact is that we have found through many successful websites that their stability is also very good. There is very little possibility of the machine, so the project I am doing now basically does not consider the high availability of the service level. I believe that everyone has a deep understanding of these software-level load balancing software. I will explain their characteristics and applicable occasions below.

LVS: Using cluster technology and Linux operating system to achieve a high-performance, high-availability server, it has good scalability (Scalability), reliability (Reliability) and manageability (Manageability), thanks to Dr. Zhang Wensong for providing us with Such a powerful and useful open source software.

 

The characteristics of LVS are:

1. It has strong anti-load capability and works on the 4th layer of the network only for distribution purposes, without generating traffic. This feature also determines that it has the strongest performance in load balancing software;

2. The configuration is relatively low, which is a disadvantage and an advantage. Because there is not much configuration, it does not require too much contact, which greatly reduces the probability of human error;

3. The work is stable, and it has a complete dual-system hot backup solution, such as LVS+Keepalived and LVS+Heartbeat, but we use LVS/DR+Keepalived the most in project implementation;

4. No traffic, which ensures that the performance of the equalizer IO will not be affected by large traffic;

5. It has a wide range of applications and can do load balancing for all applications;

6. The software itself does not support regular processing and cannot do dynamic and static separation, which is a pity; in fact, many websites now have strong demands in this regard, which is the advantage of Nginx/HAProxy+Keepalived.

7. If the website application is relatively large, it will be more complicated to implement LVS/DR+Keepalived, especially if there is a machine with Windows Server application behind, if the implementation and configuration and maintenance process are more complicated, relatively speaking, Nginx /HAProxy+Keepalived is much simpler.

 

The features of Nginx are:

1. Working on the 7th layer of the network, it can do some diversion strategies for http applications, such as domain name and directory structure, its regular rules are more powerful and flexible than HAProxy, which is one of the reasons why many friends like it ;

2. Nginx has very little dependence on the network. In theory, it can perform the load function if it can be pinged. This is also its advantage;

3. Nginx installation and configuration are relatively simple, and it is more convenient to test;

4. It can also bear high load pressure and is stable, and generally can support more than tens of thousands of concurrency;

5. Nginx can detect the internal failure of the server through the port, such as the status code returned by the server processing the webpage, timeout, etc., and will resubmit the request that returns the error to another node, but the disadvantage is that it does not support url to detect ;

6. Nginx can only support http and Email, so the scope of application is much smaller, which is its weakness;

7. Nginx is not only an excellent load balancer/reverse proxy software, it is also a powerful web application server. LNMP is also a very popular web architecture now, and it has the potential to compete with the most popular LAMP architecture before, and it also has good results in high-traffic environments.

8. Nginx is now becoming more and more mature as a Web reverse acceleration cache. Many friends have already put it into production in the production environment, and the response is good. The speed is faster than the traditional Squid server. Interested friends can consider using it Act as a reverse proxy accelerator.

 

The features of HAProxy are:

1. HAProxy supports virtual hosts. Some friends said that this does not support virtual hosts. I hereby correct it.

2. It can supplement some of the shortcomings of Nginx, such as Session maintenance, Cookie guidance, etc.

3. The detection of problems with the server that supports the url detection backend will be very helpful.

4. Like LVS, it is just a load balancing software; purely in terms of efficiency, HAProxy will have better load balancing speed than Nginx, and it is also better than Nginx in concurrent processing.

5. HAProxy can load balance Mysql reads, detect and load balance MySQL nodes in the backend, but when the number of MySQL slaves in the backend exceeds 10, the performance is not as good as LVS, so I recommend LVS+Keepalived to everyone.

6. There are more and more algorithms of HAProxy, including the following 8 kinds:

①roundrobin, which means simple polling, this is not much to say, this is basically what load balancing has;

②static-rr, indicating that according to the weight, it is recommended to pay attention;

③leastconn, indicating that the least connected ones are processed first, it is recommended to pay attention;

④ource, which means that according to the request source IP, this is similar to the IP_hash mechanism of Nginx, we use it as a method to solve the session problem, it is recommended to pay attention;

⑤ri, indicating the URI according to the request;

⑥rl_param, indicating that according to the requested URl parameter 'balance url_param' requires an URL parameter name;

⑦hdr(name), which means to lock each HTTP request according to the HTTP request header;

⑧rdp-cookie(name), which means to lock and hash each TCP request according to cookie(name).

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326958537&siteId=291194637