All Products
Search
Document Center

ApsaraDB RDS:Enable and configure the dedicated proxy feature

Last Updated:Oct 27, 2023

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 capabilities 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 version

    RDS edition

    Minor engine version

    MySQL 8.0

    RDS Enterprise Edition

    20191204 or later

    RDS High-availability Edition

    20190915 or later

    RDS Cluster Edition

    No requirements

    MySQL 5.7

    RDS Enterprise Edition

    20191128 or later

    RDS High-availability Edition

    20190925 or later

    RDS Cluster Edition

    No requirements

    MySQL 5.6

    RDS High-availability Edition

    20200229 or later

    Note

    You can go to the Basic Information page of your RDS instance to view 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 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.

  • If you use an RDS edition other than RDS Cluster Edition, a read-only RDS instance must be 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 Hangzhou Zone C or Hangzhou Zone D.

    Note

    If your RDS instance resides in these zones, 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. Go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.
  2. In the left-side navigation pane of the page that appears, click Database Proxy.

  3. On the page that appears, click Enable Proxy. In the dialog box that appears, configure the Network Type and Proxy Instances parameters and click Enable Now.

      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 calculate the number of proxy instances by using the following formula: (Number of CPU cores that are configured for your primary RDS instance + Number of CPU cores that are configured for all read-only RDS instances of the primary RDS instance)/8. If the result is not an integer, you must round up the result to the nearest integer. Up to 16 proxy instances are supported.

      For example, if your RDS instance has 8 CPU cores and its read-only RDS instances have 4 CPU cores, the recommended number of proxy instances is 2 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 capabilities that are provided by the dedicated proxy feature, you must configure a proxy terminal for your RDS instance.

  1. Go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.
  2. In the left-side navigation pane of the page that appears, click Database Proxy.

  3. On the Proxy Terminal (Original Read/Write Splitting) tab of the page that appears, click Configure Proxy Terminal.

  4. 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 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 Pool

    Specifies whether to enable connection pooling. If you enable connection pooling, this parameter also specifies the connection pooling type 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 connection pooling. 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 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, the system 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 Splitting

    Specifies whether to enable transaction splitting. After you enable transaction splitting, the system 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 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, the system automatically assigns a read weight to the read-only RDS instance. You do not need to manually specify a read weight for the read-only RDS instance. For more information, see Default read weights.

    • 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
    • You cannot specify weights for read-only RDS instances that have the data replication latency specified. For more information, see Set the data replication latency of a read-only ApsaraDB RDS for MySQL instance

    • After you modify 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, the read weights that you specify indicate the read weights of the primary and secondary nodes in the 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, the system 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 展开 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. Go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.
  2. In the left-side navigation pane of the page that appears, click Database Proxy.

  3. In the upper-right corner of the page, click Create Proxy Terminal.

  4. 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 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 Pool

    Specifies whether to enable connection pooling. If you enable connection pooling, this parameter also specifies the connection pooling type 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: 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 connection pooling.

    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 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, the system 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 Splitting

    Specifies whether to enable transaction splitting. After you enable transaction splitting, the system 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 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, the system automatically assigns a read weight to the read-only RDS instance. You do not need to manually specify a read weight for the read-only RDS instance. For more information, see Default read weights.

    • 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
    • You cannot specify weights for read-only RDS instances that have the data replication latency specified. For more information, see Set the data replication latency of a read-only ApsaraDB RDS for MySQL instance

    • After you modify 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, the read weights that you specify indicate the read weights of the primary and secondary nodes in the 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, the system 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.

Processing logic based on the read and write attributes

Read/Write Attribute

Method to specify read weights

Weight of a primary RDS instance

Normal

After the last read-only RDS instance is deleted

After all read-only RDS instances are faulty

Read-only

Automatic or Custom

You cannot specify a read weight for your primary RDS instance.

Primary RDS instance: does not process read or write requests. In this case, no request forwarding is performed.

Proxy terminal: processes only read requests.

Primary RDS instance: does not process read or write requests. In this case, no request forwarding is performed.

Proxy terminal: does not process read or write requests. In this case, a connection error occurs.

Primary RDS instance: does not process read or write requests. In this case, no request forwarding is performed.

Proxy terminal: does not process read or write requests. In this case, a connection error occurs.

Read and write

Automatic

A weight equal to 0

For more information, see Rules of weight allocation by the system.

Primary RDS instance: processes only write requests.

Proxy terminal: processes read and write requests.

Primary RDS instance: processes read and write requests.

Proxy terminal: processes read and write requests.

Primary RDS instance: processes read and write requests.

Proxy terminal: processes read and write requests.

Custom

A weight greater than 0

Primary RDS instance: processes read and write requests.

Proxy terminal: processes read and write requests.

Primary RDS instance: processes read and write requests.

Proxy terminal: processes read and write requests.

Primary RDS instance: processes read and write requests.

Proxy terminal: processes read and write requests.

A weight equal to 0

Primary RDS instance: processes only write requests.

Proxy terminal: processes read and write requests.

Primary RDS instance: processes read and write requests.

Proxy terminal: processes read and write requests.

Primary RDS instance: processes read and write requests.

Proxy terminal: processes read and write requests.

Note
  • No request forwarding: indicates that the primary RDS instance is not involved in read-only request forwarding.

  • Connection error: indicates that a connection error is reported when the proxy terminal does not process read or write requests.

  • In read/write mode, when the weight of the primary RDS instance is set to 0, read requests are not forwarded to the primary RDS instance by default. However, if read-only RDS instances of the primary RDS instance are faulty, a forceful hint is specified, or transaction splitting is enabled, the read requests are forwarded to the primary RDS instance.

Related operations

Operation

Description

ModifyDBProxy

Enables or disables the dedicated proxy feature for an instance.

DescribeDBProxy

Queries the details of the dedicated proxy of an instance.