CREATE RESOURCE POOL
On this page
Creates a resource pool.
Syntax
CREATE RESOURCE POOL [IF NOT EXISTS] pool_name[ WITH resource_setting [, ...n] ]resource_setting:MEMORY_PERCENTAGE = percent| QUERY_MEMORY_PERCENTAGE = percent| QUERY_TIMEOUT = seconds| SOFT_CPU_LIMIT_PERCENTAGE = percent| HARD_CPU_LIMIT_PERCENTAGE = percent| MAX_CONCURRENCY = integer| MAX_QUEUE_DEPTH = integer
Remarks
-
pool_
: The name of a user-defined resource pool.name The value follows the same naming convention as a database column name. Not case sensitive. -
The memory percentages the resource governor can assign are on a per leaf basis, not the whole cluster.
For example, if your allocation is 50% of memory, that will be on a per leaf basis, so you can’t exceed the 50% limit at any time per leaf. -
Similarly, the resource governor assigns the CPU usage on a per leaf basis, not the whole cluster.
-
The maximum number of resource pools allowed is 10.
-
Refer to the Permission Matrix for the required permission.
Resource Pool Settings
When you write a CREATE RESOURCE POOL
or an ALTER RESOURCE POOL
statement, you can specify zero or more of the following limits.
-
MEMORY_
is set as the percentage of the memory currently available for query execution, which isPERCENTAGE maximum_
- "memory in use by everything except query execution".memory This includes memory used by tables and metadata. "Memory in use by everything except query execution" can be calculated as total_
-server_ memory alloc_
-query_ execution buffer_
.manager_ cached_ memory So MEMORY_
is the percentage ofPERCENTAGE maximium_
- (memory total_
-server_ memory alloc_
-query_ execution buffer_
).manager_ cached_ memory See Identifying and Reducing Memory Usage for more information on summary variables.
-
QUERY_
: this option can be used to restrict the maximum memory that a single query can use in the resource pool.MEMORY_ PERCENTAGE It is applied together with MEMORY_
.PERCENTAGE For example, setting
MEMORY_
toPERCENTAGE 60%
andQUERY_
toMEMORY_ PERCENTAGE 50%
would configure the system so that all queries running within the specified resource pool should together use a maximum of 60% of system memory, and any single query running within the pool should use, at most, 50% of system memory.Example syntax: CREATE RESOURCE POOL rpoolmain WITH MEMORY_PERCENTAGE = 60, QUERY_MEMORY_PERCENTAGE = 50, SOFT_CPU_LIMIT_PERCENTAGE = 65, MAX_CONCURRENCY = 40;
When setting
QUERY_
, the memory limit set for a pool will take effect immediately; however, queries already running in the pool will not be killed if the pool is currently over its new memory limit.MEMORY_ PERCENTAGE -
QUERY_
: A number of seconds (in multiples of five).TIMEOUT To control query execution time, you can define a query execution time limit that cancels a running query after that timeout value has been reached. There is a background thread on the aggregator scanning the list of running queries periodically, and this thread kills any query it finds that has been running longer than the timeout.
This thread wakes up roughly once every 5 seconds. However, it can miss the 5-second window to kill that query, for example, if the query has a SLEEP
(10). -
The engine variable
max_
controls the number of compilations that can run asynchronously at a given time on each node when interpreter_async_ compilation_ concurrency mode is set to interpret_ first. By decreasing the value of max_ async_ compilation_ concurrency, you can decrease the likelihood that asynchronous compilations will cause the SOFT_
orCPU_ LIMIT_ PERCENTAGE HARD_
limits to be reached.CPU_ LIMIT_ PERCENTAGE -
SOFT_
: An integer between 1 to 100.CPU_ LIMIT_ PERCENTAGE CPU usage for users can be limited from 1% - 100% of available processing capacity. This is a soft limit that allows CPU usage for a given pool to temporarily burst above the limit during a period of low/idle CPU usage; however, if other pools need CPU resources, then any pools above their soft limit will be immediately pushed down to their assigned limit. The sum of soft CPU limits of all resource pools must be <=100. To set SOFT_
when creating or altering a resource pool, the resource_CPU_ LIMIT_ PERCENTAGE governor_ cpu_ limit_ mode engine variable must be set to SOFT
.SingleStore recommends a soft CPU limit for most applications, as they typically want to utilize CPU resources from other pools, if such resources are available. -
HARD_
: An integer between 1 to 100.CPU_ LIMIT_ PERCENTAGE CPU usage for users can be limited from 1% - 100% of available processing capacity. This is a hard limit that reserves the specified CPU for a given pool. Once a resource pool’s hard limit is set, that share of the CPU is reserved for the resource pool and no other resource pool can use the reserved share. The sum of hard CPU limits of all resource pools must be <=100. To set HARD_
when creating or altering a resource pool, the resource_CPU_ LIMIT_ PERCENTAGE governor_ cpu_ limit_ mode engine variable must be set to HARD
.A hard CPU limit is useful when you want to ensure maximum predictability of CPU usage, at the expense of not utilizing extra CPU resources that may be available. -
MAX_
: If you specify this setting, at mostCONCURRENCY MAX_
concurrent SQL statements (queries) will run across all aggregators at any time.CONCURRENCY This number is approximate. Precisely, at most MAX (1, FLOOR (MAX_
concurrent SQL statements (queries) will run on one aggregator at a time.CONCURRENCY / <number of aggregators>)) To un-set this limit, set it to zero. -
MAX_
: The maximum number of queries that will be queued whenQUEUE_ DEPTH MAX_
is exceeded.CONCURRENCY If you set the MAX_
, its value must beQUEUE_ DEPTH 1
or greater.If you do not set MAX_
, the resource pool will not queue any queries.QUEUE_ DEPTH The sum of MAX_
for all user-defined resource pools cannot exceed the value of the engine variableQUEUE_ DEPTH max_
* 0.connection_ threads 8, when you create a resource pool or alter MAX_
.QUEUE_ DEPTH To understand why you may want to set MAX_
, see Resource Pool Interaction with Workload Management.QUEUE_ DEPTH
If MEMORY_
is not initially set, they will default to 100%.
If SOFT_
, HARD_
, QUERY_
, MAX_
, or MAX_
are not initially set, they default to 0 (which is represented as NULL in SHOW RESOURCE POOLS
) which results in no limit being set.
If QUERY_
is not initially set, there is no memory limit on a per-query basis (default behavior).
The CPU Limit Mode
The resource governor runs in either hard CPU limit mode or soft CPU limit mode.resource_
to HARD
or SOFT
.SOFT
.
You can view the setting of this engine variable by using:
SHOW VARIABLES LIKE 'resource_governor%';
or
SELECT @@resource_governor_cpu_limit_mode;
The following notes provide further information about resource_
, referenced as the current mode
:
-
If the current mode is
HARD
, theHARD_
of a resource pool must be set while creating the pool.CPU_ LIMIT_ PERCENTAGE -
If the current mode is
SOFT
, theHARD
limits of a resource pool cannot be set, and vice-versa. -
Setting the current mode to
HARD
copies all the existingSOFT
limits toHARD
and sets the soft limits toNULL
, and vice-versa. -
While querying the current resource limits, if the current mode is
SOFT
, allHARD_
values will be displayed asCPU_ LIMIT_ PERCENTAGE NULL
, and vice-versa. -
If the current mode is
HARD
andenable_
is set tobackground_ statistics_ collection ON
, the built-insystem_
reserves 5% of the CPU utilization for collection of background statistics.optimizer_ pool
Resource Pool Interaction with Workload Management
Suppose your cluster has two user-defined resource pools, pool1
and pool2
.pool1
is a lightly loaded pool.pool2
.pool2
’s MAX_
setting .MAX_
(the maximum number of queries allowed to be queued in the resource pool) set appropriately in pool2
, these queries cause the workload_
to be exceeded, causing the workload manager to cancel the queued queries in pool1
.
Note
When you submit a new query to a resource pool and the pool’s MAX_
is 0
, the workload manager will check if resources are available to immediately run the query.
MAX_
0
, the following logic executes: If the number of queries currently running in the cluster has reached MAX_
, SingleStore will attempt to queue the query.
See Using the Workload Manager for a discussion on how the workload manager operates.
Other Remarks
-
You can create at most ten resource pools, not including the built-in resource pools.
-
CREATE POOL
privilege is required to create a resource pool. -
This command can be run on a master, or child aggregator node (see Node Requirements for SingleStore Commands).
Examples
Example 1: Creating Two Resource Pools
The following example creates two resource pools.resource_
is set to HARD
and enable_
is set to ON
.
CREATE RESOURCE POOL executive WITH MEMORY_PERCENTAGE = 60,HARD_CPU_LIMIT_PERCENTAGE = 65, MAX_CONCURRENCY = 40;CREATE RESOURCE POOL general WITH MEMORY_PERCENTAGE = 40,HARD_CPU_LIMIT_PERCENTAGE = 30, MAX_CONCURRENCY = 20;
The HARD_
of the two resource pools sums to 95%.system_
reserves 5% of the hard CPU utilization.
Display the resource pool configuration.HARD_
column.
SHOW RESOURCE POOLS;
+-----------------------+-------------------+---------------+-----------------+---------------------------+---------------------------+-----------------+
| Pool_Name | Memory_Percentage | Query_Timeout | Max_Concurrency | Soft_CPU_Limit_Percentage | Hard_CPU_Limit_Percentage | Max_Queue_Depth |
+-----------------------+-------------------+---------------+-----------------+---------------------------+---------------------------+-----------------+
| default_pool | 100 | NULL | NULL | NULL | NULL | NULL |
| system_auto | 100 | NULL | NULL | NULL | NULL | NULL |
| system_optimizer_pool | 100 | NULL | NULL | NULL | 5 | NULL |
| executive | 60 | NULL | 40 | NULL | 65 | 20 |
| general | 40 | NULL | 20 | NULL | 30 | 20 |
+-----------------------+-------------------+---------------+-----------------+---------------------------+---------------------------+-----------------+
Example 2: Attempting to Exceed the Hard CPU Limit when the system_ optimizer_ pool
is Running
The following example attempts to create two resource pools.resource_
is set to HARD
and enable_
is set to ON
.
CREATE RESOURCE POOL executive WITH MEMORY_PERCENTAGE = 60,HARD_CPU_LIMIT_PERCENTAGE = 65, MAX_CONCURRENCY = 40;CREATE RESOURCE POOL general WITH MEMORY_PERCENTAGE = 40,HARD_CPU_LIMIT_PERCENTAGE = 35, MAX_CONCURRENCY = 20;
Because 5% of CPU utilization is reserved for collection of background statistics, the CREATE RESOURCE POOL general .
command fails, because the HARD_
would exceed 100%.
Example 3: Setting query-timeout
and Attempting to Exceed the Query Execution Time Limit
The following example shows the intended behavior of the query-timeout
setting.SELECT SLEEP(30)
query.
CREATE RESOURCE POOL test_pool WITH QUERY_TIMEOUT = 20;
Query OK, 0 rows affected (0.00 sec)
SET resource_pool = test_pool;
Query OK, 0 rows affected (0.00 sec)
SELECT SLEEP(30);
ERROR 2293 (HY000): The query has reached the timeout set for this connection's resource pool.
SHOW RESOURCE POOLS;
+--------------+-------------------+---------------+-----------------+---------------------------+
| Pool_Name | Memory_Percentage | Query_Timeout | Max_Concurrency | Soft_CPU_Limit_Percentage |
+--------------+-------------------+---------------+-----------------+---------------------------+
| default_pool | 100 | NULL | NULL | 100 |
| test_pool | 100 | 20 | NULL | 100 |
+--------------+-------------------+---------------+-----------------+---------------------------+
2 rows in set (0.01 sec)
Because the previous query attempts to execute for greater than the 20 second limit, it times out.
Related Topics
-
For more information about using resource pools to specify resource limits, see Setting Resource Limits.
Last modified: August 26, 2024