Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RU calcuation to explain docs #14956

Merged
merged 7 commits into from
Oct 17, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions sql-statements/sql-statement-explain-analyze.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,32 @@ RU:273.842670
>
> This value shows the actual RUs consumed by this execution. The same SQL statement might consume different amounts of RUs each time it is executed due to the effects of caching (for example, [coprocessor cache](/coprocessor-cache.md)).

The RU count can be calculated from the other values in `EXPLAIN ANALYZE`; specifically, the `executeInfo` block. For example, given:
hfxsd marked this conversation as resolved.
Show resolved Hide resolved

```
'executeInfo': 'time:2.55ms, loops:2, RU:0.329460, Get:{num_rpc:1, '
'total_time:2.13ms}, total_process_time: 231.5µs, '
'total_wait_time: 732.9µs, tikv_wall_time: 995.8µs, '
'scan_detail: {total_process_keys: 1, total_process_keys_size: '
'150, total_keys: 1, get_snapshot_time: 691.7µs, rocksdb: '
'{block: {cache_hit_count: 2, read_count: 1, read_byte: 8.19 '
'KB, read_time: 10.3µs}}}',
adamf-db marked this conversation as resolved.
Show resolved Hide resolved
```

The base costs are in [the pd source](https://github.com/tikv/pd/blob/aeb259335644d65a97285d7e62b38e7e43c6ddca/client/resource_group/controller/config.go#L58C19-L67) and the calculations are done in [model.go](https://github.com/tikv/pd/blob/54219d649fb4c8834cd94362a63988f3c074d33e/client/resource_group/controller/model.go#L107)
hfxsd marked this conversation as resolved.
Show resolved Hide resolved

If you are using 7.1.x, the calculation is sum `BeforeKVRequest() + AfterKVRequest()` in `pd/pd-client/model.go`, that is:
adamf-db marked this conversation as resolved.
Show resolved Hide resolved

```
before :
adamf-db marked this conversation as resolved.
Show resolved Hide resolved
consumption.RRU += float64(kc.ReadBaseCost) -> kv.ReadBaseCost * rpc_nums
after:
consumption.RRU += float64(kc.ReadBytesCost) * readBytes -> kc.ReadBytesCost * total_process_keys_size
consumption.RRU += float64(kc.CPUMsCost) * kvCPUMs -> kc.CPUMsCost * total_process_time
```

For writes & batch gets the calculation is similar with different base values.
hfxsd marked this conversation as resolved.
Show resolved Hide resolved

### Other common execution information

The Coprocessor operators usually contain two parts of execution time information: `cop_task` and `tikv_task`. `cop_task` is the time recorded by TiDB, and it is from the moment that the request is sent to the server to the moment that the response is received. `tikv_task` is the time recorded by TiKV Coprocessor itself. If there is much difference between the two, it might indicate that the time spent waiting for the response is too long, or the time spent on gRPC or network is too long.
Expand Down