During cluster load balancing, Dubbo provides multiple balancing strategies, with the default being the weighted random
strategy, which is a weight-based random load balancing strategy.
In terms of implementation, Dubbo provides client-side load balancing, meaning the Consumer determines which Provider instance to send the request to using a load balancing algorithm.
Currently, Dubbo has built-in the following load balancing algorithms, which can be enabled through configuration adjustments.
Algorithm | Characteristics | Remarks |
---|---|---|
Weighted Random LoadBalance | Weighted Random | Default algorithm, default weights are the same. |
RoundRobin LoadBalance | Weighted Round Robin | Inspired by Nginx’s smooth weighted round-robin algorithm. |
LeastActive LoadBalance | Least Active + Weighted Random | The principle of “the more capable, the more work”. |
Shortest-Response LoadBalance | Shortest Response + Weighted Random | Focuses more on response speed. |
ConsistentHash LoadBalance | Consistent Hashing | Deterministic parameters lead to a deterministic provider, suitable for stateful requests. |
P2C LoadBalance | Power of Two Choice | After randomly selecting two nodes, choose the one with fewer “connections”. |
Adaptive LoadBalance | Adaptive Load Balancing | Based on P2C algorithm, chooses the node with the least load. |
For the weighted round robin, if a node’s weight is too large, there’s the problem of concentrated calls in a short time span.
The Power of Two Choice algorithm is simple but classic.
Adaptive, as the name suggests, is a self-adapting load balancing mechanism that always tries to forward requests to the least loaded node.
Dubbo allows providers to configure a default load balancing strategy so that all consumers will use the strategy specified by the provider by default. Consumers can also specify their own load balancing strategies. If neither side has any configuration, the random load balancing strategy is used by default.
Each application can configure different services to use different load balancing strategies and can even specify different strategies for different methods of the same service.
For configuration details, refer to the implementations in different languages:
Load balancing strategies support custom extension implementations. For details, please see Dubbo’s Extensibility.