Database Autonomy Service (DAS) provides the SQL throttling feature. You can use this feature to manage the number of database access requests and the number of concurrent SQL statements to ensure service availability. This topic describes how to use SQL throttling in ApsaraDB RDS for MySQL.
- MySQL 5.6, MySQL 5.7, or MySQL 8.0 in ApsaraDB RDS for MySQL
- MySQL 5.6, MySQL 5.7, or MySQL 8.0 in the ApsaraDB PolarDB MySQL-compatible edition
|Sharp rise in the number of concurrent SQL statements of a specific type||Cache penetration or suspicious calls can cause an unexpected rise in the number of concurrent SQL statements.|
|SQL statements that cause data skew||During promotions, a large number of query requests can cause a slow system response.|
|Tables that are not indexed||If tables are not indexed, a large number of SQL statements can cause a slow system response.|
- In the left-side navigation pane, click Instance Sessions. For more information, see View the session statistics of an ApsaraDB RDS for MySQL instance.
- On the Instance Sessions page, click SQL Throttling.
- In the upper-left corner of the SQL Throttling dialog box, click Create.
- In the Create SQL Throttling Rule dialog box, configure the parameters. Then, click Create.
Parameter Description SQL Type The type of the SQL statement. Valid values: SELECT, UPDATE, and DELETE. Max Concurrency The maximum number of concurrent SQL statements. Throttling is triggered when the number of SQL statements that contain specific keywords reaches the maximum value. The minimum value of this parameter is 1. Throttling Duration The duration during which the SQL throttling rule takes effect. SQL throttling is an emergency measure. We recommend that you specify the throttling duration based on your business requirements and disable throttling when throttling is no longer needed. SQL Keywords The keywords that are used to identify the SQL statements that need to be throttled. If you specify multiple keywords, throttling is triggered only if an SQL statement contains all specified keywords. Separate multiple keywords with tildes (~). The keywords cannot contain only SELECT, UPDATE, or DELETE. The keywords are case-sensitive for instances except for the instances of some earlier versions. For example, if the statement to be throttled 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, set this parameter to SELECT~min~id~max~id~FROM~task_event~WHERE~gmt_modified~AND~begin_time~AND~source~IN~AND~id~AND~id.Note After you create a throttling rule, if an application sends an SQL statement that contains all specified keywords, the instances or clusters provided by different database services return different responses. The following list provides two examples:
- For an ApsaraDB RDS for MySQL instance that runs on MySQL 5.6 or MySQL 5.7 or a cluster of the ApsaraDB PolarDB MySQL-compatible edition that runs on MySQL 5.6, the system returns the error code 1317 and the error message query execution was interrupted.
- For an ApsaraDB RDS for MySQL instance that runs on MySQL 8.0 or a cluster of the
ApsaraDB PolarDB MySQL-compatible edition that runs on MySQL 5.7 or MySQL 8.0, the
system does not return an error. However, the SQL statement enters the
Concurrency control waitingstate.
- After the SQL throttling rule is created, you can view the status of the rule in the
list of throttling rules. Note If you want to disable or modify a throttling rule before the specified throttling duration expires, click Close or Edit in the Actions column.