如何理解资源管控 (Resource Control) 中的RU

【 TiDB 使用环境】 Poc
【 TiDB 版本】8.0.11-TiDB-v8.1.0
在官网文档资源管控章节:https://docs.pingcap.com/zh/tidb/stable/tidb-resource-control 中关于 Request Unit部分是这么介绍:

  • 在tidb-server侧做CPU运算(排序操作),是否会增大RU消耗?
# tikv扫描全表,topN不下推,在tidb-server中做大量数据排序,观察tidb-server消耗较多CPU对RU的影响。
mysql> explain analyze select c_name from customer order by C_ADDRESS limit 1000000,10;
+----------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+----------+---------+
| id                         | estRows    | actRows | task      | access object  | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                             | operator info             | memory   | disk    |
+----------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+----------+---------+
| Limit_9                    | 10.00      | 10      | root      |                | time:2.8s, loops:2, RU:4873.498317                                                                                                                                                                                                                                                                                                                                                                                                                         | offset:1000000, count:10  | N/A      | N/A     |
| └─Sort_10                  | 1000010.00 | 1000010 | root      |                | time:2.8s, loops:977                                                                                                                                                                                                                                                                                                                                                                                                                                       | tpch10.customer.c_address | 108.5 MB | 0 Bytes |
|   └─TableReader_13         | 1500000.00 | 1500000 | root      |                | time:243.8ms, loops:1469, cop_task: {num: 54, max: 42.8ms, min: 467.2µs, avg: 13.3ms, p95: 37.7ms, max_proc_keys: 50144, p95_proc_keys: 50144, tot_proc: 571.4ms, tot_wait: 3.41ms, copr_cache: disabled, build_task_duration: 11µs, max_distsql_concurrency: 3}, rpc_info:{Cop:{num_rpc:54, total_time:719.3ms}}                                                                                                                                          | data:TableFullScan_12     | 8.47 MB  | N/A     |
|     └─TableFullScan_12     | 1500000.00 | 1500000 | cop[tikv] | table:customer | tikv_task:{proc max:38ms, min:0s, avg: 9.52ms, p80:16ms, p95:33ms, iters:1679, tasks:54}, scan_detail: {total_process_keys: 1500000, total_process_keys_size: 305225771, total_keys: 1500054, get_snapshot_time: 1.33ms, rocksdb: {key_skipped_count: 1500000, block: {cache_hit_count: 10250}}}, time_detail: {total_process_time: 571.4ms, total_suspend_time: 1.45ms, total_wait_time: 3.41ms, total_kv_read_wall_time: 514ms, tikv_wall_time: 584.3ms} | keep order:false          | N/A      | N/A     |
+----------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+----------+---------+
4 rows in set (2.80 sec)

# tikv扫描全表,topN不下推,在tidb-server中做少量数据排序,观察tidb-server消耗较少CPU对RU的影响
mysql> explain analyze select c_name from customer order by C_ADDRESS limit 10,10;
+----------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+----------+---------+
| id                         | estRows    | actRows | task      | access object  | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                             | operator info             | memory   | disk    |
+----------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+----------+---------+
| Limit_9                    | 10.00      | 10      | root      |                | time:2.49s, loops:2, RU:4881.730370                                                                                                                                                                                                                                                                                                                                                                                                                        | offset:10, count:10       | N/A      | N/A     |
| └─Sort_10                  | 20.00      | 20      | root      |                | time:2.49s, loops:1                                                                                                                                                                                                                                                                                                                                                                                                                                        | tpch10.customer.c_address | 108.5 MB | 0 Bytes |
|   └─TableReader_13         | 1500000.00 | 1500000 | root      |                | time:234ms, loops:1469, cop_task: {num: 54, max: 47.7ms, min: 574.8µs, avg: 13.6ms, p95: 45.2ms, max_proc_keys: 50144, p95_proc_keys: 50144, tot_proc: 596.1ms, tot_wait: 3.83ms, copr_cache: disabled, build_task_duration: 9.68µs, max_distsql_concurrency: 3}, rpc_info:{Cop:{num_rpc:54, total_time:734.4ms}}                                                                                                                                          | data:TableFullScan_12     | 5.70 MB  | N/A     |
|     └─TableFullScan_12     | 1500000.00 | 1500000 | cop[tikv] | table:customer | tikv_task:{proc max:42ms, min:0s, avg: 9.59ms, p80:15ms, p95:38ms, iters:1679, tasks:54}, scan_detail: {total_process_keys: 1500000, total_process_keys_size: 305225771, total_keys: 1500054, get_snapshot_time: 1.14ms, rocksdb: {key_skipped_count: 1500000, block: {cache_hit_count: 10250}}}, time_detail: {total_process_time: 596.1ms, total_suspend_time: 1.43ms, total_wait_time: 3.83ms, total_kv_read_wall_time: 518ms, tikv_wall_time: 607.5ms} | keep order:false          | N/A      | N/A     |
+----------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------------------------+----------+---------+
4 rows in set (2.49 sec)

从测试来看在tidb-server做了较多数据量的排序,但是RU消耗基本不变。

  • 在tikv侧做CPU运算(排序操作),是否会增大RU消耗?
# tikv扫描全表,topN下推,在tidb中做大量排序,tidb侧少量排序,观察tikv消耗较多CPU对RU的影响。
mysql> explain analyze select  /*+ LIMIT_TO_COP() */ c_name from customer order by C_ADDRESS limit 1000000,10;
+------------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------+---------+------+
| id                           | estRows    | actRows | task      | access object  | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                             | operator info                                       | memory  | disk |
+------------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------+---------+------+
| Projection_7                 | 10.00      | 10      | root      |                | time:3.15s, loops:2, RU:4871.174181, Concurrency:OFF                                                                                                                                                                                                                                                                                                                                                                                                       | tpch10.customer.c_name                              | 1.49 KB | N/A  |
| └─TopN_8                     | 10.00      | 10      | root      |                | time:3.15s, loops:2                                                                                                                                                                                                                                                                                                                                                                                                                                        | tpch10.customer.c_address, offset:1000000, count:10 | 90.4 MB | N/A  |
|   └─TableReader_15           | 1000010.00 | 1500000 | root      |                | time:170ms, loops:1469, cop_task: {num: 54, max: 48.3ms, min: 508.9µs, avg: 12.3ms, p95: 41.7ms, max_proc_keys: 50144, p95_proc_keys: 50144, tot_proc: 564.4ms, tot_wait: 3.11ms, copr_cache: disabled, build_task_duration: 9.48µs, max_distsql_concurrency: 3}, rpc_info:{Cop:{num_rpc:54, total_time:661.4ms}}                                                                                                                                          | data:TopN_14                                        | 11.3 MB | N/A  |
|     └─TopN_14                | 1000010.00 | 1500000 | cop[tikv] |                | tikv_task:{proc max:42ms, min:0s, avg: 9.48ms, p80:15ms, p95:38ms, iters:1679, tasks:54}, scan_detail: {total_process_keys: 1500000, total_process_keys_size: 305225771, total_keys: 1500054, get_snapshot_time: 1.09ms, rocksdb: {key_skipped_count: 1500000, block: {cache_hit_count: 10250}}}, time_detail: {total_process_time: 564.4ms, total_suspend_time: 27.5ms, total_wait_time: 3.11ms, total_kv_read_wall_time: 511ms, tikv_wall_time: 601.9ms} | tpch10.customer.c_address, offset:0, count:1000010  | N/A     | N/A  |
|       └─TableFullScan_13     | 1500000.00 | 1500000 | cop[tikv] | table:customer | tikv_task:{proc max:42ms, min:0s, avg: 9.46ms, p80:15ms, p95:38ms, iters:1679, tasks:54}                                                                                                                                                                                                                                                                                                                                                                   | keep order:false                                    | N/A     | N/A  |
+------------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------+---------+------+
5 rows in set (3.15 sec)

# tikv扫描全表,topN下推,在tikv中做少量排序,tidb侧少量排序,观察tikv消耗较少CPU对RU的影响。
mysql> explain analyze select  /*+ LIMIT_TO_COP() */ c_name from customer order by C_ADDRESS limit 10,10;
+------------------------------+------------+---------+-----------+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------+---------+------+
| id                           | estRows    | actRows | task      | access object  | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                                    | operator info                                  | memory  | disk |
+------------------------------+------------+---------+-----------+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------+---------+------+
| Projection_7                 | 10.00      | 10      | root      |                | time:278.2ms, loops:2, RU:4895.388275, Concurrency:OFF                                                                                                                                                                                                                                                                                                                                                                                                            | tpch10.customer.c_name                         | 1.54 KB | N/A  |
| └─TopN_8                     | 10.00      | 10      | root      |                | time:278.2ms, loops:2                                                                                                                                                                                                                                                                                                                                                                                                                                             | tpch10.customer.c_address, offset:10, count:10 | 1.59 KB | N/A  |
|   └─TableReader_15           | 20.00      | 60      | root      |                | time:278.2ms, loops:3, cop_task: {num: 3, max: 278.1ms, min: 215.6ms, avg: 237.7ms, p95: 278.1ms, max_proc_keys: 603265, p95_proc_keys: 603265, tot_proc: 709.8ms, tot_wait: 513.1µs, copr_cache: disabled, build_task_duration: 31.9µs, max_distsql_concurrency: 3}, rpc_info:{Cop:{num_rpc:3, total_time:713.2ms}}                                                                                                                                              | data:TopN_14                                   | 2.75 KB | N/A  |
|     └─TopN_14                | 20.00      | 60      | cop[tikv] |                | tikv_task:{proc max:277ms, min:214ms, avg: 236.3ms, p80:277ms, p95:277ms, iters:1466, tasks:3}, scan_detail: {total_process_keys: 1500000, total_process_keys_size: 305225771, total_keys: 1500003, get_snapshot_time: 374µs, rocksdb: {key_skipped_count: 1500000, block: {cache_hit_count: 9995}}}, time_detail: {total_process_time: 709.8ms, total_suspend_time: 1.52ms, total_wait_time: 513.1µs, total_kv_read_wall_time: 549ms, tikv_wall_time: 712.2ms}   | tpch10.customer.c_address, offset:0, count:20  | N/A     | N/A  |
|       └─TableFullScan_13     | 1500000.00 | 1500000 | cop[tikv] | table:customer | tikv_task:{proc max:212ms, min:146ms, avg: 183ms, p80:212ms, p95:212ms, iters:1466, tasks:3}                                                                                                                                                                                                                                                                                                                                                                      | keep order:false                               | N/A     | N/A  |
+------------------------------+------------+---------+-----------+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------+---------+------+
5 rows in set (0.28 sec)

从测试来看在tikv侧做了较多数据量的排序,但是RU消耗基本不变

  • 分析是否只和tikv侧的coprocessor到storage层的请求有关
# tikv全表扫描,不做排序,做谓词过滤,过滤后无记录数。
mysql> explain analyze select count(*) from customer where c_name='xxx';
+------------------------------+------------+---------+-----------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+-----------+------+
| id                           | estRows    | actRows | task      | access object  | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                                      | operator info                     | memory    | disk |
+------------------------------+------------+---------+-----------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+-----------+------+
| StreamAgg_20                 | 1.00       | 1       | root      |                | time:235.8ms, loops:2, RU:4867.325278                                                                                                                                                                                                                                                                                                                                                                                                                               | funcs:count(Column#11)->Column#9  | 388 Bytes | N/A  |
| └─TableReader_21             | 1.00       | 0       | root      |                | time:235.8ms, loops:1, cop_task: {num: 3, max: 235.8ms, min: 196.1ms, avg: 209.6ms, p95: 235.8ms, max_proc_keys: 603265, p95_proc_keys: 603265, tot_proc: 625.6ms, tot_wait: 445.7µs, copr_cache: disabled, build_task_duration: 11.4µs, max_distsql_concurrency: 3}, rpc_info:{Cop:{num_rpc:3, total_time:628.8ms}}                                                                                                                                                | data:StreamAgg_9                  | 367 Bytes | N/A  |
|   └─StreamAgg_9              | 1.00       | 0       | cop[tikv] |                | tikv_task:{proc max:235ms, min:194ms, avg: 208.7ms, p80:235ms, p95:235ms, iters:1466, tasks:3}, scan_detail: {total_process_keys: 1500000, total_process_keys_size: 305225771, total_keys: 1500003, get_snapshot_time: 362.6µs, rocksdb: {key_skipped_count: 1500000, block: {cache_hit_count: 9995}}}, time_detail: {total_process_time: 625.6ms, total_suspend_time: 1.03ms, total_wait_time: 445.7µs, total_kv_read_wall_time: 563ms, tikv_wall_time: 627.7ms}   | funcs:count(1)->Column#11         | N/A       | N/A  |
|     └─Selection_19           | 1.00       | 0       | cop[tikv] |                | tikv_task:{proc max:235ms, min:194ms, avg: 208.7ms, p80:235ms, p95:235ms, iters:1466, tasks:3}                                                                                                                                                                                                                                                                                                                                                                      | eq(tpch10.customer.c_name, "xxx") | N/A       | N/A  |
|       └─TableFullScan_18     | 1500000.00 | 1500000 | cop[tikv] | table:customer | tikv_task:{proc max:205ms, min:178ms, avg: 187.7ms, p80:205ms, p95:205ms, iters:1466, tasks:3}                                                                                                                                                                                                                                                                                                                                                                      | keep order:false                  | N/A       | N/A  |
+------------------------------+------------+---------+-----------+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------------------+-----------+------+
5 rows in set (0.24 sec)

# tikv全表扫描,不做排序,不做谓词过滤。
mysql> explain analyze select * from customer;
+-----------------------+------------+---------+-----------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+---------+------+
| id                    | estRows    | actRows | task      | access object  | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                         | operator info        | memory  | disk |
+-----------------------+------------+---------+-----------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+---------+------+
| TableReader_5         | 1500000.00 | 1500000 | root      |                | time:1.14s, loops:1469, RU:5319.041649, cop_task: {num: 54, max: 341.5ms, min: 836µs, avg: 57ms, p95: 322.5ms, max_proc_keys: 50144, p95_proc_keys: 50144, tot_proc: 1.91s, tot_wait: 30.3ms, copr_cache: disabled, build_task_duration: 13.4µs, max_distsql_concurrency: 3}, rpc_info:{Cop:{num_rpc:54, total_time:3.08s}}                                                                                                                            | data:TableFullScan_4 | 22.5 MB | N/A  |
| └─TableFullScan_4     | 1500000.00 | 1500000 | cop[tikv] | table:customer | tikv_task:{proc max:53ms, min:0s, avg: 15.5ms, p80:25ms, p95:52ms, iters:1679, tasks:54}, scan_detail: {total_process_keys: 1500000, total_process_keys_size: 305225771, total_keys: 1500054, get_snapshot_time: 1.51ms, rocksdb: {key_skipped_count: 1500000, block: {cache_hit_count: 10250}}}, time_detail: {total_process_time: 1.91s, total_suspend_time: 2.21ms, total_wait_time: 30.3ms, total_kv_read_wall_time: 837ms, tikv_wall_time: 2.06s} | keep order:false     | N/A     | N/A  |
+-----------------------+------------+---------+-----------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+---------+------+
2 rows in set (1.14 sec)

可以看到只要coprocessor到storage层的读取数据量一样,消耗的RU几乎一样。

  • 验证是否和扫描过的数据量(大小)有关
# 对全表做count操作,请求次数应和上面一样,但是每次只请求key,不请求value值,因此整体数据量是少的,所以RU:717.318402 
mysql> explain analyze select count(*) from customer;
+----------------------------+------------+---------+-----------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+-----------+------+
| id                         | estRows    | actRows | task      | access object  | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                                     | operator info                    | memory    | disk |
+----------------------------+------------+---------+-----------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+-----------+------+
| StreamAgg_16               | 1.00       | 1       | root      |                | time:118.2ms, loops:2, RU:717.318402                                                                                                                                                                                                                                                                                                                                                                                                                               | funcs:count(Column#11)->Column#9 | 388 Bytes | N/A  |
| └─TableReader_17           | 1.00       | 3       | root      |                | time:118.2ms, loops:2, cop_task: {num: 3, max: 118.1ms, min: 88.9ms, avg: 98.8ms, p95: 118.1ms, max_proc_keys: 603265, p95_proc_keys: 603265, tot_proc: 293.7ms, tot_wait: 471.1µs, copr_cache: disabled, build_task_duration: 10.9µs, max_distsql_concurrency: 3}, rpc_info:{Cop:{num_rpc:3, total_time:296.2ms}}                                                                                                                                                 | data:StreamAgg_8                 | 378 Bytes | N/A  |
|   └─StreamAgg_8            | 1.00       | 3       | cop[tikv] |                | tikv_task:{proc max:117ms, min:88ms, avg: 97.7ms, p80:117ms, p95:117ms, iters:1466, tasks:3}, scan_detail: {total_process_keys: 1500000, total_process_keys_size: 40500000, total_keys: 1500003, get_snapshot_time: 322.7µs, rocksdb: {key_skipped_count: 1500000, block: {cache_hit_count: 9995}}}, time_detail: {total_process_time: 293.7ms, total_suspend_time: 650.5µs, total_wait_time: 471.1µs, total_kv_read_wall_time: 293ms, tikv_wall_time: 295.2ms}    | funcs:count(1)->Column#11        | N/A       | N/A  |
|     └─TableFullScan_15     | 1500000.00 | 1500000 | cop[tikv] | table:customer | tikv_task:{proc max:117ms, min:88ms, avg: 97.7ms, p80:117ms, p95:117ms, iters:1466, tasks:3}                                                                                                                                                                                                                                                                                                                                                                       | keep order:false                 | N/A       | N/A  |
+----------------------------+------------+---------+-----------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+-----------+------+
4 rows in set (0.12 sec)

# 对全表做count操作,测试到storage层请求kv数据,RU:4816.295563
mysql> explain analyze select count(*) from customer where c_name !='xx';
+------------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+-----------+------+
| id                           | estRows    | actRows | task      | access object  | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                                   | operator info                    | memory    | disk |
+------------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+-----------+------+
| StreamAgg_20                 | 1.00       | 1       | root      |                | time:209.8ms, loops:2, RU:4816.295563                                                                                                                                                                                                                                                                                                                                                                                                                            | funcs:count(Column#11)->Column#9 | 388 Bytes | N/A  |
| └─TableReader_21             | 1.00       | 3       | root      |                | time:209.8ms, loops:2, cop_task: {num: 3, max: 209.7ms, min: 132.3ms, avg: 158.5ms, p95: 209.7ms, max_proc_keys: 603265, p95_proc_keys: 603265, tot_proc: 472.5ms, tot_wait: 427.5µs, copr_cache: disabled, build_task_duration: 10.3µs, max_distsql_concurrency: 3}, rpc_info:{Cop:{num_rpc:3, total_time:475.4ms}}                                                                                                                                             | data:StreamAgg_9                 | 411 Bytes | N/A  |
|   └─StreamAgg_9              | 1.00       | 3       | cop[tikv] |                | tikv_task:{proc max:209ms, min:131ms, avg: 157.3ms, p80:209ms, p95:209ms, iters:1466, tasks:3}, scan_detail: {total_process_keys: 1500000, total_process_keys_size: 305225771, total_keys: 1500003, get_snapshot_time: 359.2µs, rocksdb: {key_skipped_count: 1500000, block: {cache_hit_count: 9995}}}, time_detail: {total_process_time: 472.5ms, total_suspend_time: 1ms, total_wait_time: 427.5µs, total_kv_read_wall_time: 402ms, tikv_wall_time: 474.3ms}   | funcs:count(1)->Column#11        | N/A       | N/A  |
|     └─Selection_19           | 1500000.00 | 1500000 | cop[tikv] |                | tikv_task:{proc max:208ms, min:130ms, avg: 156.3ms, p80:208ms, p95:208ms, iters:1466, tasks:3}                                                                                                                                                                                                                                                                                                                                                                   | ne(tpch10.customer.c_name, "xx") | N/A       | N/A  |
|       └─TableFullScan_18     | 1500000.00 | 1500000 | cop[tikv] | table:customer | tikv_task:{proc max:179ms, min:109ms, avg: 134ms, p80:179ms, p95:179ms, iters:1466, tasks:3}                                                                                                                                                                                                                                                                                                                                                                     | keep order:false                 | N/A       | N/A  |
+------------------------------+------------+---------+-----------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+-----------+------+
5 rows in set (0.21 sec)

看起来64 KiB read request payload和coprocessor到storage层的报文请求字节数有关。

通过整体测试大概的感觉是:1、RU和CPU使用的多少看起来似乎关系不大;2、read requests和copTask请求没太大关系,和coprocessor到storage请求的行为有关系;3、数据量的请求和coprocessor到storage的请求大小有关系。

因此整体上想请教下:

  1. 如何理解storage read batches,是否是coprocessor到storage请求的行为?

  2. 如何理解storage read requests 否是coprocessor到storage请求的行为?与执行计划中tikv_task中的iters是否有关系?Get/Scan/Coprocess这些kv请求和storage read request是如何对应的?

  3. 对于CPU,3 ms 消耗 1 RU,从测试来看没看出来tidb-server,tikv消耗CPU会增加RU,这个CPU是统计tidb-server侧的还是tikv侧的,如果是tidb-server侧的这个CPU统计怎么做的?

  4. 在tidb-server中有令牌流控机制来控制整体资源的使用,这个是如何控制tidb-server的算子避免过多的资源消耗的?是如何控制kvrequest避免过多消耗的?

  5. 一次kvrequest请求后会反馈给tidb-server本次kvrequest消耗了多少RU,在一个资管控制组(resource group)中计算当前RU_PER_SECOND时是否会用这个kvrequest带过来的RU信息来做RU平均使用情况,以此来动态计算令牌额度来进行流控?

2 个赞

关注学习一下,很有深度的问题!

  1. 对,可以认为请求到 storage 前会有个 batch 的机制。
  2. 可以看执行计划的 num_rpc。
  3. op 部署的目前只统计的 tikv 侧, serverless 的会有计算层的统计。
  4. 通过 kv request 的限制进而间接减少在 tidb 层 group 之间的影响。
  5. 会的,kv request 收和发都会统计消耗,并判断是否需要进行流控。

另外关心具体的 sql 消耗 RU,可以 dashboard 上查看 statement 的统计,而具体计算,可以参考这个 issue:
https://github.com/pingcap/tidb/issues/47269#issuecomment-1737854502

3 个赞

storage read batches 具体是指什么?
楼上 nolouch 说了 grpc batch,我补充想到的另一个 batch
在 tikv 处理读查询的时候,也是以 batch 为单位进行的,每个 batch 处理多行的内容

storage read requests 包含了 coprocessor,但是由于上面提到的 grpc batch,一个 read request 可能包含多个 coprocessor task

执行计划中 tikv_task 的 iters 是 tikv 处理读查询时候总共的 batch 数量(所有的 coprocessor task 循环的总次数)

1 个赞

请教下,这里tikv的iters的行为和tidb侧的loop是一样的么?

请教下,这个storage read batches(storage write batch)是和如下这个参数相关么:

是类似的机制,但是数值是分别统计的

好的,感谢!

前面应该是指 TiDB 上发送请求的 batch
https://docs.pingcap.com/zh/tidb/dev/system-variables#tidb_store_batch_size