Skip to content

Latest commit

 

History

History
150 lines (117 loc) · 6.45 KB

File metadata and controls

150 lines (117 loc) · 6.45 KB
title summary
CREATE RESOURCE GROUP
Learn the usage of CREATE RESOURCE GROUP in TiDB.

CREATE RESOURCE GROUP

You can use the CREATE RESOURCE GROUP statement to create a resource group.

Note:

This feature is not available on {{{ .starter }}} and {{{ .essential }}} clusters.

Synopsis

CreateResourceGroupStmt ::=
   "CREATE" "RESOURCE" "GROUP" IfNotExists ResourceGroupName ResourceGroupOptionList

IfNotExists ::=
    ('IF' 'NOT' 'EXISTS')?

ResourceGroupName ::=
    Identifier
|   "DEFAULT"

ResourceGroupOptionList ::=
    DirectResourceGroupOption
|   ResourceGroupOptionList DirectResourceGroupOption
|   ResourceGroupOptionList ',' DirectResourceGroupOption

DirectResourceGroupOption ::=
    "RU_PER_SEC" EqOpt stringLit
|   "PRIORITY" EqOpt ResourceGroupPriorityOption
|   "BURSTABLE"
|   "BURSTABLE" EqOpt "MODERATED"
|   "BURSTABLE" EqOpt "UNLIMITED"
|   "BURSTABLE" EqOpt "OFF"
|   "QUERY_LIMIT" EqOpt '(' ResourceGroupRunawayOptionList ')'
|   "QUERY_LIMIT" EqOpt '(' ')'
|   "QUERY_LIMIT" EqOpt "NULL"
|   "BACKGROUND" EqOpt '(' BackgroundOptionList ')'
|   "BACKGROUND" EqOpt '(' ')'
|   "BACKGROUND" EqOpt "NULL"

ResourceGroupPriorityOption ::=
    LOW
|   MEDIUM
|   HIGH

ResourceGroupRunawayOptionList ::=
    DirectResourceGroupRunawayOption
|   ResourceGroupRunawayOptionList DirectResourceGroupRunawayOption
|   ResourceGroupRunawayOptionList ',' DirectResourceGroupRunawayOption

DirectResourceGroupRunawayOption ::=
    "EXEC_ELAPSED" EqOpt stringLit
|   "PROCESSED_KEYS" EqOpt intLit
|   "RU" EqOpt intLit
|   "ACTION" EqOpt ResourceGroupRunawayActionOption
|   "WATCH" EqOpt ResourceGroupRunawayWatchOption WatchDurationOption

WatchDurationOption ::=
    ("DURATION" EqOpt stringLit | "DURATION" EqOpt "UNLIMITED")?

ResourceGroupRunawayWatchOption ::=
    EXACT
|   SIMILAR
|   PLAN

ResourceGroupRunawayActionOption ::=
    DRYRUN
|   COOLDOWN
|   KILL
| "SWITCH_GROUP" '(' ResourceGroupName ')'

The resource group name parameter (ResourceGroupName) must be globally unique.

TiDB supports the following DirectResourceGroupOption, where Request Unit (RU) is a unified abstraction unit in TiDB for CPU, IO, and other system resources.

Option Description Example
RU_PER_SEC Rate of RU backfilling per second RU_PER_SEC = 500 indicates that this resource group is backfilled with 500 RUs per second
PRIORITY The absolute priority of tasks to be processed on TiKV PRIORITY = HIGH indicates that the priority is high. If not specified, the default value is MEDIUM.
BURSTABLE Whether to allow the resource group to overuse the available remaining system resources Starting from v9.0.0, the following three modes are supported: OFF indicates that the resource group is not allowed to overuse any remaining system resources. MODERATED indicates that the resource group is allowed to overuse remaining system resources to a limited extent. UNLIMITED indicates that the resource group can overuse remaining system resources without limitation. If no value is specified for BURSTABLE, the MODERATED mode is enabled by default.
QUERY_LIMIT When the query execution meets this condition, the query is identified as a runaway query and the corresponding action is executed. QUERY_LIMIT=(EXEC_ELAPSED='60s', ACTION=KILL, WATCH=EXACT DURATION='10m') indicates that the query is identified as a runaway query when the execution time exceeds 60 seconds. The query is terminated. All SQL statements with the same SQL text will be terminated immediately in the coming 10 minutes. QUERY_LIMIT=() or QUERY_LIMIT=NULL means that runaway control is not enabled. See Runaway Queries.

Note:

  • The CREATE RESOURCE GROUP statement can only be executed when the global variable tidb_enable_resource_control is set to ON. TiDB automatically creates a default resource group during cluster initialization. For this resource group, the default value of RU_PER_SEC is UNLIMITED (equivalent to the maximum value of the INT type, that is, 2147483647) and its BURSTABLE mode is UNLIMTED. All requests that are not bound to any resource group are automatically bound to this default resource group. You cannot delete the default resource group, but can modify its RU configuration.
  • Currently, only the default resource group supports modifying the BACKGROUND configuration.

Examples

Create two resource groups rg1 and rg2.

DROP RESOURCE GROUP IF EXISTS rg1;
Query OK, 0 rows affected (0.22 sec)
CREATE RESOURCE GROUP IF NOT EXISTS rg1
  RU_PER_SEC = 100
  PRIORITY = HIGH
  BURSTABLE;
Query OK, 0 rows affected (0.08 sec)
CREATE RESOURCE GROUP IF NOT EXISTS rg2
  RU_PER_SEC = 200 QUERY_LIMIT=(EXEC_ELAPSED='100ms', ACTION=KILL);
Query OK, 0 rows affected (0.08 sec)
SELECT * FROM information_schema.resource_groups WHERE NAME ='rg1' or NAME = 'rg2';
+------+------------+----------+----------------+---------------------------------+
| NAME | RU_PER_SEC | PRIORITY | BURSTABLE      | QUERY_LIMIT                     |
+------+------------+----------+----------------+---------------------------------+
| rg1  | 100        | HIGH     | MODERATED      | NULL                            |
| rg2  | 200        | MEDIUM   | OFF            | EXEC_ELAPSED=100ms, ACTION=KILL |
+------+------------+----------+----------------+---------------------------------+
2 rows in set (1.30 sec)

MySQL compatibility

MySQL also supports CREATE RESOURCE GROUP. However, the acceptable parameters are different from that of TiDB so that they are not compatible.

See also