Help Center/ Distributed Database Middleware/ User Guide/ Data Nodes/ Configuring Read/Write Splitting
Updated on 2024-04-01 GMT+08:00

Configuring Read/Write Splitting

Read/Write splitting offloads read requests from associated primary DB instances to its read replicas at a ratio, improving processing of read/write transactions. This function is transparent to applications, and you do not need to modify service code. Configure read weights of primary instances and their read replicas on the DDM console, and read traffic will be distributed at the preset ratio and write traffic will be forwarded to the primary instances by default. The ratio is generally based on service requirements and loads of associated data nodes.

Data is asynchronously replicated from the primary instance to read replicas, and there is a delay between them in milliseconds. Set weights of the primary instance and its read replicas to 0 and 100, respectively, that is, distribute all read requests to read replicas if sub-second latency is allowed for read requests and these requests require high query costs that may impact read/write transactions. In other scenarios, adjust the ratio based on service requirements.

Precautions

  • If the DDM kernel version is 3.1.0 or later, you need to manually enable read/write splitting and then adjust read weights of your primary instance and read replicas.
  • If the DDM kernel version is earlier than 3.1.0, read/write splitting is enabled by default. You just need to adjust read weights of your primary instance and read replicas.
  • The SELECT statements that contain hints or modify data in transactions are all executed by the primary instance.
  • If the primary instance becomes faulty and parameter Seconds_Behind_Master on its read replicas is set to NULL, read-only requests are still forwarded to the primary instance. Recover the faulty instance as soon as possible.

Prerequisites

  • You have bought a DDM instance and a data node with read replicas.
  • You have created a schema.

Procedure

  1. Log in to the DDM console.
  2. Locate the DDM instance that you want to configure read/write splitting for and click its name.
  3. In the navigation pane on the left, choose Data Nodes.
  4. Enabling read/write splitting affects only the nodes in read/write groups.

    • If the DDM kernel version is 3.1.0 or later, you need to manually enable read/write splitting by referring to Enabling Read/Write Splitting. Then, go to 5.
    • If the kernel version is earlier than 3.1.0, read/write splitting is enabled by default. Skip this step and go to 5.

    You can create a read-only group and use the private IP address of the read-only group to process read requests without enabling read/write splitting. For details, see Creating a Read-Only Group.

  5. Configure read weights.

    For details, see Configuring Read Weights.