This topic describes how to enable and configure the dedicated proxy feature for an ApsaraDB RDS for MySQL instance. The dedicated proxy feature provides advanced features such as read/write splitting, connection pooling, transaction splitting, and SSL encryption.

Prerequisites

  • Your RDS instance is a primary instance that runs one of the following MySQL versions and RDS editions:
    • MySQL 8.0 with a minor engine version of 20191204 or later on RDS Enterprise Edition
    • MySQL 8.0 with a minor engine version of 20190915 or later on RDS High-availability Edition
    • MySQL 5.7 with a minor engine version of 20191128 or later on RDS Enterprise Edition
    • MySQL 5.7 with a minor engine version of 20190925 or later on RDS High-availability Edition
    • MySQL 5.6 with a minor engine version of 20200229 or later on RDS High-availability Edition
    Note To view the minor engine version of your RDS instance, you must log on to the ApsaraDB RDS console and go to the Basic Information page. In the Configuration Information section of the page, you can check whether the Upgrade Kernel Version button is displayed. If the button is displayed, you can click the button to view and update the minor engine version of your RDS instance. If the button is not displayed, your RDS instance runs the latest minor engine version. For more information, see Update the minor engine version of an ApsaraDB RDS for MySQL instance.
  • A read-only RDS instance is created for your RDS instance. For more information, see Create a read-only ApsaraDB RDS for MySQL instance.
  • Your RDS instance does not reside in Zone C or Zone D of the China (Hangzhou) region.
    Note If your RDS instance resides in Zone C or Zone D of the China (Hangzhou) region, you must migrate your RDS instance to other zones before you enable the dedicated proxy feature for your RDS instance. For more information, see Migrate an ApsaraDB RDS for MySQL instance across zones in the same region.

Billing rules

For more information, see Billing rules for dedicated proxy instances that are enabled on an ApsaraDB RDS for MySQL instance.

Limits

  • If you enable the dedicated proxy feature for your RDS instance, your RDS instance does not support compression protocols.
  • If you enable the dedicated proxy feature for your RDS instance, your RDS instance does not support vSwitch changes.

Step 1: Enable the dedicated proxy feature

This section describes how to enable the dedicated proxy feature for your RDS instance in the ApsaraDB RDS console. You can also enable the dedicated proxy feature when you create a read-only RDS instance for your RDS instance. For more information, see Create a read-only ApsaraDB RDS for MySQL instance.

  1. Access RDS Instances, select a region at the top, and then click the ID of the target RDS instance.
  2. In the left-side navigation pane, click Database Proxy.
  3. On the page that appears, click Enable Proxy. In the dialog box that appears, configure the Network Type parameter and the Proxies parameter and click Enable.
    Enable Database Proxy dialog box
    Note
    • Before you can use the advanced features, such as read/write splitting, that are provided by the dedicated proxy feature, you must configure a proxy terminal for your RDS instance. 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.

Step 2: Configure a proxy terminal

Before you can use the advanced features that are provided by the dedicated proxy feature, you must configure a proxy terminal for your RDS instance.

  1. Access RDS Instances, select a region at the top, and then click the ID of the target RDS instance.
  2. In the left-side navigation pane, click Database Proxy.
  3. On the Proxy Terminal (Original Read/Write Splitting) tab, click Configure Proxy Terminal.
  4. In the dialog box that appears, configure the following parameters and click OK.
    Parameter Description
    Custom Proxy Terminal The name of the proxy terminal. The name can be up to 30 characters in length.
    Read/Write Attribute The read and write attribute of the proxy terminal. Valid values:
    • Read/Write (Primary Instance Connected to Receive Write Requests): The proxy terminal connects to the primary RDS instance and the read-only RDS instances, and can receive write requests. This is the default attribute.
    • 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 Pool Specifies whether to enable the connection pool feature and specifies the type of connection pool that you want to enable. Valid values:
    • Transaction Connection Pool: If tens of thousands of or more connections need to be established, select this value. This is the default value.
    • Session Connection Pool: If only short-lived connections over PHP need to be established, set this parameter to this value.
    • Disable Connection Pool: If you want to disable the connection pool feature, set this parameter to this value.

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

    Note This parameter is displayed only if you set the Read/Write Attribute parameter to Read/Write (Primary Instance Connected to Receive Write Requests).
    Latency Threshold The 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 routes 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 is displayed only if you set the Read/Write Attribute parameter to Read/Write (Primary Instance Connected to Receive Write Requests).
    Transaction Splitting Specifies whether to enable the transaction splitting feature. After you enable the transaction splitting feature, ApsaraDB RDS can route 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. This feature is enabled by default.
    Note This parameter is displayed only if you set the Read/Write Attribute parameter to Read/Write (Primary Instance Connected to Receive Write Requests).
    Read Weight Distribution The 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. The read weight of a read-only RDS instance defaults to 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 open. Only the requests that are sent over new connections are routed based on the new weights.

After you configure a proxy terminal, you must add the specified endpoint of the proxy terminal to your application. This endpoint is also known as a proxy endpoint. Then, ApsaraDB RDS can route write requests to the primary RDS instance and read requests to the read-only RDS instances based on the read weights of these instances.

Step 3: Optional. Create a proxy terminal

Each RDS instance supports up to seven proxy terminals. You can create multiple proxy terminals, which help you apply different read and write policies to different clients.

Prerequisites

Multiple proxy instances are enabled, and the number of proxy instances that you enabled is greater than the number of proxy terminals that you created. For more information, see Adjust the number of dedicated proxy instances that are enabled on an ApsaraDB RDS for MySQL instance.

  1. Access RDS Instances, select a region at the top, and then click the ID of the target RDS instance.
  2. In the left-side navigation pane, click Database Proxy.
  3. In the upper-right corner of the page, click Create Proxy Terminal.

After you create a proxy terminal, you must add the specified endpoint of the proxy terminal to your application. This endpoint is also known as a proxy endpoint. Then, ApsaraDB RDS can route write requests to the primary RDS instance and read requests to the read-only RDS instances based on the read weights of these instances.

Related operations

Operation Description
ModifyDBProxy Enables or disables the dedicated proxy feature for an ApsaraDB RDS instance.
DescribeDBProxy Queries the details about the dedicated proxy of an ApsaraDB RDS instance.