This topic describes how to enable the read/write splitting feature for an ApsaraDB RDS for MySQL instance. The read/write splitting feature allows ApsaraDB RDS to route read and write requests to the primary and read-only RDS instances in your database system based on the read weights of these instances. This requires the use of the read/write splitting endpoint or a dedicated proxy endpoint.

Prerequisites

Procedure

  1. Go to the Database Proxy page.
    1. Log on to the ApsaraDB for RDS console. In the left-side navigation pane, click Instances. In the top navigation bar, select the region where your RDS instance resides.
      选择地域
    2. Find your primary RDS instance and click its ID. In the left-side navigation pane, click Database Proxy.
  2. On the Read/Write Splitting tab, click Enable.
  3. Configure the following parameters
    Configure read weights
    Parameter Description
    Latency Threshold The maximum latency that is allowed for data replication from your primary RDS instance to its read-only RDS instances. If the latency of data replication to a read-only RDS instance exceeds the specified threshold, ApsaraDB RDS stops routing read requests to the instance. This applies even if the instance has a high read weight.

    Valid values: 0 to 7200. Unit: seconds. In most cases, a read-only RDS instance replicates data at a specific latency due to SQL statement execution limits. We recommend that you set this parameter to a value that is greater than or equal to 30.

    Read Weight Distribution The read weight of each RDS instance in your database system. A higher read weight indicates more read requests to process. For example, your primary RDS instance is attached with three read-only RDS instances, and the read weights of these instances are 0, 100, 200, and 200. In this case, your primary RDS instance processes only write requests, and the three read-only RDS instances process all the read requests based on the 1:2:2 ratio.
    • Automatic Distribution: ApsaraDB assigns a read weight to each RDS instance based on the specifications of the instance. After you create a read-only RDS instance, ApsaraDB RDS assigns a read weight to the instance and adds the instance to the read/write splitting link. No manual operations are required. For more information, see Rules of weight allocation by the system.
    • Customized Distribution: You must manually specify a read weight for each RDS instance. Valid values: 0 to 10000. After you create a read-only RDS instance, the read weight of the instance is 0 by default. You must manually specify a new read weight for the instance.
    Note If you have specified a data replication latency for a read-only RDS instance, you cannot specify a read weight for the instance. For more information, see Set a replication delay for an RDS MySQL read-only instance.
  4. Click OK.

After the read/write splitting feature is enabled, you must add the used dedicated proxy endpoint to your application. Then, ApsaraDB RDS can route read and write requests to your primary RDS instance and its read-only RDS instances based on the read weights of these instances.

Introduction to the Read/Write Splitting tab

After you enable the dedicated proxy service, you can configure the following parameters on the Read/Write Splitting tab.

Read/Write Splitting tab
Section Parameter Description
Basic Information of Read/Write Splitting Read/Write Splitting Endpoint After you add the read/write splitting endpoint to an application, ApsaraDB RDS can route the read and write requests from the application to your primary RDS instance and its read-only RDS instances based on the read weights of these instances.
Note All the dedicated proxy endpoints that you have created on the Proxy Service tab can be used as the read/write splitting endpoint. You can add these dedicated proxy endpoints to different applications based on access types or business requirements.
Port The port that is bound to the read/write splitting endpoint.
Network Type The network type of the read/write splitting endpoint.
Latency Threshold The maximum latency that is allowed for data replication from your primary RDS instance to its read-only RDS instances. If the latency of data replication to a read-only RDS instance exceeds the specified threshold, ApsaraDB RDS stops routing read requests to the instance. This applies even if the instance has a high read weight.
Read Weight Distribution Valid values:
  • Automatic Distribution: ApsaraDB RDS assigns a read weight to each RDS instance based on the specifications of the instance. After you create a read-only RDS instance, ApsaraDB RDS assigns a read weight to the instance and adds the instance to the read/write splitting link. No manual operations are required. For more information, see Rules of weight allocation by the system.
  • Customized Distribution: You must manually specify a read weight for each RDS instance. Valid values: 0 to 10000. After you create a read-only RDS instance, the read weight of the instance is 0 by default. You must manually specify a new read weight for the instance.
Involved Instances The total number of primary and read-only RDS instances that are involved in read/write splitting in your database system.
Primary Instance The ID of your primary RDS instance. The Weight of Primary Instance parameter on the right shows the read weight of your primary RDS instance.
Read-only Instance The ID of a read-only RDS instance. The Weight of Read-only Instance parameter on the right shows the read weight of the read-only RDS instance.
Transaction Splitting Specifies whether to enable the transaction splitting feature for the read/write splitting endpoint. The transaction splitting feature allows ApsaraDB RDS to route the read requests prior to write operations in a transaction to the read-only RDS instances. This reduces the loads on your primary RDS instance. For more information, see Transaction splitting.
Note You can click Enable or Disable to the right of the Transaction Splitting parameter to enable or disable the transaction splitting feature.
Read/Write Splitting Architecture None The architecture and status of your primary RDS instance and its read-only RDS instances.

Related operations

Operation Description
DescribeDBProxy Queries details about the dedicated proxies of an ApsaraDB RDS instance.
DescribeDBProxyEndpoint Queries information about the dedicated proxy endpoints of an ApsaraDB RDS instance.
ModifyDBProxyEndpoint Modifies information about the dedicated proxy endpoints of an ApsaraDB RDS instance.