When cluster load balancing, Dubbo provides a variety of balancing strategies, the default is random
random calls.
In terms of specific implementation, Dubbo provides client load balancing, that is, the Consumer uses the load balancing algorithm to determine which Provider instance to submit the request to.
You can expand the load balancing strategy by yourself, see: Load Balance Extension
Currently Dubbo has the following built-in load balancing algorithms, which users can directly configure and use:
| Algorithms | Features | Remarks | | :————————– | :——————– – | :———————————————- | | RandomLoadBalance | Weighted random | Default algorithm, same weight by default | | RoundRobinLoadBalance | Weighted round-robin | Based on Nginx’s smooth weighted round-robin algorithm, the default weight is the same, | | LeastActiveLoadBalance | Least Active Priority + Weighted Random | Behind it is the idea that those who can do more work | | ShortestResponseLoadBalance | Shortest Response First + Weighted Random | More focus on response speed | | ConsistentHashLoadBalance | Consistent Hash | Definite input parameters, definite provider, suitable for stateful requests |
During the weighted round-robin process, if the weight of a node is too large, there will be a problem of too concentrated calls within a certain period of time.
For example, ABC three nodes have the following weights: {A: 3, B: 2, C: 1}
Then according to the most primitive polling algorithm, the calling process will become: A A A B B C
In this regard, Dubbo has optimized it by referring to Nginx’s smooth weighted round-robin algorithm. The calling process can be abstracted into the following table:
| Pre-round sum weight | Current round winner | Total weight | Post-round weight (winner minus total weight) |
| :—————— | :——- | :——- | :———- —————– |
| Starting round | \ | \ | A(0), B(0), C(0)
|
| A(3), B(2), C(1)
| A | 6 | A(-3), B(2), C(1)
|
| A(0), B(4), C(2)
| B | 6 | A(0), B(-2), C(2)
|
| A(3), B(0), C(3)
| A | 6 | A(-3), B(0), C(3)
|
| A(0), B(2), C(4)
| C | 6 | A(0), B(2), C(-2)
|
| A(3), B(4), C(-1)
| B | 6 | A(3), B(-2), C(-1)
|
| A(6), B(0), C(0)
| A | 6 | A(0), B(0), C(0)
|
We found that after the total weight (3+2+1) rounds, the cycle returns to the starting point, the node traffic is smooth throughout the process, and even in a short period of time, the probability is distributed according to expectations.
If users have the requirement of weighted polling, they can use this algorithm with confidence.
###ShortestResponse
Response time here = the average response time of a provider within the window time, and the default window time is 30s.
###ConsistentHash
<dubbo:parameter key="hash.arguments" value="0,1" />
<dubbo:parameter key="hash.nodes" value="320" />
<dubbo:service interface="..." loadbalance="roundrobin" />
<dubbo:reference interface="..." loadbalance="roundrobin" />
<dubbo:service interface="...">
<dubbo:method name="..." loadbalance="roundrobin"/>
</dubbo:service>
<dubbo:reference interface="...">
<dubbo:method name="..." loadbalance="roundrobin"/>
</dubbo:reference>