Updated on 2024-05-21 GMT+08:00

Assigning Read Weights

After read/write splitting is enabled, you can assign read weights as required. You can also adjust the number of nodes and their read weights when configuring a routing policy.

Description

  • After read/write splitting is enabled, you can assign read weights for the primary node and read replicas.
  • The default read weight of the primary node is 0. The higher read weight the primary node is assigned, the more read requests it can process.
  • When the read weights of all nodes are 0, services are not affected. In this case, the primary node processes all read and write requests by default.
  • The weight of a read replica ranges from 0 to 1000.
  • Newly created read replicas are automatically associated with proxy instances and their read weights are 0 by default. For details about the weight assignment rules, see Introducing Read Weight Assignment Rules.

Procedure

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page, choose Databases > GaussDB(for MySQL).
  4. On the Instances page, click the instance name to go to the Basic Information page.
  5. Click the name of a proxy instance.
  6. On the Basic Information page, click Change next to Routing Policy.
  7. In the displayed dialog box, select nodes for which you want to assign weights on the left and assign the weights on the right.

    • Different applications can connect to the GaussDB(for MySQL) instance through different proxy addresses. Read and write requests are forwarded to associated nodes. You can also add nodes to or remove nodes from proxy instances.
    • In the read/write mode, all write requests are routed to the primary node, and read requests are routed to each node based on the read weights.
    • In the read-only mode, only read requests can be routed to read replicas based on the read weights.
    • In the load balancing policy, read requests are routed only to the selected nodes. The weights of nodes cannot be modified.
    • In the weighted policy, you can set weights for selected nodes.
    Figure 1 Setting weights of nodes (in the weighted policy)

    Example:

    For example, a DB instance contains one primary node and two read replicas, and two proxy instances have been created.

    • Proxy instance 1 is in the read/write mode. The primary node and read replica 1 are connected to proxy instance 1 and assigned with a read weight of 200 and 100, respectively. They process read requests in the ratio of 2:1, that is, the primary node processes 2/3 read requests and read replica 1 processes 1/3 read requests. Write requests are automatically routed to the primary node.
    • Proxy instance 2 is in read-only mode. The primary node and read replica 2 are connected to proxy instance 2 and assigned with a read weight of 100 and 200, respectively. In this case, the weight of the primary node does not take effect, and read replica 2 processes all read requests.
    Figure 2 Ratio of read requests processed by each node in multiple proxy instances
    • When there are multiple proxy instances, newly created read replicas are automatically associated with proxy instances and their read weights are 0 by default.
    • After a read replica is deleted, its weight is automatically removed while the weights of other read replicas remain unchanged.