Search CTRL + K

Load Balancing

负载均衡(load balancing,LB) 是用于给多个服务充当流量代理的解决方案,它负责分发不同应用流量到不同服务,还负责平衡不同服务器上同一个服务的流量负载以提高整体应用程序性能、稳定性,同时需要保持会话。负载均衡负载均衡器(load balancer,LB) 实现,有专用硬件实现,也有软件实现。

即使后端实例只有一个,也建议部署负载均衡器做一对一转发,因为 负载均衡 有许多重要优势:

负载均衡算法

负载均衡算法是负载均衡器采取的流量分发策略,分为静态和动态两类。

静态负载均衡算法

静态负载均衡算法根据预先设置好的计划转发流量,不会运行时动态调整。因此这种算法可能造成节点过载/节点饥饿。

主要的算法有:

动态负载均衡算法

动态负载均衡算法在运行时根据每个服务器状态(可用性、工作量和健康状况等)调整流量转发。但这种算法配置比较复杂。

主要的算法有:

负载均衡类型

通常根据 OSI 模型 分类 负载均衡器,有四层负载均衡器和七层负载均衡器。

What is load balancing?

Load balancing is the practice of distributing computational workloads between two or more computers. On the Internet, load balancing is often employed to divide network traffic among several servers. This reduces the strain on each server and makes the servers more efficient, speeding up performance and reducing latency. Load balancing is essential for most Internet applications to function properly.[1]

What is load balancer?

A load balancer is a solution that acts as a traffic proxy and distributes network or application traffic across endpoints on a number of servers. Load balancers are used to distribute capacity during peak traffic times, and to increase reliability of applications. They improve the overall performance of applications by decreasing the burden on individual services or clouds, and distribute the demand across different compute surfaces to help maintain application and network sessions.[2]

What is a load balancing algorithm?

A load balancing algorithm is the logic that a load balancer uses to distribute network traffic between servers (an algorithm is a set of predefined rules).

There are two primary approaches to load balancing. Dynamic load balancing uses algorithms that take into account the current state of each server and distribute traffic accordingly. Static load balancing distributes traffic without making these adjustments.[3]

Load Balancing ALgorithms

There are two types of load-balancing algorithms in terms of how they operate: static and dynamic. Static load balancing measures the incoming load on a server using algorithms that have performance capacity information about the existing servers in the distributed network. Dynamic load balancing can dynamically identify the amount of load that needs to be shed during runtime and which system should bear the load.[2:1]

Static load balancing algorithms

Static load balancing algorithms distribute workloads without taking into account the current state of the system. A static load balancer will not be aware of which servers are performing slowly and which servers are not being used enough. Instead it assigns workloads based on a predetermined plan. Static load balancing is quick to set up, but can result in inefficiencies.[1:1]

Dynamic load balancing algorithms

Dynamic load balancing algorithms take the current availability, workload, and health of each server into account. They can shift traffic from overburdened or poorly performing servers to underutilized servers, keeping the distribution even and efficient. However, dynamic load balancing is more difficult to configure. A number of different factors play into server availability: the health and overall capacity of each server, the size of the tasks being distributed, and so on.[1:2]


  1. https://www.cloudflare.com/learning/performance/what-is-load-balancing/ ↩︎ ↩︎ ↩︎

  2. https://www.f5.com/glossary/load-balancer ↩︎ ↩︎

  3. https://www.cloudflare.com/learning/performance/types-of-load-balancing-algorithms/ ↩︎