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. I will study all the good things I have heard in real time from

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, memory andCpThere is almost no u consumption.

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 operations on almost all applications.Server Load balancerIncluding http, database, and chat room.

In addition, lvs is not completely capable of identifying node faults. For example, in the wlc allocation mode,ClusterIf no VIP is configured for a node in the cluster, the entire cluster cannot be used. In this case, a machine is lost when wrr is used. 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. TheoreticallyPingIf the webpage is accessed normally, nginx can be connected. nginx can also distinguish between the Intranet and the Internet. If it is a node with both the Intranet and the Internet, it is equivalent to a single machine with a backup line; lvs depends on the network environment. Currently, the server is in the same network segment and lvs uses direct traffic delivery, which ensures the effect. In addition, note that lvs needs to apply for at least one ip address from the producer for Vi.SuIt seems that the virtual IP address cannot be used 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 directly, the apache server will occupy a large amount of memory and cannot be released when many narrowband connections occur, if one more nginx is used as the apache proxy, these narrowband links will be blocked by nginx, and apache will not pile up too many requests, which reduces the memory usage. This uses squIdIt also has the same effect, even if squid itself is configured as not cached, it will be 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, which basically has no rivals. The only thing that can shake nginx is lig.HttpdHowever, lighttpd does not yet provide complete nginx functions, and 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.

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.