How to expand business horizontally? What is load balancing? What are proxies and reverse proxies?

How to expand business horizontally? What is load balancing? What are proxies and reverse proxies?

Load balancer:

First, let’s take an example of a website named -xxx. A user visits the xxx website to initiate an http request and hits the target server. Assume that the xxx website currently has more than 200 users, and the server only has 2Core 4GB memory. But as the number of website users increases, the number of users will reach 2 million after one year. Obviously, when 2 million people send requests to a server at the same time, the server needs more than 2 million threads to process these requests. At this time, the dual-core and 4G memory share Not enough. Here’s how to solve this problem:

  • Vertical expansion: Simply expand the memory of the machine. For example, 2-core 4G memory is too fast to play games. You can change to 4-core 8G, or even higher. However, it should be noted that the memory-performance ratio of vertical expansion is not linear, as shown in the figure. Show:

Insert image description here
That is to say, the higher the memory cost you invest, the lower the return will be. Then there is vertical expansion and there is horizontal expansion.

  • Horizontal expansion: Directly understand the above picture above
    Insert image description here
    is horizontal expansion, then how to carry out horizontal expansion, this time leads to load balancing, to talk about load balancing, first of all we have to talk about what is a reverse proxy (reverse proxy), then we have to understand what Is a proxy

Proxy:

Take a chestnut: your mother at home does not allow you to use your computer to use any web pages other than QQ, but you want to check your college entrance examination results, and you cannot access the web page for checking results due to restrictions, so you found yours on QQ Teacher, I asked you to check your grades for you. Your teacher found your grades and sent you on QQ. During this process, your teacher acted as an agent: so what is a reverse proxy
Insert image description here
:

Reverse proxy:

Then there is a chestnut, your classmate wants to know your grades, but he does not have your QQ, then he went to find your teacher and asked your teacher about your grades, your teacher asked about your grades and told you Your classmate: In this process, your teacher acts as a reverse proxy server:
Insert image description here
the process of proxy and reverse proxy is just the opposite. The proxy is for the external website you want to go to, and the reverse proxy refers to the external website. To access your server,
Insert image description here
you generally know what the proxy is used for, so how does the reverse proxy use it like this:
Take a chestnut: If we want to help the bank develop a fund management system, the server of this system has very high requirements for security performance, and the server deployment After success, direct access from the external network is not allowed, and any port of the server cannot be exposed to the external network. Then how to allow users to access the fund management system after the system is online? At this time, a reverse proxy server is used. On the one hand, the reverse proxy server has
a The external network IP, on the one hand, has an internal network IP, which can bear the http request directly initiated by the external network, helps external network users connect to the real fund management system server, and returns the http form returned by the fund management system server Then return it to external users. Using this method, external users can use the system we built through the reverse proxy server. In addition, the reverse proxy server has the function of caching. For example, in the chestnuts for checking the results of the college entrance examination above, the students ask the head teacher about your grades. If the teacher has asked/checked your grades before, the students will ask the teacher about your grades. The teacher will not ask you again, but will directly return your grades to that classmate. This is the cache of the reverse proxy. In
Insert image description here
addition, another feature of using the reverse proxy is that the reverse proxy server is the same as the real server. In the pure intranet, there is no need to use https communication between them, just use http communication, and the real server can also restrict the ip address, and only the reverse proxy server is allowed to initiate requests to it, so the real server is more secure. There is no need to support https. To save trouble, reverse proxy is still quite useful.

Back to load balancing (reverse proxy):

After talking about reverse proxy, now back to load balancing. To put it bluntly, load balancing is a reverse proxy server plus a load balancing algorithm. The relationship is as shown in the figure: The
Insert image description here
most typical algorithm is the rotation method, which means to send requests to different servers in turn. . But if our business is special and requires a guarantee that users always use a certain server, a hash algorithm is used at this time:
For example: Suppose there are ten windows in the school cafeteria. In order to ensure the load balance of the ten windows in the cafeteria, each student is required to Go to a specific window to eat, set the hash algorithm, and the student number is 10, and you will get the student's designated window for eating. The same principle applies to specifying different http requests using a hash algorithm. http requests are based on the TCP-IP protocol, so it is easy to get the IP address, and then hash the IP address to get the target server to which the request is sent, so as to ensure the load. balanced
Insert image description here

  • Comparison of Vertical Expansion & Horizontal Expansion
    Insert image description here
    Therefore, when purchasing servers, the performance of using three servers of 300 yuan per month is much better than that of using one server of 1,000 yuan per month. However, no matter how many servers
    you have, you must finally If the amount of requests is too large and there are too many servers, then the final load balancing may be exhausted (single point of failure), so it is necessary to start the master-slave load balancing plan. After the master load balancing dies, the slave load balancing will take over the work , to ensure business continuity.

Guess you like

Origin blog.csdn.net/khadijiah/article/details/105920258