All Products
Search
Document Center

AnalyticDB:Best practices for workload management

Last Updated:Mar 28, 2026

Workload management (WLM) lets you control query load before queries run, while they run, and on an ongoing basis for specific tables or databases. Use the rules in this guide to prevent a few heavy queries from degrading cluster health for all users.

Use the following table to choose a strategy based on your current situation:

SituationStrategy
A known query pattern is too slow or too expensive to run at full concurrencyThrottle before execution — assign it to a low-priority queue
The cluster is already under critical loadStop during execution — stop specific query types, users, or IP addresses immediately
Certain tables or databases consistently cause pressureRoutine throttling — permanently assign queries against those objects to a lower-priority queue

Prerequisites

Before you begin, ensure that:

  • Your AnalyticDB for MySQL cluster is running kernel version 3.1.6.3 or later

To check the kernel version, log on to the AnalyticDB for MySQL console and go to the Configuration Information section of the Cluster Information page. To upgrade, see Update the minor version of a cluster.

Before execution: throttle queries

Before a query runs, WLM evaluates it against your rules, assigns it to a queue, and enforces the concurrency limit for that queue. The diagram below shows how priority queues work:

image

Throttle queries by SQL pattern

Use this approach when you can identify a specific query pattern that is too expensive to run at full concurrency. WLM matches queries by their SQL pattern hash, so structurally identical queries are grouped and throttled together regardless of their literal parameter values.

  1. Calculate the hash value of the SQL pattern you want to throttle:

    wlm calc_pattern_hash

    For command details, see Calculate a pattern_hash value.

  2. Create a rule that routes queries with that pattern hash to the low-priority queue:

    wlm add_rule
    name=confine_query
    type=query
    action=ADD_PROPERTIES
    predicate='pattern_hash=XXXXXXXXXXXXXX'
    attrs='{
      "add_prop": {
        "query_priority": "low"
      }
    }'

    Replace XXXXXXXXXXXXXX with the hash value from step 1.

  3. Set the maximum concurrency for the low-priority queue. The default is 20:

    SET ADB_CONFIG XIHE_ENV_QUERY_LOW_PRIORITY_MAX_CONCURRENT_SIZE=20;
    Note

    For more information about how to modify the queue concurrency, see Priority queues and concurrency of an Interactive resource group.

    Lower this value to apply stricter throttling.

Throttle queries based on historical execution time

Use this approach when you want to automatically catch slow queries without identifying specific patterns upfront. The predicate PATTERN_EXECUTION_TIME_P50>2000 matches queries whose historical median (P50) execution time for that SQL pattern exceeds 2,000 milliseconds — a reliable signal that the query is expensive at scale.

  1. Create a rule that routes historically slow queries to the low-priority queue:

    wlm add_rule
    name=confine_query
    type=query
    action=ADD_PROPERTIES
    predicate='PATTERN_EXECUTION_TIME_P50>2000'
    attrs='{
      "add_prop": {
        "query_priority": "low"
      }
    }'
  2. Set the maximum concurrency for the low-priority queue:

    SET ADB_CONFIG XIHE_ENV_QUERY_LOW_PRIORITY_MAX_CONCURRENT_SIZE=20;

During execution: stop abnormal queries

When the cluster is already under critical load, create a KILL rule to stop specific queries immediately. Because KILL rules affect all matching queries — including queries that start after the rule is created — delete or disable each rule as soon as the cluster load returns to normal. For instructions on deleting or disabling a rule, see WLM.

Stop all SELECT queries

Use this when SELECT queries are blocking critical writes and you need to stop them immediately. Setting query_task_type=1 targets SELECT queries only.

wlm add_rule
name=kill_select_query
type=query
action=KILL
predicate='query_task_type=1'
Warning

This rule stops all active SELECT queries and continues to block new ones until you delete or disable it. Delete this rule as soon as the cluster load normalizes.

Stop queries from a specific user

Use this when queries from a single user account are causing cluster instability.

wlm add_rule
name=kill_query_from_user
type=query
action=KILL
predicate='user=testuser1'

Replace testuser1 with the actual username. Delete this rule after the situation is resolved.

Stop queries from a specific IP address

Use this when you have traced the problematic queries to a single IP address.

wlm add_rule
name=kill_query_from_ip
type=query
action=KILL
predicate='source_ip=10.10.XX.XX'

Replace 10.10.XX.XX with the actual IP address. Delete this rule after the situation is resolved.

Stop all queries exceeding 100 MB of memory

Use this when memory-intensive queries are destabilizing the cluster and you need to stop all of them, including write operations.

wlm add_rule
name=kill_Big_query
type=query
action=KILL
predicate='QUERY_PEAK_MEMORY>=100'

This rule applies to both SELECT queries and write operations. Delete this rule after the cluster stabilizes.

Stop SELECT queries exceeding 100 MB of memory

Use this when large SELECT queries are causing instability but you want to keep write operations running. The predicate combines a memory threshold with query_task_type=1 to target only SELECT queries.

wlm add_rule
name=kill_Big_query
type=query
action=KILL
predicate='QUERY_PEAK_MEMORY>100 && query_task_type=1'

Delete this rule after the cluster stabilizes.

Routine throttling

Use routine throttling to permanently limit the concurrency of queries that scan specific tables or databases — for example, tables used by low-priority reporting jobs that run alongside production workloads.

  1. Create a rule that routes queries scanning the target tables to the low-priority queue:

    wlm add_rule
    name=confine_query_in_table
    type=query
    action=ADD_PROPERTIES
    predicate='query_table_list in database.table1, database.table2'
    attrs='{
      "add_prop": {
        "query_priority": "low"
      }
    }'

    Replace database.table1, database.table2 with the actual database and table names you want to throttle.

  2. Set the maximum concurrency for the low-priority queue:

    SET ADB_CONFIG XIHE_ENV_QUERY_LOW_PRIORITY_MAX_CONCURRENT_SIZE=20;

Predicates reference

The following table lists the predicates used in this guide. For a complete list of supported predicates and their valid values, see WLM.

PredicateDescriptionExample value
pattern_hashHash value of an SQL pattern. Queries with the same structural pattern share the same hash value. Use wlm calc_pattern_hash to calculate it.XXXXXXXXXXXXXX
PATTERN_EXECUTION_TIME_P50Historical median execution time (in milliseconds) for an SQL pattern. Use > to match patterns that are consistently slow.2000
query_task_typeType of query task. Set to 1 to match SELECT queries only.1
userDatabase username. Matches all queries submitted by the specified user.testuser1
source_ipSource IP address of the query. Matches all queries from the specified IP address.10.10.XX.XX
QUERY_PEAK_MEMORYPeak memory used by the query, in MB. Use >= or > to match memory-intensive queries.100
query_table_listTables scanned by the query. Use in with a comma-separated list of database.table pairs.database.table1, database.table2

Related topics