Comparison and analysis of load balance between LVS, Haproxy and Nginx

Source: Internet
Author: User
Tags hosting node server haproxy netscaler

Software to achieve load balance of several software, small d look at a bit, from the performance and stability of the most bull, basically reached the F5 hardware equipment 60% performance, a few other 10% are a bit difficult.

But because of the LVS bull, configuration is the most troublesome, and health testing needs to be configured Ldirector, other haproxy and nginx themselves, and the configuration super simple.

So small d suggested that if the site visits are not portal level with haproxy or nginx OK, to the portal level in the use of Lvs+idirector bar haha

LVS and Nginx can be used as a multi-machine load scheme, each with excellent shortage, in the production environment need to analyze the actual situation and use.

First of all remind, do technology must not conform to, I cloud is you cloud, at the same time also not too tend to conservative, too believe the old has the way and wait others to help you to do mat is tested. It is a good habit to delve into all the good things that are immediately heard and to improve your knowledge and level of technology.

Here's a look at both of them:

First, the advantages of LVS:

1, strong anti-load ability, because the LVS work mode logic is very simple, and work in the Network 4 layer only to do the request for distribution, no traffic, so in the efficiency of the basic need not too much consideration. In my hand, the LVS, just once the problem: in the concurrency of the highest period of time the equalizer packet loss, according to the analysis of network problems, that is, Nic or linux2.4 core load capacity has reached the upper limit, memory andCPThe u aspect is basically no consumption.

2, low-profile, which is usually a major disadvantage, but also a big advantage, because there is not too many configurable options, so in addition to increase or decrease the server, do not need to touch it frequently, greatly reducing the chance of human error.

3, the work is stable, because of its own resistance to load capacity is very strong, so the stability is also natural, and a variety of LVS have a complete dual-machine hot-standby scheme, so a little do not worry about the equalizer itself will be what problems, node failure, LVS will automatically distinguish, so the overall system is very stable.

4, no flow, the above has been mentioned. LVS simply distributes the request, and the traffic does not go out of it itself, so it can be used to do some line diversion. Without traffic, the IO performance of the Equalizer will not be affected by large traffic.

5, basically can support all applications, because LVS work in the 4 layer, so it can load balance almost all applications, including HTTP, database, chat room and so on.

Another: LVS is not fully able to identify node failures, for example, in the WLC allocation mode,ClusterThere is a node not configured VIP, will make the whole cluster can not be used, when using WRR allocation method will lose a machine. The problem is still being tested further. Therefore, the use of LVS also have to be more careful to be wonderful.

Second, the results of the comparison between Nginx and LVs

1, Nginx work in the Network 7 layer, so it can be targeted at the HTTP application itself to do the shunt strategy, for example, for the domain name, directory structure, in contrast, LVS does not have such a function, so the nginx alone can use the occasion far more than LVS But Nginx useful these functions make its adjustable degree is higher than LVS, so often to touch touch, from the 2nd advantage of LVs See, touch more, the probability of human problems will be big.

2, Nginx dependence on the network is small, theoretically as long asPingGet through, the Web Access is normal, nginx can be connected, nginx at the same time can also distinguish between internal and external network, if it is both inside and outside the network node, the equivalent of a single machine has a backup line; LVs is more dependent on the network environment, the server is in the same network segment and LVS using direct mode shunt, The results are more assured. Also note that LVS needs to apply at least one more IP to the custodian to do VIsuAl IP, it seems to be unable to use their own IP to do the VIP. To do a good job of the LVS administrator, do have to follow up learning a lot about network communication knowledge, it is no longer an HTTP so simple.

3, Nginx installation and configuration is relatively simple, testing is also very convenient, because it is basically able to print out the error log. LVS installation and configuration, testing will take a long time, because, as mentioned above, LVS depends on the network is relatively large, many times can not be configured to succeed because of network problems rather than configuration problems, out of the problem to solve also the corresponding will be more troublesome.

4, Nginx can also withstand a very high load and stability, but the load and stability of the LVS there are several levels: Nginx processing all traffic is limited to the machine IO and configuration, its own bugs are still unavoidable; Nginx does not have ready-made dual-machine hot standby scheme, so running on a single computer or a large risk, Everything on a single machine is hard to say.

5, Nginx can detect the internal failure of the server, such as the server to handle the return of the page status code, timeout and so on, and will return the wrong request resubmitted to another node. At present, LDIRECTD in LVS can also support monitoring the internal conditions of the server, but the principle of LVS makes it impossible to re-send requests. Resend the request this, for example, the user is uploading a file, and processing the upload node just in the upload process failure, Nginx will upload to another server to re-processing, and LVS directly broken off, if it is to upload a large file or very important files, users may be annoyed.

6, Nginx to the request of asynchronous processing can help the node server to reduce the load, if using Apache Direct service, then there are a lot of narrow-band link when the Apache server will occupy a lot of memory and can not be released, using more than one nginx to do Apache agent, These narrow-band links will be blocked by Nginx, Apache will not accumulate too many requests, which reduces the amount of memory consumption. This uses squIDAlso has the same effect, even if the squid itself is configured to not cache, the Apache still has a great help. LVS does not have these features and cannot be compared.

7, Nginx can support HTTP and email (the function of email is estimated to be less used), the application supported by LVS will be more than Nginx.

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

Important IP address, preferably by the LVS hosting, such as the database IP, WebService server IP and so on, these IP addresses over time, the use of polygons will become larger, if the replacement of IP will follow. So it is most prudent to give these important IPs to the LVS hosting, the only disadvantage is that the number of VIPs will be more.

Nginx can be used as the LVS node machine, one can use Nginx function, the second is the performance of Nginx can be used. Of course, this level can also directly use the function of Squid,squid is weaker than Nginx, performance is also inferior to nginx.

Nginx can also be used as a middle-tier agent, this level nginx basically no opponent, the only one can shake Nginx only Lighttpd, but LIGHTTPD has not yet been able to do the full functionality of Nginx, the configuration is not so clear and easy to read. In addition, the middle-level proxy IP is also important, so the middle-level agent also has a VIP and LVs is the most perfect solution.

Nginx can also be used as a static Web server, but beyond the scope of this discussion, simply mention.

Specific application also have to be specific analysis, if it is relatively small site (pv<1000 million), with Nginx can be completely, if the machine is also a lot, you can use DNS polling, LVS, the cost of the machine is more; large web sites or important services, machines do not worry about the time, You should consider using LVs a lot.

*************************************************************************************************************** *

The advantages of Nginx:
Good performance, can load more than 10,000 of the concurrency.
Many functions, in addition to load balancing, can be used as a Web server, but also through the GEO module to achieve traffic distribution.
Community active, third-party patches and modules many
Support for Gzip Proxy
Session hold is not supported.
The health check function of the back-end realserver is not effective. It is only supported for detection by port and is not supported by URL.
Nginx support for big request header is not very good, if the client_header_buffer_size setting is relatively small, it will return to the 400bad request page.
Advantages of Haproxy:
Its advantages just can be added to the shortcomings of Nginx. Supports session hold while supporting the detection of the status of the backend server by obtaining the specified URL.
Supports load balancing in TCP mode. For example, you can load balance MySQL from the server cluster and mail server.
Virtual Host not supported (this is silly)
There are currently no performance monitoring templates for Nagios and cacti
Advantages of LVS:
Good performance, close to hardware equipment network throughput and connection load capacity.
LVS's Dr mode, which supports load balancing over a WAN. None of this other load balancing software is currently available.
More heavy. Another community than Nginx active.


Now the common load balancing in the network is mainly divided into two kinds: one is through hardware, common hardware has more expensive NetScaler, F5, Radware and array and other commercial load balancer, there are similar to LVs, Nginx, Haproxy's Linux-based, open-source load balancing strategy,

Commercial load balancing inside NetScaler is more efficient than F5 in effect. For a load balancer, however, the commercial load balancer can be built on the four to seven layer protocol, so the application of a wider range so there is no alternative, his advantage is that there is a professional maintenance team to maintain these services, the disadvantage is that the cost is too large, so for the smaller network services for the moment there is no need to use.

Another way to load balance is through the software: more common with LVs, Nginx, Haproxy, etc., where LVS is built on the four layer protocol above, and the other Nginx and Haproxy is based on the seven layer protocol, the following respectively about

LVS: Achieve a high-performance, high-availability server with cluster technology and Linux operating systems with good scalability (Scalability), Reliability (reliability), and manageability (manageability).

LVS is characterized by:

1, strong anti-load capacity, is the work in the Network 4 layer on the distribution only, no flow generation;

2, the configuration is relatively low, this is a disadvantage is also an advantage, because there is not much to configure things, so do not need too much contact, greatly reducing the chance of human error;

3, stable work, self has a complete two-machine hot standby program;

4, no flow, to ensure that the performance of the Equalizer IO will not receive the impact of large traffic;

5, a wide range of applications, can be load-balanced for all applications;

6, LVS need to apply to IDC more than one IP to do the visual IP, so the need for a certain network knowledge, so the operator's requirements are relatively high.

The features of Nginx are:

1, work in the network on the 7 layer, can be targeted for HTTP applications to do some diversion strategy, such as for the domain name, directory structure;

2, Nginx dependence on the network is relatively small;

3, Nginx installation and configuration is relatively simple, testing more convenient;

4, can also bear high load pressure and stability, generally can support more than 10,000 times the concurrency;

5, Nginx can detect the server internal fault through the port, for example, according to the server processing the status code returned by the Web page, time-out and so on, and will return the wrong request resubmitted to another node, but the disadvantage is that the URL is not supported to detect;

6, Nginx to the request of asynchronous processing can help the node server to reduce the load;

7, Nginx can support HTTP and email, so much smaller in the scope of application;

8, does not support the session to maintain, the big request header support is not very good, in addition, the default is only Round-robin and Ip-hash two load balancing algorithms.

Haproxy is characterized by:

1, Haproxy is working on the network 7 layer above.

2, can add some of the shortcomings of Nginx such as the session of the maintenance, cookie guidance and other work

3, support the URL detection backend server problem detection will be very good to help.

4, more load balancing strategy such as: Dynamic weighted round robin (Round Robin), weighted source address hash (Weighted source hash), weighted URL hash and weighted parameter hash (Weighted Parameter hash) has been implemented

5, simply from the efficiency of the haproxy more than Nginx has a better load balancing speed.

6, Haproxy can load balance MySQL, the back-end of the DB node detection and load balancing.


Now the trend of Web site development on the use of Network Load balancing with the increase of site size according to different stages to use different technologies:

The first stage: using Nginx or Haproxy for a single point of load balancing, this stage of the server scale just out of the single-server, single-database mode, requires a certain load balancing, but still small, no professional maintenance team to maintain, there is no need for large-scale site deployment. This use of Nginx or Haproxy is the first choice, at this time these things get started fast, easy to configure, on the seven layer above the use of HTTP protocol can. This is the first choice.

The second stage: with the further expansion of network services, then the single-point Nginx can not meet, when using LVS or commercial F5 is the primary choice, nginx at this time as LVS or F5 node to use, specific LVS or F5 is the choice is based on the company size, Talent and capital ability to choose, here also do not do in detail, but generally this phase of the relevant talent to keep up with the business, so the purchase of commercial load balance has become the only way.

The third stage: The Network Service has become the mainstream products, at this time with the company's popularity is further expanded, the ability of relevant talents and the number of the increase, then regardless of the development of their own product customization, and reduce the cost of the open source LVs, has become the first choice, then LVS will become the mainstream.

The final formation of a more ideal state is: F5/lvs<->haproxy<->squid/varnish<->appserver.

Comparison and analysis of load balance between LVS, Haproxy and Nginx

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: 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.