Understand Layer 4/Layer 7 load balancing

Load balancing means that when a large number of concurrent requests come to the server, we can distribute these requests to multiple computer nodes, allowing more nodes to process requests and responses, which can greatly reduce the waiting time for user requests.

1 Layer 4 / Layer 7 load balancing

The OSI network model is divided into seven layers, that is, seven processes are required from the user initiating a request to the server receiving it. The seven layers from top to bottom are the application layer, presentation layer, session layer, transport layer, network layer, data link layer, and physical layer.

The so-called load balancing layering corresponds to the OSI seven-layer model. The seven-layer load balancing means that Nginx provides services at the application layer, and the fourth layer means that Nginx provides services at the transport layer.

1.1 Four-layer load balancing

The four-layer load balancing is based on IP+port load balancing. The principle is to forward the request to the background server. It is only responsible for forwarding and recording which server the current connection is processed by. Subsequent requests for this connection are processed by the same server. , Which is actually equivalent to a long connection, Once this long connection is opened, it will always process the connection status, and its performance will be very high. The fourth layer is based on the transport layer, mainly based on tcp and udp.

  • F5 hard load balancing: commercial grade, very expensive

  • LVS four-layer load balancing: It is the load of the Linux kernel and has nothing to do with the protocol. It is mainly responsible for forwarding some requests. It is based on the CS side.

  • HA proxy four-layer load balancing: it also supports forwarding functions, and is very flexible. In addition to doing four layers, it can also do seven-layer load balancing

  • Nginx four-layer load balancing: it can be used for load balancing or seven-layer load balancing, which can be used to realize the forwarding, proxy, etc. of the four-layer protocol

1.2 Seven-layer load balancing

Load balancing based on URL or IP, based on the application layer, is a load balancing for http protocol.

  • Nginx seven-layer load balancing performs load balancing on http protocol or mailbox protocol, with strong performance

  • Haproxy's seven-layer load balancing is very flexible

  • The flexibility of the Apache seven-layer load balancing protocol is not high, and the performance will be very poor if the concurrency reaches millions

to sum up:

  1. LVS is generally used for the four-layer load, and Nginx is more suitable for the seven-layer load.
  2. The four-layer load balancing is mainly suitable for processing based on the tcp and udp protocols, and the focus is on forwarding requests, not processing requests; the seven-layer is generally used to process the http protocol and is suitable for web servers; the seven-layer will process requests, such as It can handle some content of static resources, and can be compressed or cached.

1.3 DNS geographical load balancing

Is identified by the DNS server,Access the nearest server based on the IP address using the principle of proximity

Guess you like

Origin blog.csdn.net/LIZHONGPING00/article/details/113922307