Database Autonomy Service (DAS) provides the SQL throttling feature. You can use this feature to control the number of requests sent to access databases and the number of SQL statements that can be concurrently executed. This feature can help you ensure the availability of your database service. This topic describes how to use SQL throttling for an ApsaraDB RDS for MySQL instance.
Prerequisites
- 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 PolarDB for MySQL
- PolarDB-X 2.0
Scenarios
Scenario | Description |
---|---|
Sharp rise in the number of concurrent SQL statements of a specific type | Cache penetration or abnormal calls can cause an unexpected rise in the number of concurrent SQL statements. |
Existence of SQL statements that cause data skew | If a large amount of data is queried during a promotional event, the overall system slows down. |
Lack of index tables | If a large number of SQL statements are executed on tables that are not indexed, the overall system slows down. |
Procedure
Throttling modes
DAS provides three modes to throttle SQL statements.
Parameter | Description | Supported databases |
---|---|---|
Throttled by Keywords | Throttles the SQL statements that contain the specified keywords. |
|
Throttle by SQL Template ID | Throttles the SQL statements that use the SQL templates with the specified IDs. The
SQL template IDs can be obtained from SQL logs, sessions, and results returned after
EXPLAIN statements are executed.
Note The ID of an SQL template is a hexadecimal string that contains eight characters in
length.
|
PolarDB-X 2.0 |
Throttle by Execution Duration | Throttles SQL statements by execution duration. If the execution duration of an SQL
statement of the specified type exceeds the specified threshold value, the system
fetches the ID of the SQL template used by the SQL statement and adds the ID to the
throttling rule. Then, SQL statements that use the SQL template are executed with
the specified concurrency.
Note You can configure the maximum number of SQL template IDs. After the number of SQL
template IDs added to the throttling rule reaches the upper limit, the system stops
fetching SQL template IDs.
|
PolarDB-X 2.0 |