CALIBRATE RESOURCE

The CALIBRATE RESOURCE statement is used to estimate and output the 'Request Unit (RU)` capacity of the current cluster.

Synopsis

CalibrateResourceStmt
CALIBRATERESOURCEWorkloadOption
WorkloadOption
WORKLOADTPCCOLTP_READ_WRITEOLTP_READ_ONLYOLTP_WRITE_ONLYSTART_TIMETIMESTAMPDURATIONstringLitEND_TIMETIMESTAMP

Privileges

To execute this command, make sure that the following requirements are met:

  • You have enabled tidb_enable_resource_control.
  • The user has SUPER or RESOURCE_GROUP_ADMIN privilege.
  • The user has the SELECT privilege for all tables in the METRICS_SCHEMA schema.

Methods for estimating capacity

TiDB provides two methods for estimation:

Estimate capacity based on actual workload

If your application is already running in a production environment, or you can run actual business tests, it is recommended to use the actual workload over a period of time to estimate the total capacity. To improve the accuracy of the estimation, observe the following constraints:

  • Use the START_TIME parameter to specify the time point at which the estimation starts, in the format of 2006-01-02 15:04:05. The default estimation end time is the current time.
  • After specifying the START_TIME parameter, you can use the END_TIME parameter to specify the estimation end time, or use the DURATION parameter to specify the estimation time window from START_TIME.
  • The time window ranges from 10 minutes to 24 hours.
  • In the specified time window, if the CPU utilization of TiDB and TiKV is too low, you cannot estimate the capacity.

Estimate capacity based on hardware deployment

This method mainly estimates capacity based on the current cluster configuration, combined with the empirical values observed for different workloads. Because different types of workloads require different ratios of hardware, the output capacity of the same configuration of hardware might be different. The WORKLOAD parameter here accepts the following different workload types. The default value is TPCC.

  • TPCC: applies to workloads with heavy data write. It is estimated based on a workload model similar to TPC-C.
  • OLTP_WRITE_ONLY: applies to workloads with heavy data write. It is estimated based on a workload model similar to sysbench oltp_write_only.
  • OLTP_READ_WRITE: applies to workloads with even data read and write. It is estimated based on a workload model similar to sysbench oltp_read_write.
  • OLTP_READ_ONLY: applies to workloads with heavy data read. It is estimated based on a workload model similar to sysbench oltp_read_only.

Examples

Specify the start time START_TIME and the time window DURATION to view the RU capacity according to the actual workload.

CALIBRATE RESOURCE START_TIME '2023-04-18 08:00:00' DURATION '20m'; +-------+ | QUOTA | +-------+ | 27969 | +-------+ 1 row in set (0.01 sec)

Specify the start time START_TIME and the end time END_TIME to view the RU capacity according to the actual workload.

CALIBRATE RESOURCE START_TIME '2023-04-18 08:00:00' END_TIME '2023-04-18 08:20:00'; +-------+ | QUOTA | +-------+ | 27969 | +-------+ 1 row in set (0.01 sec)

When the time window range DURATION does not fall between 10 minutes and 24 hours, an error occurs.

CALIBRATE RESOURCE START_TIME '2023-04-18 08:00:00' DURATION '25h'; ERROR 1105 (HY000): the duration of calibration is too long, which could lead to inaccurate output. Please make the duration between 10m0s and 24h0m0s CALIBRATE RESOURCE START_TIME '2023-04-18 08:00:00' DURATION '9m'; ERROR 1105 (HY000): the duration of calibration is too short, which could lead to inaccurate output. Please make the duration between 10m0s and 24h0m0s

When the workload within the time window is too low, an error occurs.

CALIBRATE RESOURCE START_TIME '2023-04-18 08:00:00' DURATION '60m'; ERROR 1105 (HY000): The workload in selected time window is too low, with which TiDB is unable to reach a capacity estimation; please select another time window with higher workload, or calibrate resource by hardware instead

The capacity estimation function requires monitoring metrics data according to the actual workload, including resource_manager_resource_unit, process_cpu_usage, tikv_cpu_quota, and tidb_server_maxprocs. If the corresponding monitor data is empty, an error occurs with the corresponding monitor item name, as shown in the following example. When there is no workload and resource_manager_resource_unit is empty, this error also occurs.

CALIBRATE RESOURCE START_TIME '2023-04-18 08:00:00' DURATION '60m'; Error 1105 (HY000): metrics 'resource_manager_resource_unit' is empty

TiKV does not monitor CPU usage on macOS. The following error occurs when you estimate capacity based on actual workload on macOS:

CALIBRATE RESOURCE START_TIME '2023-04-18 08:00:00' DURATION '60m'; ERROR 1105 (HY000): metrics 'process_cpu_usage' is empty

Specify WORKLOAD to view the RU capacity. The default value is TPCC.

CALIBRATE RESOURCE; +-------+ | QUOTA | +-------+ | 190470 | +-------+ 1 row in set (0.01 sec) CALIBRATE RESOURCE WORKLOAD OLTP_WRITE_ONLY; +-------+ | QUOTA | +-------+ | 27444 | +-------+ 1 row in set (0.01 sec)

Was this page helpful?