current position:Home>Im instant messaging development: load balancing of high-performance HTTP server

Im instant messaging development: load balancing of high-performance HTTP server

2022-04-29 06:08:42Grumpy battery

In a typical high concurrency 、 Large number of users Web In the architecture design of Internet system , Yes HTTP The load balancing design of cluster is an essential scheme in the optimization of high-performance system .HTTP The essence of load balancing is to Web User traffic is balanced and depressurized , Therefore, in the large traffic projects of the Internet , Its importance is self-evident .

Instant messaging network note : What is mentioned in this article HTTP Load balancing scheme and algorithm , Not entirely applicable IM im Socket Load balancing for long connections , because IM A long connection 、 The characteristic of being stateful , Follow HTTP This short connection 、 The characteristics of Statelessness are contradictory , So don't blindly apply . but , A complete IM The system is composed of HTTP Short connection +IM Long connections make up , Therefore, although the content of this paper cannot be applied to IM Long connection load balancing scheme , But it can be used for you IM High concurrency 、 Large number of users HTTP Short connection scheme design .

What is load balancing ?

Early Internet applications , Because the user traffic is relatively small , The business logic is also relatively simple , Often a single server can meet the load demand . With the increasing traffic on the Internet , A slightly better system , The number of visits is very large , And the system functions are becoming more and more complex , Then even if the performance of a single server is optimized better , It can't support the access pressure of such a large number of users , At this time, you need to use multiple machines , Design high-performance clusters to deal with .

that , How multiple servers balance traffic 、 How to form a high-performance cluster ?

At this point, you need to ask out 「 Load Balancer 」 It's in .

Load balancing (Load Balancer) It refers to the traffic accessed by users , adopt 「 Load Balancer 」, According to some forwarding strategy , Distribute evenly to multiple servers at the back end , The back-end server can respond and process requests independently , So as to achieve the effect of distributed load . Load balancing technology improves the service capacity of the system , Enhanced application availability .

There are several mainstream load balancing schemes ?

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

1) be based on DNS Load balancing ;

2) Based on hardware load balancing : such as F5

3) Based on software load balancing : such as Nginx、Squid.

Each of the three plans has its own advantages and disadvantages ,DNS Load balancing can achieve regional traffic balance , Hardware load balancing is mainly used for load requirements in large server clusters , Software load balancing is mostly based on machine level traffic balancing . In the real world , These three can be combined .

be based on DNS To do load balancing is actually the simplest implementation scheme , By means of DNS Just make a simple configuration on the server .

The principle is : When a user accesses a domain name , Will go first to DNS The server resolves the corresponding domain name IP Address , At this time, we can let DNS The server returns different information according to users in different geographical locations IP. For example, users in the South will return to our business server in Guangzhou IP, If users from the North come to visit , I will return to the location of the Beijing business server IP.

In this mode , The user is equivalent to realizing according to 「 Nearby principle 」 Shunting requests , It not only reduces the load pressure of a single cluster , It also improves the access speed of users .

Use DNS Do a load balancing scheme , The natural advantage is simple configuration , The cost of implementation is very low , No additional development and maintenance work is required .

But it also has an obvious disadvantage : When the configuration is modified , Untimely entry into force . This is because DNS It's the nature of ,DNS There are usually multi-level caches , So when we modify DNS After configuration , Because of caching , It can lead to IP Changes are not timely , This affects the effect of load balancing .

in addition , Use DNS For load balancing , Mostly based on region or simply do it directly IP polling , There is no more advanced routing policy , So this is also DNS The limitations of the scheme . Instant messaging chat software development can consult weikeyun .

Hardware load balancing is awesome , For example, famous F5 Network Big-IP, That's what we often say F5, It's a network device , You can simply understand it as something similar to a network switch , Completely resistant to pressure through hardware , The performance is very good , Millions of requests can be processed per second , namely Millions of millions / second The load of , Of course, the price is very, very expensive , There are hundreds of thousands to millions of RMB .

Because such devices are generally used at the front end of the traffic entrance of large Internet companies , And the government 、 State owned enterprises and other enterprises that do not lack money will use it . General small and medium-sized companies are not willing to use .

use F5 If this kind of hardware is used for load balancing , The main thing is to save worry and trouble , Just buy one , Powerful performance , General business is no problem . Moreover, it also supports many flexible strategies in the algorithm of load balancing , At the same time, it also has some security functions such as firewall . But the disadvantages are obvious , One word : your .

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

There are seven layers of network protocol , The scheme of traffic distribution based on the fourth layer transport layer is called 4 Layer load balancing , for example LVS; The traffic distribution based on the seventh application layer is called 7 Layer load balancing , for example Nginx. There are some differences between the two in terms of performance and flexibility .

be based on 4 The load balancing performance of the layer is higher , Generally can achieve Hundreds of thousands of / second The processing capacity of , And based on 7 The load balancing processing capacity of the layer is generally only in tens of thousands / second .

The characteristics of software based load balancing are also obvious , cheap . Just deploy it on a normal server , There is no need to purchase extra , Is to invest a little bit of technology to optimize it , So this is one of the most used ways for Internet companies .

What are the commonly used equalization algorithms ?

The above describes the common load balancing technical solutions , Then let's take a look at , In practical application , Which equalization algorithms can be used in general ?

The main equalization algorithms are :

1) Polling strategy ;

2) Load degree policy ;

3) Response strategy ;

4) Hash strategy .

copyright notice
author[Grumpy battery],Please bring the original link to reprint, thank you.

Random recommended