Database Autonomy Service (DAS) provides the SQL throttling feature to control the volume of database access requests and SQL concurrency to ensure service availability.
Prerequisites
The supported database engines are:
-
ApsaraDB RDS for MySQL 5.6, 5.7, and 8.0.
-
ApsaraDB RDS for PostgreSQL 13 and later.
Note-
For PostgreSQL 13, the minor engine version must be 20250430 or later.
-
For PostgreSQL 14 or 15, the minor engine version must be 20230330 or later.
-
For PostgreSQL versions later than 15, any minor engine version is supported.
-
-
PolarDB for MySQL 5.6, 5.7, and 8.0.
-
PolarDB-X 2.0.
-
MongoDB.
Throttling error messages
After you create an SQL throttling rule, the database system returns a specific error message if an application runs an SQL statement that matches the rule's keywords or template.
|
Maximum concurrency |
Instance version |
Error code |
Error message |
|
0 or a positive integer |
|
1317 |
|
|
MongoDB |
56900 |
|
|
|
Positive integer |
ApsaraDB RDS for MySQL 5.7 (minor engine version 20200630 or later) |
5041 |
Note
Maximum concurrency is a positive integer, and related SQL queries will be in the |
|
ApsaraDB RDS for MySQL 8.0 |
7534 |
||
|
PolarDB for MySQL 5.7 |
3277 |
||
|
PolarDB for MySQL 8.0 |
7533 |
||
|
0 |
ApsaraDB RDS for MySQL 5.7 (minor engine version 20200630 or later) |
5042 |
Note
If the maximum concurrency is 0, an error is returned immediately. |
|
ApsaraDB RDS for MySQL 8.0 |
7535 |
||
|
PolarDB for MySQL 5.7 |
3278 |
||
|
PolarDB for MySQL 8.0 |
7534 |
-
When DAS performs SQL throttling, if the
ccl_max_waiting_countparameter is set to 0, DAS uses its default value of 10. If the parameter is set to a value greater than 0, DAS uses the specified value. -
For ApsaraDB RDS for MySQL 5.7 (with minor version 20200630 or later) and ApsaraDB RDS for MySQL 8.0 instances, if the
ccl_wait_timeoutparameter is set (and supported by the instance version), SQL statements in theConcurrency control waitingstate continue to execute and are no longer throttled after this limit is exceeded. -
For PolarDB for MySQL 8.0 instances, you can set the
ccl_modeparameter to control the behavior of SQL statements when the concurrency limit is exceeded. This parameter is available only on supported instance versions.-
WAIT (default): The statement waits in a queue.
-
REFUSE: The statement does not wait, and an error is returned immediately.
-
Scenarios
|
Scenario |
Description |
|
Sudden increase in SQL concurrency |
Cache penetration or abnormal calls can cause a sudden increase in SQL concurrency. |
|
SQL queries with data skew |
Frequently querying hot data during a sales promotion can overload the system. |
|
Missing indexes |
A high volume of SQL calls on an unindexed table can overload the system. |
Throttling modes
|
Mode |
Description |
Supported databases |
|
Keyword throttling |
Throttles SQL statements that contain specified keywords. Note
You cannot use this mode to throttle a specific SQL statement. |
|
|
Throttle by SQL Template |
Enter an SQL sample. The system processes it into an SQL template and then throttles all matching SQL statements. |
|
|
Throttles SQL statements by matching SQL template IDs. You can obtain SQL template IDs from SQL logs, sessions, and EXPLAIN execution results. Note
An SQL template ID is an 8-character hexadecimal string. |
PolarDB-X 2.0 Enterprise Edition |
|
|
Throttle by Execution Duration |
If an SQL statement's execution time exceeds the specified threshold, its SQL template ID is automatically added to the throttling rule. Subsequent statements that match this ID are then executed based on the rule's specified concurrency. Note
You can also set a limit on the number of throttled SQL template IDs. After the limit is reached, no more throttling rules are created for other SQL statements. |
PolarDB-X 2.0 Enterprise Edition |
|
Operation Type Throttling |
Controls the concurrency of find, insert, update, and delete operations on a specified collection. |
MongoDB
|
Procedure
This topic uses ApsaraDB RDS for MySQL as an example to describe how to use the throttling feature. For related operations for other database types, see Related documentation.
Log on to the DAS console.
In the navigation pane on the left, click .
Find the target instance and click the instance ID to open the instance details page.
-
In the left-side navigation pane, click Instance Sessions.
-
On the Session Management page, click SQL Throttling.
-
In the dialog box, click Create Throttling Rule.
-
In the Create Throttling Rule dialog box, configure the following parameters based on the database engine.
-
This parameter is required if you set Throttling Mode to Throttle by Keyword.
-
You can throttle INSERT statements only on the following database engines:
-
ApsaraDB RDS for MySQL 8.0
-
PolarDB for MySQL 5.7 and 8.0
-
PolarDB-X 2.0
-
-
You cannot throttle
INSERT...SELECT...statements. -
This parameter is required if you set Throttling Mode to Throttle by Keyword.
-
If you specify multiple keywords, the throttling rule is triggered only if an SQL statement contains all of the specified keywords. Separate multiple keywords with tildes (~). The order of the keywords does not matter.
For example, if the original statement is
SELECT min(id), max(id) FROM task_event WHERE gmt_modified < '2020-06-21' AND begin_time > '2020-07-09' AND source IN (527) AND id >= 15673 AND id <= 8015673,the corresponding throttling keywords are
SELECT~min~id~max~id~FROM~task_event~WHERE~gmt_modified~AND~begin_time~AND~source~IN~AND~id~AND~id. -
You cannot specify only
SELECT, INSERT, UPDATE, DELETEas throttling keywords. Keywords are case-sensitive. However, some earlier instance versions are not case-sensitive. -
This parameter is required if you set Throttling Mode to Throttle by SQL Template.
-
For complex SQL statements, DAS transforms the SQL Sample for internal processing, but the final SQL template remains unchanged. The throttling effect is not affected by this transformation.
For example, if you enter
select name from das where name = `das` and age = 21 limit 20,it is templated to
select name from das where name = ? and age = ? limit ?and then rewritten to
select name from das where name = `param0` and age = `param1` limit 20. -
This parameter is required if you set Throttling Mode to Throttle by SQL Template.
-
For complex SQL statements, DAS transforms the SQL Sample for internal processing, but the final SQL template remains unchanged. The throttling effect is not affected by this transformation.
For example, if you enter
select name from das where name = "das" and age = 21 limit 20,it is templated to
select name from das where name = ? and age = ? limit ?and then rewritten to
select name from das where name = "param0" and age = "param1" limit 20. -
You can throttle
INSERTstatements only on the following database engines:-
ApsaraDB RDS for MySQL 8.0
-
PolarDB for MySQL 5.7 and 8.0
-
PolarDB-X 2.0
-
-
You cannot throttle
INSERT...SELECT...statements. -
This parameter is required if you set Throttling Mode to Throttle by Keyword.
-
If you specify multiple keywords, the throttling rule is triggered only if an SQL statement contains all of the specified keywords. Separate multiple keywords with tildes (~). The order of the keywords does not matter.
For example, if the original statement is
SELECT min(id), max(id) FROM task_event WHERE gmt_modified < '2020-06-21' AND begin_time > '2020-07-09' AND source IN (527) AND id >= 15673 AND id <= 8015673,the corresponding throttling keywords are
SELECT~min~id~max~id~FROM~task_event~WHERE~gmt_modified~AND~begin_time~AND~source~IN~AND~id~AND~id. -
You cannot specify only SELECT, INSERT, UPDATE, or DELETE as throttling keywords. Keywords are case-sensitive. However, some earlier instance versions are not case-sensitive.
-
This parameter is required if you set Throttling Mode to Throttle by SQL Template.
-
For complex SQL statements, DAS transforms the SQL Sample for internal processing, but the final SQL template remains unchanged. The throttling effect is not affected by this transformation.
For example, if you enter
select name from das where name = "das" and age = 21 limit 20,it is templated to
select name from das where name = ? and age = ? limit ?and then rewritten to
select name from das where name = "param0" and age = "param1" limit 20. -
You can throttle
INSERTstatements only on the following database engines:-
ApsaraDB RDS for MySQL 8.0
-
PolarDB for MySQL 5.7 and 8.0
-
PolarDB-X 2.0
-
-
You cannot throttle
INSERT...SELECT...statements. -
This parameter is required if you set Throttling Mode to Throttle by Keyword.
-
If you specify multiple keywords, the throttling rule is triggered only if an SQL statement contains all of the specified keywords. Separate multiple keywords with tildes (~). The order of the keywords does not matter.
For example, if the original statement is
SELECT min(id), max(id) FROM task_event WHERE gmt_modified < '2020-06-21' AND begin_time > '2020-07-09' AND source IN (527) AND id >= 15673 AND id <= 8015673,the corresponding throttling keywords are
SELECT~min~id~max~id~FROM~task_event~WHERE~gmt_modified~AND~begin_time~AND~source~IN~AND~id~AND~id. -
You cannot specify only SELECT, INSERT, UPDATE, or DELETE as throttling keywords. Keywords are case-sensitive. However, some earlier instance versions are not case-sensitive.
-
Click Submit.
After the SQL throttling rule is created, you can view its details on the Running tab. The following table describes the parameters.
NoteThe parameters in the list vary slightly depending on the database engine and throttling mode.
Parameter
Description
Throttling Mode
The mode that you selected.
Throttling Rule
-
Throttle by Keyword: The configured throttling keywords.
-
Throttle by SQL Template: The template ID corresponding to the SQL Sample.
-
Throttle by Execution Duration: The configured execution time threshold and the number of throttled SQL templates.
Maximum Concurrency
The maximum number of concurrent SQL statements.
Maximum Waiting Queries
The maximum number of waiting queries configured in the throttling rule.
NoteThis parameter is displayed for ApsaraDB RDS for PostgreSQL instances when Throttling Mode is set to Throttle by SQL Template.
Throttling Duration (min)
The duration for which the SQL throttling rule is effective.
Start Time
The time when the throttling rule was configured and took effect.
Remaining time
The remaining time before the throttling rule expires.
SQL Sample
An example SQL statement to throttle.
NoteThis parameter is displayed if you set Throttling Mode to Throttle by SQL Template.
Throttling Template ID
The template ID corresponding to the SQL Sample.
NoteThis parameter is displayed if you set Throttling Mode to Throttle by SQL Template.
Status
Indicates that the rule is active.
Database
The database where SQL statements will be throttled.
NoteThis parameter is displayed if you set Throttling Mode to Throttle by SQL Template.
Search Path
The search path that corresponds to the throttled SQL statement.
NoteThis parameter is displayed for ApsaraDB RDS for PostgreSQL instances when Throttling Mode is set to Throttle by SQL Template.
Matched SQL Query
The number of SQL queries that match the throttling rule.
NoteThis parameter is displayed if you set Throttling Mode to Throttle by SQL Template.
Waiting SQL Query
The number of SQL queries that are waiting due to the throttling rule.
NoteThis parameter is displayed if you set Throttling Mode to Throttle by SQL Template.
Actions
Allows you to Disable or Modify the rule.
-
RDS for MySQL
|
Parameter |
Description |
|
Throttling Mode |
Select a throttling mode as needed. |
|
SQL Type |
The type of the SQL statement. Valid values: SELECT, UPDATE, DELETE, and INSERT. Note
|
|
Database |
The database where SQL statements will be throttled. Note
This parameter is required if you set Throttling Mode to Throttle by SQL Template. |
|
Maximum Concurrency |
The maximum number of concurrent SQL statements. The minimum value is 0. Note
Throttling begins when the number of concurrent SQL statements matching the rule reaches this value. |
|
Throttling Duration |
The duration for which the SQL throttling rule is effective. Important
SQL throttling is an emergency measure. We recommend setting the duration based on your business needs and disabling the rule when it is no longer required. |
|
SQL Keywords |
Keywords in the SQL statements to be throttled. Note
|
|
SQL Sample |
An example SQL statement to throttle. Note
|
RDS for PostgreSQL
|
Parameter |
Description |
|
Throttling Mode |
ApsaraDB RDS for PostgreSQL supports only Throttle by SQL Template. |
|
Database |
The database where SQL statements will be throttled. |
|
Search Path |
The search path for SQL throttling. Note
Separate multiple paths with commas ( |
|
Maximum Concurrency |
The maximum number of concurrent SQL statements. The minimum value is 0. Note
Throttling begins when the number of concurrent SQL statements matching the rule reaches this value. |
|
Maximum Waiting Queries |
The maximum number of waiting queries. |
|
Throttling Duration |
The duration for which the SQL throttling rule is effective. Important
SQL throttling is an emergency measure. We recommend setting the duration based on your business needs and disabling the rule when it is no longer required. |
|
SQL Sample |
An example SQL statement to throttle. Note
|
PolarDB for MySQL
|
Parameter |
Description |
|
Throttling Mode |
Select a throttling mode as needed. |
|
SQL Type |
The type of the SQL statement. Valid values: Note
|
|
Maximum Concurrency |
The maximum number of concurrent SQL statements. The minimum value is 0. Note
Throttling begins when the number of concurrent SQL statements matching the rule reaches this value. |
|
Database |
The database where SQL statements will be throttled. Note
This parameter is required if you set Throttling Mode to Throttle by SQL Template. |
|
Throttling Duration |
The duration for which the SQL throttling rule is effective. Important
SQL throttling is an emergency measure. We recommend setting the duration based on your business needs and disabling the rule when it is no longer required. |
|
SQL Keywords |
Keywords in the SQL statements to be throttled. Note
|
|
SQL Sample |
An example SQL statement to throttle. Note
|
PolarDB-X 2.0
|
Parameter |
Description |
|
Throttling Mode |
Select a throttling mode as needed. |
|
SQL Type |
The type of the SQL statement. Valid values: Note
|
|
Maximum Concurrency |
The maximum number of concurrent SQL statements. The minimum value is 0. Note
Throttling begins when the number of concurrent SQL statements matching the rule reaches this value. |
|
Throttling Duration |
The duration for which the SQL throttling rule is effective. Important
SQL throttling is an emergency measure. We recommend setting the duration based on your business needs and disabling the rule when it is no longer required. |
|
SQL Keywords |
Keywords in the SQL statements to be throttled. Note
|
|
SQL Template ID |
The ID of the SQL template to throttle. An ID is an 8-character hexadecimal string. Separate multiple SQL template IDs with commas ( Note
This parameter is required for PolarDB-X Throttling Mode instances when Throttling Mode is set to Throttle by SQL Template. |
|
Minimum SQL Execution Duration |
The threshold for the SQL execution time. If the execution time of an SQL statement exceeds the specified threshold, the system adds the SQL statement's template ID to the throttling rule. Note
This parameter is required for PolarDB-X Throttling Mode instances when Throttling Mode is set to Throttle by Execution Duration. |
|
Maximum Number of Throttled Queries |
The maximum number of SQL template IDs that can be throttled based on execution time. After this limit is reached, the system no longer creates throttling rules for other SQL statements whose execution time exceeds the specified threshold. Note
This parameter is required for PolarDB-X Throttling Mode instances when Throttling Mode is set to Throttle by Execution Duration. |
|
Database Account with Throttled Queries |
The database account associated with the throttled SQL statement. Note
This parameter is required if you set Throttling Mode to Throttle by Keyword or Throttle by SQL Template. |
MongoDB
Parameter | Description |
Operation type | Select the operation types to throttle. You can select multiple types. Valid values: |
Operation concurrency | Specify the maximum number of concurrent operations allowed for the selected operation types. Requests that exceed this threshold are throttled. |
Throttling duration | Set the active duration for the throttling rule. After the rule expires, the system automatically disables it and moves it to the Ended tab. |
Kill Statement | (Optional) If you enable this option, when the throttling rule takes effect, the system automatically terminates (kills) any active operations that match the rule, such as long-running |
Throttling scope | This option is available only for ApsaraDB for MongoDB sharded cluster instances. You can apply the rule to All Shards or Partial Shards. |
Throttled collections | Specify the collections that the rule applies to. Use the |
Related topics
Related APIs
|
API |
Description |
|
Enables SQL throttling. |
|
|
Disables a specified throttling rule. |
|
|
Disables all running throttling rules. |
|
|
Returns the running throttling rules. |
|
|
Returns the throttling rules that are running or have been triggered. |
|
|
Generates throttling keywords from an SQL statement. |