This topic describes how to enable the read/write splitting feature to forward read and write requests. This feature provides a read/write splitting endpoint. This endpoint can forward write requests to your primary RDS instance and read requests to the read-only RDS instances that are attached to your primary 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 deliver 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.

This topic applies only to RDS instances that run in shared proxy mode. For more information about RDS instances that run in dedicated proxy mode, see What are database proxies?.

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 of the page that appears, 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.
      Enable Database Proxy dialog box
      Note
      • Required. After you enable the dedicated proxy feature for your RDS instance, you must configure a proxy terminal for your RDS instance to implement read/write splitting. For more information, see Step 2: Configure a proxy terminal.
      • The default network type of a proxy endpoint varies based on the configuration of your RDS instance. For more information, see Manage the dedicated proxy endpoints of an ApsaraDB RDS for MySQL instance.
      • We recommend that you set the number of proxy instances to one-eighth of the total number of cores that are configured for your RDS instance and its read-only RDS instances. If the result is not an integer, you must round up the result to the nearest integer. You can specify up to 60 proxy instances.

        For example, if your RDS instance has 8 cores and its read-only RDS instance has 4 cores, we recommend that you specify two proxy instances based on the following calculation: (8 + 4)/8 = 1.5. The result 1.5 is rounded up to 2.

  3. Enable the read/write splitting feature.
    1. On the Read/Write Splitting tab, click Enable now.
    2. In the dialog box that appears, configure the following parameters and click OK.
      ParameterDescription
      Custom Proxy TerminalThe name of the proxy terminal. The name can be up to 30 characters in length.
      Read/Write AttributeThe read and write attributes of the proxy terminal. Valid values:
      • Read/Write (Read/Write Splitting): The proxy terminal connects to both your RDS instance and its read-only RDS instances. The proxy terminal can receive write requests. This is the default value.
      • Read-only (Primary Instance Not Connected to Receive Write Requests): The proxy terminal connects only to the read-only RDS instances and cannot receive write requests.

      For more information, see What is read/write splitting?.

      Connection PoolSpecifies whether to enable the connection pool feature. If you enable this feature, this parameter also specifies the type of connection pool that you want to enable. Valid values:
      • Transaction Connection Pool: This option is suitable in the scenarios in which a large number of connections, such as 10,000 or more connections, are established.
      • Session Connection Pool: This option is suitable in scenarios in which only short-lived connections over PHP are established.
      • Disable Connection Pool: This option indicates that you do not want to enable the connection pool feature. This is the default value.

      For more information, see Set the connection pool type of an ApsaraDB RDS for MySQL instance.

      Note This parameter appears only when you set the Read/Write Attribute parameter to Read/Write (Read/Write Splitting).
      Latency ThresholdThe maximum latency that is allowed for data replication from the primary RDS instance to the read-only RDS instances. If the latency of data replication to a read-only RDS instance exceeds the value of this parameter, ApsaraDB RDS no longer forwards read requests to the read-only RDS instance regardless of the read weight of the read-only RDS instance.

      Valid values: 0 to 3600. Unit: seconds. The read-only RDS instances may replicate data from the primary RDS instance at a specific latency. The latency varies based on the statuses of the SQL statements that are executed. We recommend that you set this parameter to a value that is greater than or equal to 30.

      Note This parameter appears only when you set the Read/Write Attribute parameter to Read/Write (Read/Write Splitting).
      Transaction SplittingSpecifies whether to enable the transaction splitting feature. After you enable the transaction splitting feature, ApsaraDB RDS forwards the read requests prior to write operations in transactions to the read-only RDS instances. This way, the loads on the primary RDS instance are reduced. The default value is Enabled.
      Note This parameter appears only when you set the Read/Write Attribute parameter to Read/Write (Read/Write Splitting).
      Read Weight DistributionThe method that is used to assign read weights. A higher read weight indicates more read requests that need to be processed. For example, three read-only RDS instances are attached to the primary RDS instance, the read weight of the primary RDS instance is 0, and the read weights of the three read-only RDS instances are 100, 200, and 200. In this case, the primary RDS instance processes only write requests, and the three read-only RDS instances process all read requests based on the 1:2:2 ratio.
      • Automatic: ApsaraDB RDS assigns a read weight to each RDS instance in your database system based on the specifications of the RDS instance. After you create a read-only RDS instance, ApsaraDB RDS automatically assigns a read weight to the read-only RDS instance and adds the read-only RDS instance to the read/write splitting link. For more information, see Rules of weight allocation by the system.
      • Custom: You must manually specify a read weight for each RDS instance in your database system. Valid values: 0 to 10000. By default, the read weight of a read-only RDS instance is 0. After you create a read-only RDS instance, you must manually specify a read weight for the read-only RDS instance based on your business requirements.
      Note
      • If a data replication latency is specified for a read-only RDS instance, you cannot specify a read weight for the read-only RDS instance. For more information, see Set the data replication latency of a read-only ApsaraDB RDS for MySQL instance.
      • After you reconfigure this parameter, the new read weights immediately take effect and no transient connections occur. In addition, the existing connections remain valid. Only the requests that are sent over new connections are forwarded based on the new weights.
      • If you use RDS Cluster Edition, you need to assign read weights to the primary and secondary nodes in your RDS cluster.

What to do next

After you enable the dedicated proxy feature and configure a proxy terminal for your RDS instance, you must add the endpoint of the proxy terminal to your application. This endpoint is also known as a proxy endpoint. For more information, see Manage the dedicated proxy endpoints of an ApsaraDB RDS for MySQL instance. Then, ApsaraDB RDS can forward write requests to the primary RDS instance and read requests to the read-only RDS instances based on the read weights of these instances. If the dedicated proxy feature is disabled, you must add an endpoint for read requests and another endpoint for write requests to your application.

Note On the Instances page, you can click the Show icon icon to view read-only RDS instances.

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