Comparison and analysis of lvs, haproxy and nginx load balancing

2013/05/02 21:56
Reading number 1.2K

Comparison and analysis of lvs, haproxy and nginx load balancing
 
D has a detailed look at the software that implements load balancing. LVS is the best in terms of performance and stability. It basically reaches 60% of the performance of F5 hardware devices, and the other 10% are a little difficult.
However, because the LVS is so awesome, the configuration is also the most troublesome. In addition, the health detection needs to be configured with Ldirector. Other HAPROXY and NGINX are used by themselves, and the configuration is super simple.
 
So D suggested that HAPROXY or NGINX should be used if the website traffic is not portal level, and LVS+Idirector should be used at portal level haha
Both lvs and nginx can be used as multi machine load solutions. They have their own advantages and disadvantages. In the production environment, the actual situation needs to be analyzed and utilized.


First of all, we should remind you that technology must not be copied by others. My cloud is your cloud; At the same time, you should not be too conservative, too trusting in the old ways and waiting for others to do the mat test for you. It is a good habit to delve into all the good things you hear immediately, so as to improve your knowledge and level of technology.


The two are analyzed as follows:


1、 Advantages of lvs:


1. The anti load capability is strong, because the logic of the lvs working mode is very simple, and the lvs working on the network layer 4 is only used for request distribution, without traffic, so the efficiency does not need to be considered too much. In my lvs, there was only one problem: the equalizer lost packets in a short period of time with the highest concurrency. According to the analysis, it was a network problem, that is, the carrying capacity of the network card or the linux 2.4 kernel had reached the upper limit, and there was no consumption of memory and cpu.


2. Low configurability is usually a major disadvantage, but it is also a major advantage. Because there are not many configurable options, you do not need to touch it frequently except for adding or removing servers, which greatly reduces the chance of human error.


3. It works stably because of its strong load resistance, so it is reasonable to have high stability. In addition, all kinds of lvs have a complete dual machine hot standby scheme, so there is no need to worry about what will happen to the equalizer itself. If a node fails, lvs will automatically judge, so the whole system is very stable.


4. No traffic, as mentioned above. LVS only distributes requests, and the traffic does not flow out of it. Therefore, it can be used to divert lines. Without traffic, the IO performance of the equalizer will not be affected by large traffic.


5. Basically, it can support all applications. Since LVS works in Layer 4, it can load balance almost all applications, including http, databases, chat rooms, etc.


In addition, lvs is not completely able to identify node failures. For example, under the wlc allocation mode, a node in the cluster is not configured with a VIP, which will make the entire cluster unusable. In this case, using the wrr allocation mode will result in the loss of a machine. At present, this problem is still under further testing. Therefore, it is better to be more careful when using lvs.


2、 Results of comparison between nginx and lvs


1. Nginx works on the 7 layers of the network, so it can make diversion strategies for http applications themselves, such as domain names, directory structures, etc. In contrast, lvs does not have such functions, so Nginx can be used far more often than lvs alone; However, these useful functions of nginx make it more adjustable than lvs, so it is often necessary to touch it. From the second advantage of lvs, more touch will lead to more human problems.


2. Nginx is less dependent on the network. In theory, as long as pinging is available and web page access is normal, nginx can connect. Nginx can also distinguish between internal and external networks. If you have both internal and external network nodes, it is equivalent that a single machine has a backup line; Lvs is more dependent on the network environment. At present, the server is in the same network segment and lvs uses the direct method to shunt. The effect can be better guaranteed. In addition, LVS needs to apply for at least one more IP address from the hosting provider to use as the Visual IP address. It seems that it cannot use its own IP address as the VIP address. To be a good LVS administrator, you really need to follow up and learn a lot about network communication. It is no longer as simple as HTTP.


3. Nginx is easy to install and configure, and easy to test, because it can basically print errors with logs. It will take a long time to install, configure, and test lvs. As mentioned above, lvs relies heavily on the network. In many cases, the failure to configure successfully is due to network problems rather than configuration problems. If problems occur, it will be more troublesome to solve them.


4. Nginx can also withstand a high load and is stable, but there are several levels of poor load and stability lvs: Nginx's handling of all traffic is limited by machine IO and configuration; Its own bugs are also unavoidable; There is no ready dual machine hot standby scheme for nginx, so it is still risky to run on a single machine. It is hard to say everything about a single machine.


5. Nginx can detect the internal faults of the server, such as the status code returned by the server processing the web page, timeout, etc., and will resubmit the returned error request to another node. At present, ldirectd in lvs can also monitor the internal conditions of the server, but the principle of lvs makes it unable to resend requests. For example, if the user is uploading a file, and the node processing the upload happens to fail during the upload process, nginx will switch the upload to another server for reprocessing, and the lvs will be directly disconnected. If it is uploading a large file or an important file, the user may be angry about it.


6. The asynchronous processing of requests by nginx can help the node server reduce the load. If Apache is used for direct external services, the Apache server will occupy a lot of memory and cannot release many narrowband links. If one more nginx is used as the Apache proxy, these narrowband links will be blocked by nginx, There will not be too many requests piled up on Apache, which will reduce the memory consumption considerably. Squid has the same effect. Even if Squid itself is configured not to cache, it is very helpful for Apache. Without these functions, lvs cannot be compared.


7. Nginx can support http and email (email function is estimated to be used by fewer people), and lvs supports more applications than nginx in this regard.


In terms of use, the front end strategy should be LVS, that is, DNS should point to an LVS equalizer. The advantages of LVS make it very suitable for this task.


Important IP addresses, such as database IP and web service server IP, should be hosted by the LVS. These IP addresses will be used more and more frequently over time. If the IP address is replaced, failures will follow. Therefore, it is safest to entrust these important IPs to the lvs. The only disadvantage of this is that there will be a large number of VIPs required.


Nginx can be used as an lvs node machine. First, you can use the functions of nginx. Second, you can use the performance of nginx. Of course, Squid can also be used directly at this level. Squid is much weaker than nginx in terms of function and performance.


Nginx can also be used as a mid-level proxy. At this level, nginx has no rivals. The only thing that can shake nginx is lighttpd. However, lighttpd has not yet achieved full functionality of nginx, and the configuration is not so clear and readable. In addition, the IP address of the middle agent is also important, so the middle agent also has a VIP and lvs, which is the most perfect solution.


Nginx can also be used as a static web server, but it is beyond the scope of this article.


The specific application needs specific analysis. If it is a relatively small website (PV<10 million per day), nginx is all right. If there are many machines, DNS polling can be used. LVS still consumes a lot of machines; For large websites or important services, when the machine is not worried, you should consider using lvs more.
****************************************************************************************************************
Nginx advantages:
Good performance, can load more than 10000 concurrency.
It has many functions. In addition to load balancing, it can also be used as a Web server, and it can achieve traffic distribution through the Geo module.
The community is active, and there are many third-party patches and modules
Support gzip proxy
Disadvantages:
Session retention is not supported.
The health check function of the backend realserver does not work well. It only supports detection through ports, not through urls.
Nginx does not support the big request header very well. If the client_header_buffer_size setting is relatively small, the 400bad request page will be returned.
Advantages of Haproxy:
Its advantages can just complement the disadvantages of nginx. Session retention is supported, and the status of the back-end server can be detected by obtaining the specified url.
Support load balancing in TCP mode. For example, load balancing can be done for MySQL slave server cluster and mail server.
Disadvantages:
Virtual host is not supported (this is silly)
Currently, there is no performance monitoring template for nagios and cacti
Advantages of LVS:
Good performance, close to the network throughput and connection load capacity of hardware devices.
The DR mode of LVS supports load balancing through the WAN. This other load balancing software is not available at present.
Disadvantages:
It is relatively heavy. In addition, the community is not as active as nginx.
*************************************************************************************
There are two kinds of common load balancing in the network: one is through hardware. Common hardware includes more expensive commercial load balancers such as NetScaler, F5, Radware and Array, as well as open-source Linux based load balancing strategies similar to LVS, Nginx and HAproxy,
In commercial load balancing, NetScaler is more efficient than F5. For load balancers, however, commercial load balancers can be built on Layer 4 to Layer 7 protocols, so they are more widely used and irreplaceable. Their advantage is that there is a professional maintenance team to maintain these services. The disadvantage is that it costs too much, so they are not needed for small-scale network services.
Another way of load balancing is through software: LVS, Nginx, HAproxy, etc. are common. LVS is based on the four layer protocol, while Nginx and HAproxy are based on the seven layer protocol
LVS: It uses cluster technology and Linux operating system to realize a high-performance, highly available server with good scalability, reliability and manageability.
LVS features:
1. It has strong load resistance and works on the network layer 4 for distribution only, without traffic generation;
2. Low configurability is a disadvantage as well as an advantage. Because there is not much to configure, it does not require too much contact, which greatly reduces the chance of human error;
3. It works stably and has a complete dual machine hot standby scheme;
4. No traffic, ensuring that the performance of equalizer IO will not be affected by large traffic;
5. It has a wide range of applications and can load balance all applications;
6. LVS needs to apply for an additional IP from IDC to do Visual IP, so it needs some network knowledge, so it has high requirements for operators.
Nginx features:
1. Working on the 7 layers of the network, you can do some diversion strategies for http applications, such as domain names and directory structures;
2. Nginx is less dependent on the network;
3. Nginx is easy to install and configure, and easy to test;
4. It can also bear high load pressure and is stable, and can generally support more than 10000 concurrent operations;
5. Nginx can detect the internal faults of the server through the port, such as the status code and timeout returned by the server when processing the webpage, and will resubmit the request that returns the error to another node. However, it does not support url detection;
6. Nginx's asynchronous processing of requests can help the node server reduce the load;
7. Nginx can support http and email, which is much smaller in the scope of application;
8. The session maintenance is not supported, and the Big Request header is not well supported. In addition, the default load balancing algorithms are Round robin and IP hash.
The features of HAProxy are:
1. HAProxy works on the network layer 7.
2. It can supplement some shortcomings of Nginx, such as session maintenance, cookie guidance, etc
3. It will be very helpful to support the URL detection of the back end server problems.
4. More load balancing strategies, such as Dynamic Round Robin, Weighted Source Hash, Weighted URL Hash and Weighted Parameter Hash, have been implemented
5. In terms of efficiency, HAProxy has a better load balancing speed than Nginx.
6. HAProxy can load balance MySQL and detect and load balance the back-end DB nodes.
***********************************************************************************************
The current trend of website development is to use different technologies according to different stages with the increase of website scale:
The first stage: use Nginx or HAProxy for single point load balancing. In this stage, the server scale has just left the single server and single database mode, which requires a certain load balancing. However, the scale is still small, and there is no professional maintenance team to maintain it, and there is no need for large-scale website deployment. In this way, using Nginx or HAproxy is the first choice. At this time, these things are quick to use and easy to configure. HTTP protocol can be used on the seventh layer. This is the first choice
Phase II: With the further expansion of network services, single point Nginx can no longer meet the requirements. At this time, LVS or commercial F5 is the first choice, Nginx is now used as a node of LVS or F5. The specific selection of LVS or F5 is based on the company's size, talent and financial capacity. This is not discussed in detail here, but generally speaking, relevant talents can not keep up with the improvement of business at this stage, so buying business load balancing has become the only way.
Stage 3: At this time, network services have become the mainstream product. At this time, with the further expansion of the company's popularity, the ability and number of relevant talents have also increased. At this time, no matter in terms of developing customized products suitable for their own products and reducing costs, open source LVS has become the first choice. At this time, LVS will become the mainstream.
Finally, the ideal state is F5/LVS<->Haproxy<->Squid/Varnish<->AppServer.

Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
six Collection
zero fabulous
 Back to top
Top