Skip to content

Commit

Permalink
Update tidb-resource-control.md
Browse files Browse the repository at this point in the history
  • Loading branch information
hfxsd committed Jul 3, 2023
1 parent 9438200 commit e578bb4
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions tidb-resource-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,46 @@ 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 RU's consumed by a request depends on a variety of factors, such as the type of operation or the amount of data being retrieved or modified. Currently, the RU contains statistics for the following resources:

<table>
<thead>
<tr>
<th>Resource Type</th>
<th>RU Consumption</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="3">Read</td>
<td>2 storage read batches consume 1 RU</td>
</tr>
<tr>
<td>8 storage read requests consume 1 RU</td>
</tr>
<td>64 KiB read request payload consumes 1 RU</td>
<tr>
<td rowspan="3">Write</td>
<td>1 storage write batch consumes 1 RU * (the number of replicas)</td>
</tr>
<tr>
<td>1 storage write request consumes 1 RU</td>
</tr>
<tr>
<td>1 KiB write request payload consumes 1 RU</td>
</tr>
<tr>
<td>SQL CPU</td>
<td> 3 ms consumes 1 RU</td>
</tr>
</tbody>
</table>

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) and each replication operation is considered a different write operation.
> - In addition to queries executed by the user, RU can be consumed by background tasks, such as automated statistical information collection.
> - The preceding table lists only the resources involved in computing RUs for on-premises TiDB clusters, excluding the network and storage components. For TiDB Serverless RUs, see [TiDB Serverless Pricing Details](https://www.pingcap.com/tidb-cloud- serverless-pricing-details/).
## Parameters for resource control

Expand Down

0 comments on commit e578bb4

Please sign in to comment.