Load Balance Algorithm

Background

ShardingSphere built-in provides a variety of load balancer algorithms, including polling algorithm, random access algorithm and weight access algorithm, which can meet users’ needs in most business scenarios.

Moreover, considering the complexity of the business scenario, the built-in algorithm also provides an extension mode. Users can implement the load balancer algorithm they need based on SPI interface.

Parameters

Round-robin Load Balance Algorithm

Type: ROUND_ROBIN

Random Load Balance Algorithm

Type: RANDOM

Weight Load Balance Algorithm

Type: WEIGHT

Attributes:

NameDataTypeDescription
${replica-name}doubleAttribute name uses the name of the replica, and the parameter fills in the weight value corresponding to the replica. Weight parameter range min > 0, total <= Double.MAX_VALUE.

Procedure

  1. Configure a load balancer algorithm for the loadBalancers attribute to use read/write splitting.

Sample

  1. rules:
  2. - !READWRITE_SPLITTING
  3. dataSources:
  4. readwrite_ds:
  5. writeDataSourceName: write_ds
  6. readDataSourceNames:
  7. - read_ds_0
  8. - read_ds_1
  9. transactionalReadQueryStrategy: PRIMARY
  10. loadBalancerName: random
  11. loadBalancers:
  12. random:
  13. type: RANDOM