SQL throttling

更新时间:
复制 MD 格式

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

  • ApsaraDB RDS for MySQL 5.6

  • ApsaraDB RDS for MySQL 5.7 (minor engine version earlier than 20200630)

  • PolarDB for MySQL 5.6

1317

query execution was interrupted

MongoDB

56900

Sql controlled, skipped!

Positive integer

ApsaraDB RDS for MySQL 5.7 (minor engine version 20200630 or later)

5041

Concurrency control waiting count exceed max waiting count

Note

Maximum concurrency is a positive integer, and related SQL queries will be in the Concurrency control waiting state until the waiting count exceeds the value of the ccl_max_waiting_count parameter (if the instance version supports this parameter), at which point a prompt is returned.

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

Concurrency control refuse to execute query

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

Note
  • When DAS performs SQL throttling, if the ccl_max_waiting_count parameter 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_timeout parameter is set (and supported by the instance version), SQL statements in the Concurrency control waiting state 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_mode parameter 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.

  • ApsaraDB RDS for MySQL

  • PolarDB for MySQL

  • PolarDB-X 2.0

Throttle by SQL Template

Enter an SQL sample. The system processes it into an SQL template and then throttles all matching SQL statements.

  • ApsaraDB RDS for MySQL:

    • Version 5.7 with a minor engine version of 20241231 or later.

    • Version 8.0 with a minor engine version of 20230630 or later.

  • ApsaraDB RDS for PostgreSQL:

    • Version 13 with a minor engine version of 20250430 or later.

    • Version 14 with a minor engine version of 20230330 or later.

    • Version 15 with a minor engine version of 20230330 or later.

    • Versions later than 15.

  • PolarDB for MySQL:

    • Version 8.0.1 with a minor engine version of 8.0.1.1.31 or later.

    • Version 8.0.2 with a minor engine version of 8.0.2.2.12 or later.

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

  • Version 5.0 with a minor engine version of 6.0.13 or later.

  • Version 6.0 with a minor engine version of 7.0.9 or later.

  • Version 7.0 with a minor engine version of 8.0.4 or later.

  • Version 8.0, excluding minor engine version 9.0.5.

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.

  1. Log on to the DAS console.

  2. In the navigation pane on the left, click Intelligent O&M Center > Instance Monitoring .

  3. Find the target instance and click the instance ID to open the instance details page.

  4. In the left-side navigation pane, click Instance Sessions.

  5. On the Session Management page, click SQL Throttling.

  6. In the dialog box, click Create Throttling Rule.

  7. In the Create Throttling Rule dialog box, configure the following parameters based on the database engine.

  8. 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
    • 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.

    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
    • 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, DELETE as throttling keywords. Keywords are case-sensitive. However, some earlier instance versions are not case-sensitive.

    SQL Sample

    An example SQL statement to throttle.

    Note
    • 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.

    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 (,). The default value is information_schema,public.

    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
    • 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.

    PolarDB 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
    • 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.

    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
    • 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.

    SQL Sample

    An example SQL statement to throttle.

    Note
    • 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.

    PolarDB-X 2.0

    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
    • 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.

    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
    • 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.

    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: find, insert, update, and delete.

    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 find or update operations. The system performs this action only once to immediately release occupied connections and computing resources. New requests that arrive after the rule is active are throttled and are not terminated. This feature is ideal for emergency situations where a sudden workload surge has caused a large number of long-running transactions to accumulate, requiring an immediate release of resources.

    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 databaseName.collectionName format.

  9. Click Submit.

    After the SQL throttling rule is created, you can view its details on the Running tab. The following table describes the parameters.

    Note

    The 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.

    Note

    This 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.

    Note

    This parameter is displayed if you set Throttling Mode to Throttle by SQL Template.

    Throttling Template ID

    The template ID corresponding to the SQL Sample.

    Note

    This 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.

    Note

    This 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.

    Note

    This 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.

    Note

    This 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.

    Note

    This parameter is displayed if you set Throttling Mode to Throttle by SQL Template.

    Actions

    Allows you to Disable or Modify the rule.

Related topics

Related APIs

API

Description

EnableSqlConcurrencyControl

Enables SQL throttling.

DisableSqlConcurrencyControl

Disables a specified throttling rule.

DisableAllSqlConcurrencyControlRules

Disables all running throttling rules.

GetRunningSqlConcurrencyControlRules

Returns the running throttling rules.

GetSqlConcurrencyControlRulesHistory

Returns the throttling rules that are running or have been triggered.

GetSqlConcurrencyControlKeywordsFromSqlText

Generates throttling keywords from an SQL statement.