You can call the CalculateDBInstanceWeight operation to query the system-assigned read weights of a primary instance and its read-only instances.

When the read/write splitting feature is enabled, this operation is used to calculate system-assigned read weights. For more information about custom read weights, see DescribeDBInstanceNetInfo.

Before you call this operation, make sure that the following requirements are met:

  • The shared proxy feature is enabled for your ApsaraDB RDS for MySQL instance.
  • The instance must run one of the following database engine versions and RDS editions:
    • MySQL 5.7 on RDS High-availability Edition (with local SSDs)
    • MySQL 5.6
    • SQL Server on RDS Cluster Edition

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CalculateDBInstanceWeight

The operation that you want to perform. Set the value to CalculateDBInstanceWeight.

DBInstanceId String Yes rm-uf6wjk5xxxxxxx

The ID of the primary instance.

Response parameters

Parameter Type Example Description
RequestId String C816A4BF-A6EC-4722-95F9-2055859CCFD2

The ID of the request.

Items Array of DBInstanceWeight

An array that consists of the system-assigned read weights.

DBInstanceWeight
ReadonlyInstanceSQLDelayedTime String 30

The threshold for the latency of data replication from the primary instance to the read-only instances. The read-only instances start to synchronize data from the primary instance after the time specified by the ReadonlyInstanceSQLDelayedTime parameter elapses. Unit: seconds.

Weight String 100

The read weight that ApsaraDB RDS calculates in real time for the instance.

DBInstanceType String Master

The role of the instance. Valid values:

  • Master: primary instance
  • Readonly: read-only instance
DBInstanceId String rm-uf6wjk5xxxxxxx

The ID of instance.

Examples

Sample requests

http(s)://rds.aliyuncs.com/?Action=CalculateDBInstanceWeight
&DBInstanceId=rm-uf6wjk5xxxxxxx
&<Common request parameters>

Sample success response

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CalculateDBInstanceWeightResponse>
    <RequestId>4139E1C3-0480-5A50-B327-23E6B1028906</RequestId>
    <Items>
        <DBInstanceWeight>
            <Role>master</Role>
            <DBInstanceId>******</DBInstanceId>
            <DBInstanceType>Readonly</DBInstanceType>
            <Weight>400</Weight>
        </DBInstanceWeight>
        <DBInstanceWeight>
            <Role>master</Role>
            <DBInstanceId>******</DBInstanceId>
            <DBInstanceType>Master</DBInstanceType>
            <Weight>0</Weight>
        </DBInstanceWeight>
        <DBInstanceWeight>
            <Role>slave</Role>
            <DBInstanceId>******</DBInstanceId>
            <DBInstanceType>Master</DBInstanceType>
            <Weight>1600</Weight>
        </DBInstanceWeight>
    </Items>
</CalculateDBInstanceWeightResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "4139E1C3-0480-5A50-B327-23E6B1028906",
  "Items" : {
    "DBInstanceWeight" : [ {
      "Role" : "master",
      "DBInstanceId" : "******",
      "DBInstanceType" : "Readonly",
      "Weight" : "400"
    }, {
      "Role" : "master",
      "DBInstanceId" : "******",
      "DBInstanceType" : "Master",
      "Weight" : "0"
    }, {
      "Role" : "slave",
      "DBInstanceId" : "******",
      "DBInstanceType" : "Master",
      "Weight" : "1600"
    } ]
  }
}

Error codes

For a list of error codes, visit the API Error Center.