Enable and configure database proxy

更新时间:
复制 MD 格式

ApsaraDB MyBase for MySQL provides a database proxy service that supports read/write splitting.

Prerequisites

Billing

For more information, see Database proxy pricing.

Procedure

Step 1: Enable the database proxy

  1. Log on to the ApsaraDB MyBase console.

  2. In the upper-left corner of the page, select a region.

  3. In the left-side navigation pane, choose Instances > MySQL.

  4. Find the target primary instance and click Details in the Actions column.

  5. In the left-side navigation pane, click Database Proxy and then click Enable Proxy.

  6. Click Enable Now. In the dialog box that appears, set the number of proxy instances and click Enable Now.

    Note
    • The recommended number of proxy instances is one-eighth of the total number of CPU cores of the primary instance and its read-only instances, rounded up to the nearest integer. The maximum is 60. For example, if a primary instance has 8 CPU cores and a read-only instance has 4 CPU cores, the recommended number is 2 (calculated as (8 + 4) / 8 and rounded up).

    • When you release the primary instance, the database proxy is also released automatically, and billing stops.

    After you enable the database proxy, you can view its basic information on the Proxy Service tab.

    Category

    Parameter

    Description

    Proxy Service

    Status

    The status of the database proxy.

    Instance ID

    The ID of the primary instance.

    Number of Associated Proxy Instances

    The number of proxy instances associated with the proxy endpoint. You can add more proxy instances to improve the proxy throughput.

    Proxy Endpoint

    Proxy Terminal

    The name of the proxy terminal. You can create multiple proxy endpoints within one proxy terminal. For more information, see Introduction to read/write splitting.

    Proxy Endpoint

    The proxy endpoint. The database proxy provides a default proxy endpoint, to which the proxy terminal feature is bound. You can add, modify, or delete proxy endpoints. For more information, see Configure a database proxy endpoint.

    Port

    The port for the proxy endpoint.

    Note

    You can click Modify Port on the right to change the port. Valid values: 1000 to 5999.

    Network Address Type

    The network type of the proxy endpoint. You cannot change the network type.

    Proxy Instance

    Proxy Type

    Currently, only dedicated proxy is supported.

    Proxy Specifications

    The specifications of the proxy instance. Currently, only 2-core CPU and 4 GB memory are supported.

    Number of Instances

    The number of proxy instances. Multiple proxy instances provide load balancing. You can enable up to 60 proxy instances.

    Note

    The recommended number of proxy instances is calculated by using the following formula: (Number of CPU cores of the primary instance + Total number of CPU cores of all its read-only instances) / 8. The result is rounded up to the nearest integer. You can enable a maximum of 60 proxy instances.

    For example, if the primary instance has an 8-core CPU and it has one read-only instance with a 4-core CPU, then the recommended number of proxies is (8+4)/8 ≈ 2.

Step 2: Configure a proxy terminal

After enabling the database proxy, you must configure a proxy terminal to use its core features.

  1. On the Database Proxy page, click the Proxy Terminal (formerly Read/Write Splitting) tab.

  2. Click Configure Proxy Terminal and configure the following parameters.

    Parameter

    Description

    Custom Proxy Terminal

    The name of the proxy terminal. The name can be up to 30 characters long.

    Read/Write Attribute

    The read/write mode.

    • Read/Write (Default): Connects to both the primary and read-only instances and accepts write requests.

    • Read-only: Connects only to read-only instances and does not accept write requests.

    For more information, see Introduction to read/write splitting.

    Connection Pool

    The connection pool type for the proxy endpoint:

    • Transaction-level connection pool (Default): Suitable for scenarios with a large number of connections, such as tens of thousands.

    • Session-level connection pool: Suitable for scenarios with short-lived connections, such as PHP applications.

    • Disable Connection Pool: Disables the connection pool.

    For more information, see Configure the connection pool type.

    Note

    This parameter is available only when Read/Write Attribute is set to Read/Write.

    Latency Threshold

    The maximum allowed replication latency between the primary instance and a read-only instance. If the latency of a read-only instance exceeds this threshold, read requests are not routed to the instance, regardless of its weight.

    Valid values: 0 to 3,600 seconds. Due to the nature of SQL execution, read-only instances may experience replication delays. We recommend that you set this value to at least 30 seconds.

    Note

    This parameter is available only when Read/Write Attribute is set to Read/Write.

    Transaction Splitting

    Enables or disables transaction splitting. When enabled, this feature routes read requests that occur before any write operations in a transaction to read-only instances. This reduces the load on the primary instance. This feature is enabled by default.

    Note

    This parameter is available only when Read/Write Attribute is set to Read/Write.

    For more information, see Transaction splitting.

    Read Weight Allocation

    The higher the read weight of an instance, the more read requests it processes. For example, assume that a primary instance has three read-only instances. The read weights for the primary instance and the three read-only instances are set to 0, 100, 200, and 200. In this case, the primary instance does not process read requests, but write requests are still automatically routed to it. The three read-only instances process read requests at a ratio of 1:2:2.

    • System-assigned: The system automatically allocates a read weight to each instance based on its specifications. Newly added read-only instances are automatically included in the read/write splitting configuration with a system-assigned weight.

    • Custom: Manually set the read weight for each instance. Valid values: 0 to 10000. Newly added read-only instances receive a default read weight of 0, which you must then adjust manually.

    Note

    Changes take effect immediately for new connections without interrupting existing ones.

  3. Click OK.

API reference

API

Description

ModifyDBProxy

Enables or disables the database proxy feature.

DescribeDBProxy

Queries the details of a database proxy.

ModifyDBProxyEndpoint

Configures a database proxy terminal.