This topic describes how to enable the read/write splitting feature for an ApsaraDB RDS for MySQL instance for which the shared proxy service is enabled. This feature provides a read/write splitting endpoint. This endpoint can distribute write requests to your RDS instance and read requests to the read-only RDS instances that are attached to your RDS instance. The distribution is based on the read weights of these instances.

Background information

You can upgrade your RDS instance from shared proxy to dedicated proxy. Dedicated proxies provide higher performance and easier read/write splitting than shared proxies.

Note If the shared proxy service is enabled for your RDS instance, you cannot enable the read/write splitting feature. If you attempt to enable the read/write splitting feature, an error is reported. In this case, you must disable the shared proxy service, refresh the page, enable the dedicated proxy service, and then enable the read/write splitting feature.

The following section describes how to disable the shared proxy service, enable the dedicated proxy service, and then enable the read/write splitting feature.

Procedure

  1. Go to the Database Proxy page to disable the shared proxy service.
    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 RDS instance and click its ID. In the left-side navigation pane, click Database Proxy.
    3. Turn off the switch next to Enabled.
  2. Enable the dedicated proxy service.
    1. Refresh the page and click Enable.
      Note You must confirm that the page where Enable resides is the same as the following figure.
      Enable the dedicated proxy service
    2. Configure the Network Type and Proxy Instances parameters. Then, click Enable.
      Note
      • The default network type varies based on the instance configuration. For more information, see Manage the dedicated proxy endpoints of an ApsaraDB RDS for MySQL instance.
      • We recommend that you specify the number of dedicated proxies as the rounded-up integer of the total number of CPU cores of your primary RDS instance and its read-only RDS instances divided by 8. A maximum of 60 dedicated proxies are supported.

        For example, if your primary RDS instance has eight CPU cores and its read-only RDS instances have four CPU cores, the recommended number of dedicated proxies is 2 based on the following calculation: (8 + 4)/8 = 1.5 (rounded up to 2).

      Enable Database Proxy dialog box
  3. Enable the read/write splitting feature.
    1. On the Read/Write Splitting tab, click Enable.
    2. 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.
    3. Click OK.

For more information about the read/write splitting feature in the dedicated proxy service, see Enable the read/write splitting feature for an ApsaraDB RDS for MySQL instance.