& #65279; Comparison and Analysis of nginx Server Load balancer and lvs Server Load balancer

Source: Internet
Author: User
Tags node server

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. It is estimated that nginx can support http and emailemail functions with fewer users.) 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 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.

Related Article

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.