Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the high-performance load balancing design method of the server?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the high-performance load balancing design method of the server". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn "what is the high-performance load balancing design method of the server"!

1. What is load balancing?

In the early Internet applications, because the user traffic is relatively small and the business logic is relatively simple, a single server can often meet the load demand. With the increasing traffic on the Internet, a slightly better system will have a very large number of visits, and the system functions will become more and more complex, so no matter how well a single server optimizes its performance, it can not support the access pressure of such a large number of users, so it is necessary to use multiple machines and design high-performance clusters to deal with it.

So, how do multiple servers balance traffic and form high-performance clusters?

At this point, you need to invite out the "load balancer" to enter.

Load balancing (Load Balancer) means that the traffic accessed by users is evenly distributed to multiple back-end servers through a "load balancer" according to a certain forwarding strategy, and the back-end servers can respond and process requests independently, so as to achieve the effect of load distribution. Load balancing technology improves the service capability of the system and enhances the availability of applications.

(can be understood according to the figure, picture source network) 2. How many load balancing solutions are there?

At present, there are three most common load balancing technical solutions on the market:

Load balancing based on DNS

Based on hardware load balancing

Based on software load balancing

The three schemes have their own advantages and disadvantages. DNS load balancing can achieve regional traffic balancing, hardware load balancing is mainly used for load demand in large server clusters, while software load balancing is mostly based on machine-level traffic balancing. In a real scene, these three can be used together. Let's talk about it in detail:

Load balancing based on DNS

(network picture)

Load balancing based on DNS is actually the simplest implementation scheme, which can be done by making a simple configuration on the DNS server.

The principle is that when users access a domain name, they will first resolve the IP address corresponding to the domain name to the DNS server. At this time, we can let the DNS server return different IP according to the users of different geographical locations. For example, users in the south will return the IP of our business server in Guangzhou, and if users in the north come to access it, I will return the IP where the business server in Beijing is located.

In this mode, users are equivalent to diverting requests according to the "nearest principle", which not only reduces the load on a single cluster, but also improves the access speed of users.

Using DNS as a load balancing solution, the natural advantage is that the configuration is simple, the cost is very low, and no additional development and maintenance work is needed.

But there is also an obvious disadvantage: when the configuration is modified, it does not take effect in time. This is due to the characteristics of DNS. DNS generally has multi-level cache, so when we modify the DNS configuration, the IP changes will be delayed due to cache reasons, thus affecting the effect of load balancing.

In addition, using DNS for load balancing is mostly based on region or simply doing IP polling directly, and there is no more advanced routing strategy, so this is also the limitation of DNS solution.

Based on hardware load balancing

(network picture)

Hardware load balancing is quite powerful. For example, the famous F5 Network Big-IP, which is what we often call F5, is a network device. You can simply understand it as something similar to a network switch that resists pressure entirely through hardware. The performance is very good. The number of requests per second can reach millions, that is, millions of requests per second, that is, a load of millions per second. Of course, the price is very expensive. There are hundreds of thousands to millions of yuan.

Because this kind of equipment is generally used at the front end of the traffic entrance of large Internet companies, as well as the government, state-owned enterprises and other enterprises with no shortage of money will use it. In general, small and medium-sized companies are reluctant to use it.

If you use hardware such as F5 to do load balancing, it is mainly to save worry and trouble, buy one and get it, with powerful performance, not to mention the general business. And in the load balancing algorithm also supports a lot of flexible strategies, but also has some security functions such as firewalls. But the disadvantage is also obvious, in one word: expensive.

Based on software load balancing

(network picture)

Software load balancing refers to the use of software to distribute and balance traffic. Software load balancing is divided into layer 7 protocol and layer 4 protocol.

The network protocol has seven layers. The scheme for traffic distribution based on layer 4 transport layer is called layer 4 load balancing, such as LVS, while the scheme based on layer 7 application layer for traffic distribution is called layer 7 load balancing, such as Nginx. There are some differences in performance and flexibility between the two.

The performance of load balancing based on layer 4 is higher, which can reach hundreds of thousands per second, while the capacity of load balancing based on layer 7 is only tens of thousands per second.

The characteristic of software-based load balancing is also obvious and cheap. It can be deployed on a normal server, with no additional purchase, just a little bit of technology to optimize, so this is one of the most commonly used methods in Internet companies.

What are the commonly used equalization algorithms?

After talking about the common load balancing technical solutions above, let's take a look at which balancing algorithms can be used in actual solution applications.

Polling strategy

Load degree strategy

Response strategy

Hash strategy

Let's introduce the characteristics of these equalization algorithms / strategies:

Polling strategy

The polling strategy is easy to understand, that is, when a user request comes, the "load balancer" forwards the request to different back-end business servers in turn. This strategy is often used in the DNS solution. There is no need to pay attention to the status of the back-end service. Only if there is a request, it will be forwarded to the back-end in turn, which is very simple and practical.

In practical application, there are many ways of polling, including sequential polling, random polling, and polling according to weight. The first two are easier to understand, and the third is to poll according to weight, which means to set a weight value for each back-end service. For example, a server with high performance has a higher weight, while a server with low performance has a lower weight. When assigning traffic, more traffic with high weight can give full play to the performance of the back-end machine.

Load degree strategy

The load policy means that when the "load balancer" forwards traffic to the backend, it will first evaluate the load pressure of each server in the backend, and fewer requests will be forwarded to the more stressed backend servers. For less stressed backend servers, you can forward more requests to it.

This method fully combines the running state of the back-end server to dynamically allocate traffic, which is more scientific than polling.

However, this method also brings some disadvantages, because it needs to dynamically evaluate the load pressure of the back-end server, so this "load balancer" has to do a lot of extra work in addition to forwarding requests, such as collecting the number of connections, requests, CPU load indicators, IO load indicators and so on. Through the calculation and comparison of these indicators, we can determine which back-end server has greater load pressure.

Therefore, this method not only brings the effect advantage, but also increases the difficulty and maintenance cost of the "load balancer".

Response strategy

Response strategy means that when a user request comes, the load balancer will first forward the request to the back-end server with the fastest response at the current time.

In other words, no matter whether the load of the back-end server is high or not, and regardless of the configuration, as long as you think that the server can respond to the user's request as quickly as possible at the current moment, then the request will be forwarded to it first. In this case, for the user, the experience is also best.

So how does the "load balancer" know which back-end service is the most responsive at the moment?

This requires the "load balancer" to constantly count the processing speed of each back-end server to the request, such as once a minute to generate a ranking of the processing speed of the back-end server. The load balancer then forwards the service according to this ranking.

Then the problem here is the cost of statistics, constantly doing these statistical operations will not only consume some performance, but also increase the difficulty of implementing the "load balancer" and the cost of maintenance.

Hash strategy

The Hash policy is also easy to understand, that is, a certain information in the request is calculated by hash, and then a value is obtained according to the number of backend servers, and the request with the same value is forwarded to the same backend server.

The common use is to apply this strategy to the user's IP or ID, and then the "load balancer" ensures that the same IP source or the same user will always be sent to the same back-end server, which is especially useful when dealing with caching, sessions, and other functions.

Thank you for your reading. the above is the content of "what is the high-performance load balancing design method of the server". After the study of this article, I believe you have a deeper understanding of what the high-performance load balancing design method of the server is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report