This topic describes how to verify read/write splitting on an ApsaraDB RDS for MySQL instance that runs RDS High-availability Edition. In this topic, an Elastic Compute Service (ECS) instance is connected to the RDS instance over an internal network.
Prerequisites
- A primary RDS instance that runs RDS High-availability Edition is created.
- A read-only RDS instance is created for the primary RDS instance. For more information, see Create a read-only ApsaraDB RDS for MySQL instance.
- At least one database that contains at least one table is created on the RDS instance. A test account is created for the RDS instance. The test account can be a standard account or a privileged account. For more information, see Create databases and accounts for an ApsaraDB RDS for MySQL instance. Note
- If you create a standard account, you must grant the standard account the Read/Write (DDL + DML) permissions on the required database.
- In this example, a database named testdb01, a table named products, and a test account named cxx1 are created.
- An IP address whitelist is configured for the RDS instance. For more information, see Configure an IP address whitelist for an ApsaraDB RDS for MySQL instance.
- The ECS instance that you connected to the RDS instance resides in the same virtual private cloud (VPC) as the RDS instance. The MySQL client is installed on the ECS instance.
- The database proxy feature is enabled for the RDS instance.
- The SQL Explorer and Audit feature is enabled for the RDS instance. Note You are charged for the database proxy and SQL Explorer and Audit features. For more information about how to enable the features and the billing rules of the features, see Enable and configure the dedicated proxy feature for an ApsaraDB RDS for MySQL instance and Use the SQL Explorer and Audit feature on an ApsaraDB RDS for MySQL instance.
Background information
The read/write splitting capability of the database proxy feature helps automatically forward write requests to the primary RDS instance and read requests to the read-only RDS instance based on the read weights that you specify. This helps offload read requests from the primary RDS instance. For more information, see What are database proxies? After you enable and configure the database proxy feature, you can use the method that is described in this topic to check whether read and write requests are forwarded based on the read weights that you specified.
Verification method
In this example, an ECS instance is connected to the RDS instance over an internal network. To check whether read/write splitting is implemented, you can perform the following steps:
- In the ApsaraDB RDS console, set the weight of the read-only RDS instance to a multiple of 100 and the weight of the primary RDS instance to 0. All read requests are forwarded to the read-only RDS instance only when you set the weight of the primary RDS instance to 0. In this example, the weight of the read-only RDS instance is set to 10000, and the weight of the primary RDS instance is set to 0.
- Use the test account to connect the ECS instance to the RDS instance by using the database proxy endpoint, and then perform read operations. On the SQL Explorer and Audit page of the ApsaraDB RDS console, view the records of SQL statements that are executed on the primary RDS instance and read-only RDS instance.
- Use the test account to connect the ECS instance to the RDS instance by using the database proxy endpoint, and then perform write operations. On the SQL Explorer and Audit page of the ApsaraDB RDS console, view the records of SQL statements that are executed on the primary RDS instance and read-only RDS instance.
- Determine the RDS instance that processes the read requests and the RDS instance that processes the write requests based on the execution records of SQL statements. Then, determine whether read/write splitting is implemented.
Procedure
- In the ApsaraDB RDS console, specify read weights for the primary RDS instance and read-only RDS instance.
- Verify the processing of read requests.
- Verify the processing of write requests. Note In the preceding step, you have connected the ECS instance to the RDS instance and accessed the testdb01 database. For more information, see Step 2.
Verification conclusion
If the weight of the read-only RDS instance is set to 10000 and the weight of the primary RDS instance is set to 0, all write requests are processed by the primary RDS instance, and all read requests are processed by the read-only RDS instance. This way, read/write splitting is implemented.