Comparison and Analysis of nginx load balancing and LVS Load Balancing

Source: Internet
Author: User
Tags node server nginx load balancing

Both LVS and nginx can be used as multi-host load solutions. They have advantages and disadvantages. in the production environment, you need to analyze the actual situation and make use of it.

First of all, I would like to remind you that technology is not a cloud, and my cloud is your cloud. At the same time, we should not be too conservative, too confident in the old method and wait for others to help you with the advance test. It is a good habit to study all the good things that are instantly heard, so as to improve your understanding and level of technology.

Let's take a look at the two:

I. Advantages of LVS:

1. Strong load resistance, because the logic of LVS is very simple, and it only works for request Distribution on Layer 4 of the network, with no traffic, therefore, you do not need to worry too much about efficiency. In my hand, LVS only experienced a problem once: packet loss occurred in the balancer within a short period of time with the highest concurrency. It was analyzed as a network problem, that is, the host capacity of the NIC or linux2.4 kernel has reached the upper limit, and there is basically no consumption in memory and CPU.

2. Low configuration, which 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 the server frequently except increase or decrease the server, this greatly reduces the likelihood of human error.

3. Work is stable. Because of its strong load resistance capability, high stability is also a logic. In addition, various LVS have a complete dual-machine Hot Standby solution, therefore, you don't have to worry about the problem with the balancer itself. If the node fails, LVS will automatically identify the problem, so the system is very stable as a whole.

4. No traffic, as mentioned above. LVS only distributes requests, but the traffic does not go out of it. Therefore, it can be used to distribute some lines. Without traffic, I/O performance of the balancer is not affected by large traffic.

5. Basically, it supports all applications. Because LVS works on Layer 4, it can perform Load Balancing for almost all applications, including HTTP, databases, chat rooms, and so on.

In addition, LVS does not completely identify node faults. For example, in the wlc allocation mode, if a node in the cluster is not configured with a VIP, the entire cluster will not be available, in this case, the WRR allocation method will discard a machine. This problem is still being tested. Therefore, you must be careful when using LVS.

Ii. Comparison results of nginx and LVS

1. nginx works on Layer 7 of the network. Therefore, it can be used to distribute traffic to HTTP applications, such as domain names and directory structures. In contrast, LVS does not have such a function, therefore, nginx is much more usable than LVS alone. However, nginx uses these functions to make them more adjustable than LVS, so it is often necessary to touch and touch, from the perspective of LVS's 2nd advantages, if there is more touch, there will be a higher chance of human problems.

2. nginx is less dependent on the network. In theory, as long as the Ping is successful and the webpage access is normal, nginx can be connected. nginx can also distinguish between Intranet and Internet, if a node has both Intranet and Internet, it is equivalent to a single machine with a backup line; LVS is dependent on the network environment. Currently, the server is in the same network segment and LVS uses direct traffic distribution, the effect is guaranteed. Note that LVS needs to apply for at least one more IP address as the visual IP address from the publisher. It seems that it cannot use its own IP address as the VIP address. To be a good LVS administrator, you must follow up and learn a lot about network communication, so it is no longer as simple as an HTTP.

3. nginx installation and configuration are relatively simple, and testing is also very convenient, because it can basically print out errors using logs. It takes a long time to install, configure, and test LVS. As mentioned above, LVS has a large network dependency. In many cases, failure to complete the configuration is caused by network problems rather than configuration problems, it will be much more troublesome to solve the problem.

4. nginx can also withstand high loads and stability, but its load and stability are poor. LVS has several levels: nginx handles all traffic, so it is limited by machine I/O and configuration; the bug itself is still difficult to avoid; nginx does not have a ready-made hot standby solution, so it is still highly risky to run on a single machine, and it is hard to say everything on a single machine.

5. nginx can detect internal faults on the server, such as status code returned by the server to process webpages, timeout, and so on. In addition, it will resubmit the request with an error returned to another node. Currently, ldirectd in LVS can also be monitored based on internal server conditions, but the principle of LVS makes it unable to resend requests. Resend the request. For example, if the user is uploading a file and the node that handles the upload fails during the upload process, nginx will switch the upload to another server for reprocessing, LVS directly breaks down. If it is used to upload a large or important file, the user may be annoyed.

6. asynchronous processing of requests by nginx can help the node server reduce the load. If Apache is used for external services, when many narrow-band connections occur, the Apache server will occupy a large amount of memory and cannot be released. If one more nginx is used as the Apache proxy, these narrow-band connections will be blocked by nginx, apache does not pile up too many requests, which reduces the memory usage. This also applies to squid. Even if squid is configured as not cached, it is of great help to Apache. Without these features, LVS cannot be compared.

7. nginx supports HTTP and email (fewer email functions are recommended). LVS supports more applications than nginx.

In terms of use, generally the frontend should adopt LVS, that is, the DNS should point to the LVS balancer. The advantages of LVS make it very suitable for this task.

Important IP addresses are recommended to be hosted by LVS, such as the IP address of the database and the IP address of the WebService server. These IP addresses will become more and more usable over time. If the IP address is changed, the fault will occur one after another. Therefore, it is the most secure to hand over these important IP addresses to LVS for hosting. The only drawback of this operation is that the number of VIP addresses is large.

Nginx can be used as an LVS node machine. First, nginx functions can be used, and second, nginx performance can be used. Of course, squid can also be used directly at this layer. Squid features are much weaker than nginx, and performance is inferior to nginx.

Nginx can also be used as a middle-layer proxy. Basically, nginx has no rival in this layer. The only thing that can shake nginx is Lighttpd. However, Lighttpd is not fully capable of nginx yet, the configuration is not so clear and easy to read. In addition, the IP address of the Middle-layer proxy is also important, so the Middle-layer proxy also has a VIP and LVS is the most perfect solution.

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

The specific application needs to be analyzed in detail. If it is a relatively small website (daily PV <10 million), nginx is enough. If there are many machines, you can use DNS round robin, LVS consumes a large number of machines. When large websites or important services are not worried about, LVS should be used more.

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.