Load balancing
Spring Cloud SOFA provides its own load balancing algorithms to replace native Spring Cloud algorithms, such as those in LoadBalancer and Ribbon. These algorithms are enabled by default and support weights. Weights that you configure in the SOFA microservice console will only take effect when using the Spring Cloud SOFA load balancing algorithms.
Configure load balancing
Spring Cloud SOFA provides two load balancing policies that support weights: random and round-robin. The default policy is random.
To switch the load balancing algorithm, configure the following parameters in the application.properties file.
Configuration item | Description | Default value |
spring.cloud.sofa.loadbalancer.type | The default load balancing algorithm. Valid values are random and roundRobin. | random |
spring.cloud.sofa.loadbalancer.types.{serviceId} | Configure the load balancing algorithm for a specific service. | None |
The SOFA load balancing feature requires the Spring Cloud load balancing framework. If you use Ribbon as the load balancing framework, you must also import the Spring Cloud SOFA Router module.
Disable SOFA load balancing
To disable the SOFA load balancing algorithms, set the value of spring.cloud.sofa.loadbalancer.enabled to false in the application.properties file. When disabled, load balancing reverts to the native Spring Cloud implementation. The algorithm used will then be the one provided by LoadBalancer, Ribbon, or another configured load balancer.
spring.cloud.sofa.loadbalancer.enabled=false