Enabling Read/Write Splitting
You can enable database proxy for your RDS for MySQL instance to automatically forward read and write requests though a proxy address. To reduce read pressure of the primary instance, write requests are forwarded to the primary instance and read requests to read replicas based on the routing policy of the database proxy.
Enable Database Proxy
- Log in to the management console.
- Click
in the upper left corner and select a region and a project.
- Click Service List. Under Database, click Relational Database Service.
- On the Instances page, click the target instance name to go to the Basic Information page.
- In the navigation pane on the left, choose Database Proxy.
Alternatively, in the Connection Information area on the Basic Information page, click Apply next to the Read/Write Splitting Address field.
- On the displayed page, click Create Database Proxy.
- On the displayed page, set the required parameters and click Next.
Table 1 Parameter description Parameter
Description
Proxy Name
The proxy name must start with a letter and consist of 4 to 64 characters. Only letters (case-sensitive), digits, hyphens (-), and underscores (_) are allowed.
Role
- Read and write: Read and write requests are split.
- Read only: The proxy is not connected to your primary instance and cannot receive write requests.
Routing Policy
- Weighted: You can change the weights of your DB instance and read replicas after read/write splitting is enabled.
- Load balancing: If selected, to balance the load among read replicas, read requests are automatically distributed to multiple read replicas based on the number of active connections.
You can change the routing policy after the database proxy is created. For details, see Configuring the Delay Threshold and Routing Policy.
Read Requests Accepted by Primary DB Instance
This parameter is available only when Load balancing is selected.
- Yes: Read requests can be routed to both the primary instance and read replicas, which increases the load of the primary instance. Configure this parameter as required.
- No: Read requests are routed only to read replicas to offload read pressure from the primary instance.
New Instance Class
Select specifications for the proxy instance based on service requirements. You can change the specifications after the proxy instance is created. For details, see Changing the Instance Class of a DB Proxy Instance.
For details about performance metrics, see Table 2.
Proxy Nodes
Enter an integer from 2 to 8. You can change the nodes after the proxy instance is created. For details, see Changing the Number of Proxy Nodes.
You are advised to set proxy nodes to the quantity of read replicas, with one proxy node for one read replica.
Set Read Weight
This parameter is only available if Weighted is selected. Select the primary instance and read replicas to which you want to assign weights.
Rules for configuring read weights
- Read requests are allocated proportionate to the read weight you configure. For example, if you associate two read replicas with the proxy and set their read weights to 100 and 200, all read requests forwarded to the proxy are automatically routed to the read replicas in the ratio of 1:2 (the read weights for unselected instances is 0).
- A read replica can be associated with more than one proxy. To balance traffic among the read replicas of your primary instance, set read weights for them based on the existing proxies' weights and on the amount of traffic routed to the read replicas.
- You can change read weights of the primary instance and read replicas after read/write splitting is enabled. For details, see Configuring the Delay Threshold and Routing Policy.
Select DB Instances for Load Balancing
This parameter is available only when Load balancing is selected. Select the DB instances for load balancing.
After Load balancing is selected, the proxy forwards read requests to database nodes with fewer active connections.
You can change the DB instances for load balancing after read/write splitting is enabled. For details, see Configuring the Delay Threshold and Routing Policy.
- Confirm the database proxy configuration.
- To modify the configuration, click Previous.
- To submit the request, click Submit.
- View and manage the proxy on the Database Proxy page.
You can view the read/write splitting address on the Basic Information page. Read and write requests can be split through the read/write splitting address.
The read/write splitting address and the floating IP address of the DB instance are in the same VPC and subnet and are independent from each other.
- Enable Database Proxy