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 RDS instance and meets the following requirements:
    Major engine versionRDS editionMinor engine version
    MySQL 8.0RDS Enterprise Edition20191204 or later
    RDS High-availability Edition20190915 or later
    RDS Cluster EditionNo requirements
    MySQL 5.7RDS Enterprise Edition20191128 or later
    RDS High-availability Edition20190925 or later
    RDS Cluster EditionNo requirements
    MySQL 5.6RDS High-availability Edition20200229 or later
    Note You can go to the Basic Information page of your RDS instance to obtain the preceding information. In the Configuration Information section of the page, you can check whether Upgrade Kernel Version is displayed. If Upgrade Kernel Version is displayed, click Upgrade Kernel Version to view and update the minor engine version of your RDS instance. If Upgrade Kernel Version 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.
  • If you use an RDS edition other than RDS Cluster Edition, a read-only RDS instance is created for your RDS instance. For more information, see Create a read-only ApsaraDB RDS for MySQL instance. If you use RDS Cluster Edition, you can use the primary and secondary nodes in your RDS cluster to implement read/write splitting.
  • 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 the dedicated proxy feature of ApsaraDB RDS for MySQL.

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
    • 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.

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 of the page that appears, click Configure Proxy Terminal.
  4. 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.

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 proxies 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.
  4. 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. This is the default value.
    • Session Connection Pool: If only short-lived connections over PHP need to be established, select this value.
    • Disable Connection Pool: If you want to disable the connection pool feature, select this 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.

Related operations

OperationDescription
ModifyDBProxyEnables or disables the dedicated proxy feature for an instance.
DescribeDBProxyQueries the details of the dedicated proxy of an instance.