From 743190858438eded9929b1fd27279c2ef1e07813 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Tue, 4 Jul 2023 10:53:13 +0800 Subject: [PATCH] resource_control: ru consistent with serverless (#14081) --- tidb-resource-control.md | 55 ++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/tidb-resource-control.md b/tidb-resource-control.md index 9fee7b5389199..1aa9d067bfe8e 100644 --- a/tidb-resource-control.md +++ b/tidb-resource-control.md @@ -43,21 +43,48 @@ Currently, the resource control feature has the following limitations: ## What is Request Unit (RU) -Request Unit (RU) is a unified abstraction unit in TiDB for system resources, which currently includes CPU, IOPS, and IO bandwidth metrics. The consumption of these three metrics is represented by RU according to a certain ratio. +Request Unit (RU) is a unified abstraction unit in TiDB for system resources, which currently includes CPU, IOPS, and IO bandwidth metrics. It is used to indicate the amount of resources consumed by a single request to the database. The number of RUs consumed by a request depends on a variety of factors, such as the type of operations, and the amount of data being queried or modified. Currently, the RU contains consumption statistics for the resources in the following table: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Resource typeRU consumption
Read2 storage read batches consume 1 RU
8 storage read requests consume 1 RU
64 KiB read request payload consumes 1 RU
Write1 storage write batch consumes 1 RU for each replica
1 storage write request consumes 1 RU
1 KiB write request payload consumes 1 RU
SQL CPU 3 ms consumes 1 RU
-The following table shows the consumption of TiKV storage layer CPU and IO resources by user requests and the corresponding RU weights. - -| Resource | RU Weight | -|:----------------|:-----------------| -| CPU | 1/3 RU per millisecond | -| Read IO | 1/64 RU per KB | -| Write IO | 1 RU/KB | -| Basic overhead of a read request | 0.25 RU | -| Basic overhead of a write request | 1.5 RU | - -Based on the above table, assuming that the TiKV time consumed by a resource group is `c` milliseconds, `r1` times of requests read `r2` KB data, `w1` times of write requests write `w2` KB data, and the number of non-witness TiKV nodes in the cluster is `n`. Then, the formula for the total RUs consumed by the resource group is as follows: - -`c`\* 1/3 + (`r1` \* 0.25 + `r2` \* 1/64) + (1.5 \* `w1` + `w2` \* 1 \* `n`) +> **Note:** +> +> - Each write operation is eventually replicated to all replicas (by default, TiKV has 3 replicas). Each replication operation is considered a different write operation. +> - In addition to queries executed by users, RU can be consumed by background tasks, such as automatic statistics collection. +> - The preceding table lists only the resources involved in RU calculation for TiDB Self-Hosted clusters, excluding the network and storage consumption. For TiDB Serverless RUs, see [TiDB Serverless Pricing Details](https://www.pingcap.com/tidb-cloud-serverless-pricing-details/). ## Parameters for resource control