Load Balancing Strategies and Configuration Details

The load balancing strategies supported by Dubbo for the consumer side and how to use them.

Dubbo-go has a built-in client-based load balancing mechanism. Below are the currently supported load balancing algorithms. Combined with the automatic service discovery mechanism mentioned above, the consumer side will automatically use the Weighted Random LoadBalance strategy for invocation.

If you want to adjust the load balancing algorithm, here are the built-in load balancing strategies in the Dubbo framework:

AlgorithmFeaturesRemarksConfiguration Value
Weighted Random LoadBalanceWeighted RandomDefault algorithm, same default weightrandom (default)
RoundRobin LoadBalanceWeighted Round RobinInspired by Nginx’s smooth weighted round robin algorithm, same default weightroundrobin
LeastActive LoadBalanceLeast Active First + Weighted RandomBased on the idea that those who can do more should work moreleastactive
Consistent Hash LoadBalanceConsistent HashDeterministic input, deterministic providers, suitable for stateful requestsconsistenthashing
P2C LoadBalancePower of Two ChoicesRandomly selects two nodes and continues to select the one with fewer “connections.”p2c
Interleaved Weighted Round RobinA weighted round robin algorithmhttps://en.wikipedia.org/wiki/Weighted_round_robin#Interleaved_WRRinterleavedweightedroundrobin
Alias Method Round Robinhttps://en.wikipedia.org/wiki/Alias_methodaliasmethod

Global Configuration

The default strategy of the Dubbo framework is random weighted random load balancing. To adjust the strategy, simply set the corresponding value for loadbalance. Refer to the table at the top of the document for different load balancing strategy values.

Specify global configuration for all service calls:

cli, err := client.NewClient(
	client.WithClientLoadBalance("roundrobin"),
)

Or some commonly used strategies:

cli, err := client.NewClient(
	client.WithClientLoadBalanceRoundRobin(),
)

Interface Level Configuration

cli, err := client.NewClient(
	//...
)

svc, err := greet.NewGreetService(cli, client.WithLoadBalance("roundrobin"))

Or some commonly used strategies:

cli, err := client.NewClient(
	//...
)

svc, err := greet.NewGreetService(cli, client.WithLoadBalanceRoundRobin())