Skip to content

Commit

Permalink
sql-infra: add resource control feature (#12353)
Browse files Browse the repository at this point in the history
  • Loading branch information
hfxsd committed Feb 17, 2023
1 parent c182bb9 commit a1feac5
Show file tree
Hide file tree
Showing 18 changed files with 790 additions and 78 deletions.
6 changes: 6 additions & 0 deletions TOC-tidb-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@
- [`ADMIN SHOW DDL [JOBS|JOB QUERIES]`](/sql-statements/sql-statement-admin-show-ddl.md)
- [`ALTER DATABASE`](/sql-statements/sql-statement-alter-database.md)
- [`ALTER INDEX`](/sql-statements/sql-statement-alter-index.md)
- [`ALTER RESOURCE GROUP`](/sql-statements/sql-statement-alter-resource-group.md)
- [`ALTER TABLE`](/sql-statements/sql-statement-alter-table.md)
- [`ALTER TABLE COMPACT`](/sql-statements/sql-statement-alter-table-compact.md)
- [`ALTER USER`](/sql-statements/sql-statement-alter-user.md)
Expand All @@ -267,6 +268,7 @@
- [`CREATE [GLOBAL|SESSION] BINDING`](/sql-statements/sql-statement-create-binding.md)
- [`CREATE DATABASE`](/sql-statements/sql-statement-create-database.md)
- [`CREATE INDEX`](/sql-statements/sql-statement-create-index.md)
- [`CREATE RESOURCE GROUP`](/sql-statements/sql-statement-create-resource-group.md)
- [`CREATE ROLE`](/sql-statements/sql-statement-create-role.md)
- [`CREATE SEQUENCE`](/sql-statements/sql-statement-create-sequence.md)
- [`CREATE TABLE LIKE`](/sql-statements/sql-statement-create-table-like.md)
Expand All @@ -282,6 +284,7 @@
- [`DROP COLUMN`](/sql-statements/sql-statement-drop-column.md)
- [`DROP DATABASE`](/sql-statements/sql-statement-drop-database.md)
- [`DROP INDEX`](/sql-statements/sql-statement-drop-index.md)
- [`DROP RESOURCE GROUP`](/sql-statements/sql-statement-drop-resource-group.md)
- [`DROP ROLE`](/sql-statements/sql-statement-drop-role.md)
- [`DROP SEQUENCE`](/sql-statements/sql-statement-drop-sequence.md)
- [`DROP STATS`](/sql-statements/sql-statement-drop-stats.md)
Expand Down Expand Up @@ -327,6 +330,7 @@
- [`SHOW COLLATION`](/sql-statements/sql-statement-show-collation.md)
- [`SHOW [FULL] COLUMNS FROM`](/sql-statements/sql-statement-show-columns-from.md)
- [`SHOW CREATE DATABASE`](/sql-statements/sql-statement-show-create-database.md)
- [`SHOW CREATE RESOURCE GROUP`](/sql-statements/sql-statement-show-create-resource-group.md)
- [`SHOW CREATE SEQUENCE`](/sql-statements/sql-statement-show-create-sequence.md)
- [`SHOW CREATE TABLE`](/sql-statements/sql-statement-show-create-table.md)
- [`SHOW CREATE USER`](/sql-statements/sql-statement-show-create-user.md)
Expand Down Expand Up @@ -444,6 +448,7 @@
- [`PARTITIONS`](/information-schema/information-schema-partitions.md)
- [`PROCESSLIST`](/information-schema/information-schema-processlist.md)
- [`REFERENTIAL_CONSTRAINTS`](/information-schema/information-schema-referential-constraints.md)
- [`RESOURCE_GROUPS`](/information-schema/information-schema-resource-groups.md)
- [`SCHEMATA`](/information-schema/information-schema-schemata.md)
- [`SEQUENCES`](/information-schema/information-schema-sequences.md)
- [`SESSION_VARIABLES`](/information-schema/information-schema-session-variables.md)
Expand Down Expand Up @@ -477,6 +482,7 @@
- [Table Filter](/table-filter.md)
- [Troubleshoot Inconsistency Between Data and Indexes](/troubleshoot-data-inconsistency-errors.md)
- [Serverless Tier Limitations](/tidb-cloud/serverless-tier-limitations.md)
- [Resource Control](/tidb-resource-control.md)
- FAQs
- [TiDB Cloud FAQs](/tidb-cloud/tidb-cloud-faq.md)
- [Serverless Tier FAQs](/tidb-cloud/serverless-tier-faqs.md)
Expand Down
7 changes: 7 additions & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
- [Back up and Restore Data Using Dumpling and TiDB Lightning](/backup-and-restore-using-dumpling-lightning.md)
- [Back Up and Restore RawKV](/br/rawkv-backup-and-restore.md)
- [Incremental Backup and Restore](/br/br-incremental-guide.md)
- [Resource Control](/tidb-resource-control.md)
- [Configure Time Zone](/configure-time-zone.md)
- [Daily Checklist](/daily-check.md)
- [Maintain TiFlash](/tiflash/maintain-tiflash.md)
Expand Down Expand Up @@ -608,6 +609,7 @@
- [TiKV](/grafana-tikv-dashboard.md)
- [TiFlash](/tiflash/monitor-tiflash.md)
- [TiCDC](/ticdc/monitor-ticdc.md)
- [Resource Control](/grafana-resource-control-dashboard.md)
- Secure
- [Enable TLS Between TiDB Clients and Servers](/enable-tls-between-clients-and-servers.md)
- [Enable TLS Between TiDB Components](/enable-tls-between-components.md)
Expand Down Expand Up @@ -647,6 +649,7 @@
- [`ALTER INDEX`](/sql-statements/sql-statement-alter-index.md)
- [`ALTER INSTANCE`](/sql-statements/sql-statement-alter-instance.md)
- [`ALTER PLACEMENT POLICY`](/sql-statements/sql-statement-alter-placement-policy.md)
- [`ALTER RESOURCE GROUP`](/sql-statements/sql-statement-alter-resource-group.md)
- [`ALTER TABLE`](/sql-statements/sql-statement-alter-table.md)
- [`ALTER TABLE COMPACT`](/sql-statements/sql-statement-alter-table-compact.md)
- [`ALTER USER`](/sql-statements/sql-statement-alter-user.md)
Expand All @@ -662,6 +665,7 @@
- [`CREATE DATABASE`](/sql-statements/sql-statement-create-database.md)
- [`CREATE INDEX`](/sql-statements/sql-statement-create-index.md)
- [`CREATE PLACEMENT POLICY`](/sql-statements/sql-statement-create-placement-policy.md)
- [`CREATE RESOURCE GROUP`](/sql-statements/sql-statement-create-resource-group.md)
- [`CREATE ROLE`](/sql-statements/sql-statement-create-role.md)
- [`CREATE SEQUENCE`](/sql-statements/sql-statement-create-sequence.md)
- [`CREATE TABLE LIKE`](/sql-statements/sql-statement-create-table-like.md)
Expand All @@ -678,6 +682,7 @@
- [`DROP DATABASE`](/sql-statements/sql-statement-drop-database.md)
- [`DROP INDEX`](/sql-statements/sql-statement-drop-index.md)
- [`DROP PLACEMENT POLICY`](/sql-statements/sql-statement-drop-placement-policy.md)
- [`DROP RESOURCE GROUP`](/sql-statements/sql-statement-drop-resource-group.md)
- [`DROP ROLE`](/sql-statements/sql-statement-drop-role.md)
- [`DROP SEQUENCE`](/sql-statements/sql-statement-drop-sequence.md)
- [`DROP STATS`](/sql-statements/sql-statement-drop-stats.md)
Expand Down Expand Up @@ -729,6 +734,7 @@
- [`SHOW CONFIG`](/sql-statements/sql-statement-show-config.md)
- [`SHOW CREATE DATABASE`](/sql-statements/sql-statement-show-create-database.md)
- [`SHOW CREATE PLACEMENT POLICY`](/sql-statements/sql-statement-show-create-placement-policy.md)
- [`SHOW CREATE RESOURCE GROUP`](/sql-statements/sql-statement-show-create-resource-group.md)
- [`SHOW CREATE SEQUENCE`](/sql-statements/sql-statement-show-create-sequence.md)
- [`SHOW CREATE TABLE`](/sql-statements/sql-statement-show-create-table.md)
- [`SHOW CREATE USER`](/sql-statements/sql-statement-show-create-user.md)
Expand Down Expand Up @@ -855,6 +861,7 @@
- [`PLACEMENT_POLICIES`](/information-schema/information-schema-placement-policies.md)
- [`PROCESSLIST`](/information-schema/information-schema-processlist.md)
- [`REFERENTIAL_CONSTRAINTS`](/information-schema/information-schema-referential-constraints.md)
- [`RESOURCE_GROUPS`](/information-schema/information-schema-resource-groups.md)
- [`SCHEMATA`](/information-schema/information-schema-schemata.md)
- [`SEQUENCES`](/information-schema/information-schema-sequences.md)
- [`SESSION_VARIABLES`](/information-schema/information-schema-session-variables.md)
Expand Down
36 changes: 36 additions & 0 deletions grafana-resource-control-dashboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Key Monitoring Metrics of Resource Control
summary: Learn some key metrics displayed on the Grafana Resource Control dashboard.
---

# Key Monitoring Metrics of Resource Control

If you use TiUP to deploy the TiDB cluster, the monitoring system (Prometheus & Grafana) is deployed at the same time. For more information, see [Overview of the Monitoring Framework](/tidb-monitoring-framework.md).

The Grafana dashboard is divided into a series of sub dashboards which include Overview, PD, TiDB, TiKV, Node\_exporter, Disk Performance, and Performance\_overview.

If your cluster has used the [Resource Control](/tidb-resource-control.md) feature, you can get an overview of the resource consumption status from the Resource Control dashboard.

This document describes some key monitoring metrics displayed on the Resource Control dashboard.

## Metrics about Request Unit

- RU: the [Request Unit (RU)](/tidb-resource-control.md#what-is-request-unit-ru) consumption information of each resource group, calculated in real time. `total` is the sum of the Request Units consumed by all Resource Groups. The Request Unit consumption of each resource group should be equal to the sum of its read consumption (Read Request Unit) and write consumption (Write Request Unit).
- RU Per Query: the average number of Request Units consumed by each SQL statement per second. It is obtained by dividing the above RU metric by the number of SQL statements executed per second.
- RRU: the Read Request Unit consumption information of each resource group, calculated in real time. `total` is the sum of the Read Request Units consumed by all Resource Groups.
- RRU Per Query: the average number of Read Request Units consumed by each SQL statement per second. It is obtained by dividing the above RRU metric by the number of SQL statements executed per second.
- WRU: the Write Request Unit consumption information of each resource group, calculated in real time. `total` is the sum of the Write Request Units consumed by all Resource Groups.
- WRU Per Query: the average number of Write Request Units consumed by each SQL statement per second. It is obtained by dividing the above WRU metric by the number of SQL statements executed per second.

## Metrics about resources

- KV Request Count: the number of KV requests for each resource group, calculated per second. The requests are divided into read and write types. `total` is the sum of the KV requests for all Resource Groups.
- KV Request Count Per Query: the average number of read and write KV requests by each SQL statement per second. It is obtained by dividing the above KV Request Count metric by the number of SQL statements executed per second.
- Bytes Read: the amount of data read by each Resource Group, calculated per second. `total` is the sum of the data read by all Resource Groups.
- Bytes Read Per Query: the average amount of data read by each SQL statement per second. It is obtained by dividing the above Bytes Read metric by the number of SQL statements executed per second.
- Bytes Written: the amount of data written by each Resource Group, calculated in real time. `total` is the sum of the data written by all Resource Groups.
- Bytes Written Per Query: the average amount of data written by each SQL statement per second. It is obtained by dividing the above Bytes Written metric by the number of SQL statements executed per second.
- KV CPU Time: the KV layer CPU time consumed by each Resource Group, calculated in real time . `total` is the sum of the KV layer CPU time consumed by all Resource Groups.
- KV CPU Time Per Query: the average KV layer CPU time consumed by each SQL statement per second. It is obtained by dividing the above KV CPU Time metric by the number of SQL statements executed per second.
- SQL CPU Time: the SQL layer CPU time consumed by each Resource Group, calculated in real time. `total` is the sum of the SQL layer CPU time consumed by all Resource Groups.
- SQL CPU Time Per Query: the average SQL layer CPU time consumed by each SQL statement per second. It is obtained by dividing the above SQL CPU Time metric by the number of SQL statements executed per second.
3 changes: 3 additions & 0 deletions grafana-tikv-dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ This section provides a detailed description of these key metrics on the **TiKV-
- Average gRPC message duration: The average execution time of gRPC messages
- gRPC batch size: The batch size of gRPC messages between TiDB and TiKV
- Raft message batch size: The batch size of Raft messages between TiKV instances
- gRPC request sources QPS: The QPS of gRPC request sources
- gRPC request sources duration: The execution time of gRPC request sources
- gRPC resource group QPS: The QPS of gRPC request sources by resource groups

### Thread CPU

Expand Down
85 changes: 46 additions & 39 deletions information-schema/information-schema-processlist.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ The `PROCESSLIST` table has additional columns not present in `SHOW PROCESSLIST`
* A `DIGEST` column to show the digest of the SQL statement.
* A `MEM` column to show the memory used by the request that is being processed, in bytes.
* A `DISK` column to show the disk usage in bytes.
* A `TxnStart` column to show the start time of the transaction
* A `TxnStart` column to show the start time of the transaction.
* A `RESOURCE_GROUP` column to show the resource group name.

{{< copyable "sql" >}}

Expand All @@ -21,24 +22,25 @@ USE information_schema;
DESC processlist;
```

```
+----------+---------------------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+------+---------+-------+
| ID | bigint(21) unsigned | NO | | 0 | |
| USER | varchar(16) | NO | | | |
| HOST | varchar(64) | NO | | | |
| DB | varchar(64) | YES | | NULL | |
| COMMAND | varchar(16) | NO | | | |
| TIME | int(7) | NO | | 0 | |
| STATE | varchar(7) | YES | | NULL | |
| INFO | longtext | YES | | NULL | |
| DIGEST | varchar(64) | YES | | | |
| MEM | bigint(21) unsigned | YES | | NULL | |
| DISK | bigint(21) unsigned | YES | | NULL | |
| TxnStart | varchar(64) | NO | | | |
+----------+---------------------+------+------+---------+-------+
12 rows in set (0.00 sec)
```sql
+---------------------+---------------------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------------+------+------+---------+-------+
| ID | bigint(21) unsigned | NO | | 0 | |
| USER | varchar(16) | NO | | | |
| HOST | varchar(64) | NO | | | |
| DB | varchar(64) | YES | | NULL | |
| COMMAND | varchar(16) | NO | | | |
| TIME | int(7) | NO | | 0 | |
| STATE | varchar(7) | YES | | NULL | |
| INFO | longtext | YES | | NULL | |
| DIGEST | varchar(64) | YES | | | |
| MEM | bigint(21) unsigned | YES | | NULL | |
| DISK | bigint(21) unsigned | YES | | NULL | |
| TxnStart | varchar(64) | NO | | | |
| RESOURCE_GROUP | varchar(32) | NO | | | |
+---------------------+---------------------+------+------+---------+-------+
13 rows in set (0.00 sec)
```

{{< copyable "sql" >}}
Expand All @@ -47,18 +49,21 @@ DESC processlist;
SELECT * FROM processlist\G
```

```
```sql
*************************** 1. row ***************************
ID: 16
USER: root
HOST: 127.0.0.1
DB: information_schema
COMMAND: Query
TIME: 0
STATE: autocommit
INFO: SELECT * FROM processlist
MEM: 0
TxnStart:
ID: 2300033189772525975
USER: root
HOST: 127.0.0.1:51289
DB: NULL
COMMAND: Query
TIME: 0
STATE: autocommit
INFO: SELECT * FROM processlist
DIGEST: dbfaa16980ec628011029f0aaf0d160f4b040885240dfc567bf760d96d374f7e
MEM: 0
DISK: 0
TxnStart:
RESOURCE_GROUP: rg1
1 row in set (0.00 sec)
```

Expand All @@ -76,6 +81,7 @@ Fields in the `PROCESSLIST` table are described as follows:
* MEM: The memory used by the request that is being processed, in bytes.
* DISK: The disk usage in bytes.
* TxnStart: The start time of the transaction.
* RESOURCE_GROUP: The resource group name.

## CLUSTER_PROCESSLIST

Expand All @@ -88,13 +94,14 @@ SELECT * FROM information_schema.cluster_processlist;
```

```sql
+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+
| INSTANCE | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | MEM | TxnStart |
+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+
| 10.0.1.22:10080 | 150 | u1 | 10.0.1.1 | test | Query | 0 | autocommit | select count(*) from usertable | 372 | 05-28 03:54:21.230(416976223923077223) |
| 10.0.1.22:10080 | 138 | root | 10.0.1.1 | test | Query | 0 | autocommit | SELECT * FROM information_schema.cluster_processlist | 0 | 05-28 03:54:21.230(416976223923077220) |
| 10.0.1.22:10080 | 151 | u1 | 10.0.1.1 | test | Query | 0 | autocommit | select count(*) from usertable | 372 | 05-28 03:54:21.230(416976223923077224) |
| 10.0.1.21:10080 | 15 | u2 | 10.0.1.1 | test | Query | 0 | autocommit | select max(field0) from usertable | 496 | 05-28 03:54:21.230(416976223923077222) |
| 10.0.1.21:10080 | 14 | u2 | 10.0.1.1 | test | Query | 0 | autocommit | select max(field0) from usertable | 496 | 05-28 03:54:21.230(416976223923077225) |
+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+
+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+----------------+
| INSTANCE | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | MEM | TxnStart | RESOURCE_GROUP |
+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+----------------+

| 10.0.1.22:10080 | 150 | u1 | 10.0.1.1 | test | Query | 0 | autocommit | select count(*) from usertable | 372 | 05-28 03:54:21.230(416976223923077223) | default |
| 10.0.1.22:10080 | 138 | root | 10.0.1.1 | test | Query | 0 | autocommit | SELECT * FROM information_schema.cluster_processlist | 0 | 05-28 03:54:21.230(416976223923077220) | rg1 |
| 10.0.1.22:10080 | 151 | u1 | 10.0.1.1 | test | Query | 0 | autocommit | select count(*) from usertable | 372 | 05-28 03:54:21.230(416976223923077224) | rg2 |
| 10.0.1.21:10080 | 15 | u2 | 10.0.1.1 | test | Query | 0 | autocommit | select max(field0) from usertable | 496 | 05-28 03:54:21.230(416976223923077222) | default |
| 10.0.1.21:10080 | 14 | u2 | 10.0.1.1 | test | Query | 0 | autocommit | select max(field0) from usertable | 496 | 05-28 03:54:21.230(416976223923077225) | default |
+-----------------+-----+------+----------+------+---------+------+------------+------------------------------------------------------+-----+----------------------------------------+----------------+
```
Loading

0 comments on commit a1feac5

Please sign in to comment.