View a markdown version of this page

Troubleshooting uneven load across member clusters - Amazon Aurora

Troubleshooting uneven load across member clusters

In a database cluster group for Aurora, each member cluster carries the load of the collocations that it holds, so one member cluster can carry much more load than the others. Heat is load that concentrates on one member cluster while the others are quiet. Skew is an uneven spread of data or traffic across member clusters. Before you choose a remedy, find what carries the load: one instance, the member cluster, one collocation, one tenant, or one key. Each remedy moves only some of these.

Detecting heat and diagnosing its cause are read-only. You run the remedy as its own task, with the tasks in Managing data placement. You decide what moves and when.

You measure with the same tools as on any Aurora DB cluster. CloudWatch publishes metrics for each member cluster, for the routing layer, and for the group, with the member clusters' metrics rolled up. Performance Insights and Database Insights work on each member cluster as on any Aurora DB cluster. Database Insights has no group-level view, so compare the member clusters side by side. For the metrics, see Monitoring database cluster groups for Aurora.

This page follows the work in order:

  1. Detect. Compare the member clusters side by side, as described in One member cluster is busier than the others, and classify what you find with What to look for.

  2. Diagnose. Find the instance, member cluster, collocation, tenant, or key that carries the load, with the procedure in Identifying hot member clusters.

  3. Fix. Choose a remedy that can move that load, from Choosing a remedy. The moves themselves are in Rebalancing member clusters and Moving data between member clusters.

One member cluster is busier than the others

Symptom. One member cluster shows higher CPU, DB load, or latency than the others. For example, its writer shows DB load above its CPU capacity, or an Aurora Serverless v2 member cluster runs at its maximum capacity, while the other member clusters are quiet. The other collocations on that member cluster then see latency rise with unchanged traffic, because they wait for CPU behind the busy one. Or the application's p99 latency rises, and you need to find which member cluster is responsible.

Check. The following checks are read-only. Run them one member cluster at a time, on direct connections, and read the busiest member cluster last, because it has the least headroom.

  • In CloudWatch and Performance Insights, measure every member cluster side by side, with the same metric, period, and statistic. For more information, see Monitoring metrics in an Amazon Aurora cluster and Monitoring DB load with Amazon CloudWatch Database Insights on Amazon Aurora. Performance Insights has no group view, so read it for each instance. Show one column per member cluster. Don't average percentiles across member clusters, because a group average can hide one busy member cluster. The difference between the busiest and the quietest member cluster is the skew.

  • On each member cluster (direct), count sessions on the member cluster itself. On Aurora MySQL, a member cluster's DatabaseConnections metric in CloudWatch includes the sessions that the routing layer and data movement jobs open on it.

  • Compare the instances of the busy member cluster. Routed statements run on the writer, so a busy reader means that something reads from it directly.

  • On the busy member cluster (direct), split the sessions by origin, so that a batch job that connects directly doesn't pass for routed load.

  • Compare the data on each member cluster: the mapping rows and collocations that each one holds (at the routing endpoint), and table sizes estimated from the engine's statistics (direct).

  • For a first view of data skew and query skew, use CloudWatch to compare the busy metric (CPUUtilization on a provisioned member cluster, ACUUtilization on an Aurora Serverless v2 member cluster) with VolumeBytesUsed across the member clusters. Uneven storage points at data skew. Even storage with uneven throughput points at query skew. On Aurora MySQL, compare SelectThroughput and CommitThroughput for the throughput.

Run key measurements, such as key cardinality and the share of the busiest key values, on an Aurora clone of the busy member cluster, not on the member cluster itself.

To count sessions, read performance_schema.threads on the member cluster. To split sessions by origin, use the _rds_connection_source connection attribute, as shown in Identifying hot member clusters and Tracing a session or statement across the group. Estimate table sizes from InnoDB statistics.

Cause. Classify what you find with the table in What to look for: query skew with balanced data, data skew, or both. Also rule out causes that aren't about data: a move in progress, unequal capacity or parameters, a recent restart or capacity change, memory pressure, or a missing index. To find the unit that carries the load, follow Identifying hot member clusters.

Fix. Match the remedy to what carries the load, as described in Choosing a remedy.

Comparing member clusters in Performance Insights

Performance Insights works on each DB instance of a member cluster. To compare member clusters, open the same time range for the writer of each member cluster, and compare their DB load and top SQL. For how to read DB load, see Database load and Analyzing DB load by wait events. For the top SQL, see Overview of the Top SQL tab.

What to look for

The following table lists the kinds of heat and skew and where each one points.

Finding What it means
Query skew with balanced data Member clusters hold similar data, but statements concentrate on one. Look for a busy collocation, tenant, or key. A different routing key addresses query skew.
Data skew The busy member cluster also holds a larger share of the rows or collocations. Moving collocations off it addresses data skew. Databases left in their implicit collocation all sit on one member cluster.
Layout skew The mapping layout alone is uneven: one member cluster holds many more mappings or tenants than another, even when no tenant is large. Compare load and size per member cluster, not only mapping counts. An uneven layout can also be intentional, for example all databases on one member cluster, and it isn't an error.
Hot collocation or tenant One collocation, often one large tenant, carries most of a member cluster's load. A move relocates it but can't split it.
Hot key One routing key value, or a few values, carry most of a scaleout table's rows or statements. No move or routing function spreads one key value.
One busy instance One DB instance of a member cluster is busy, not the whole member cluster. Data placement isn't the cause.

Identifying hot member clusters

Use this procedure to find the instance, member cluster, collocation, tenant, or key that carries the load. Several steps run a query, shown after the procedure.

Before you begin, do the following:

  • Collect the routing endpoint and every member cluster's alias, endpoint, and DB cluster identifier.

  • Check that statement statistics are turned on for each member cluster's instances. The following section names the setting.

  • To measure keys, plan an Aurora clone of the busiest member cluster, or a snapshot export to Amazon S3. Don't run whole-table aggregates on a member cluster that serves traffic. For more information, see Cloning a volume for an Amazon Aurora DB cluster.

  • Open each direct session read-only, with a statement time limit, as shown in the following section. Check the busiest member cluster last, because it has the least headroom.

To identify a hot member cluster
  1. In the AWS CLI or the console, measure traffic on every member cluster, side by side, over the same window. Use CloudWatch per member cluster and Performance Insights or Database Insights per DB instance, as described in Monitoring metrics in an Amazon Aurora cluster and Monitoring DB load with Amazon CloudWatch Database Insights on Amazon Aurora.

    Compare CPUUtilization on a provisioned member cluster, or ACUUtilization on an Aurora Serverless v2 member cluster. Show the results in one column per member cluster, and don't average percentiles across them. Count sessions on each member cluster itself. On Aurora MySQL, a member cluster's DatabaseConnections metric in CloudWatch includes the sessions that the routing layer and data movement jobs open on it. For the group view, see Monitoring member clusters side by side.

  2. Measure data on every member cluster. At the routing endpoint, run SELECT * FROM dbclustergroup_sys.data_mappings;, and group the rows by member cluster and collocation in your client. Then, over a direct connection to each member cluster, run the step 2 query to read the approximate size of each table.

    Count the mappings on each member cluster. For a first view, compare VolumeBytesUsed across the member clusters in CloudWatch. Uneven storage points at data skew. Even storage with uneven throughput points at query skew. On Aurora MySQL, compare SelectThroughput and CommitThroughput for the throughput. Classify the finding as query skew with balanced data, data skew, or both.

  3. Find the object that carries the load. Over a direct connection, run the step 3 query on every member cluster, the busiest last, and compare each statement's share. Rank by the application's mapped objects, not by raw statement counts, because the platform's own statements add to the totals.

    Map each cluster name back to its router name and collocation with data_mappings. Busy objects under a database-level mapping point at one database, often one large tenant. Busy member tables of a scaleout table point at a set of key values.

  4. For a scaleout table, over a direct connection to the clone, run the step 4 query to find hot keys: the key's cardinality and the share of the top key values.

    Test each key-related cause: few distinct key values, a few dominant values that hold a large share of the rows or load, an uneven routing function map, or collocations that are too coarse. To read the map, run SHOW CREATE SCALEOUT ROUTING FUNCTION at the routing endpoint, as described in SHOW CREATE SCALEOUT ROUTING FUNCTION. For a HASH routing function, check that the ranges start at 0. Note any single key value or collocation that carries most of the load, because no move can split it. For the properties of a good key, see Choosing a routing key and routing function. For the routing functions available at preview, see Routing functions.

  5. In the Performance Insights console, check whether the load is on one DB instance. For how to compare instances, see Monitoring DB load with Amazon CloudWatch Database Insights on Amazon Aurora. Compare the instances by load, wait events, and the plan of the busiest statement on each instance endpoint (direct). Routed statements run on the writer, so a busy reader means that something reads from it directly.

  6. Rule out causes that aren't about data. Over a direct connection, run the step 6 query on each member cluster to split the load by origin.

    Also check for a move in progress, unequal capacity or parameters, a recent restart or capacity change, memory pressure, a busy object that only that member cluster holds, and a missing index. To compare configuration, see Auditing access and member cluster configuration. Run the usual Aurora tuning steps on the busiest member cluster for its top statements, because a missing index can look like skew.

  7. Choose the remedy from the table in Choosing a remedy, and run it as its own task.

The following shows the session settings and the query for each step.

Before you begin

Check that performance_schema is turned on for each member cluster's instances. Open each direct session with the following settings.

SET SESSION transaction_read_only = ON, max_execution_time = 60000, lock_wait_timeout = 5, innodb_lock_wait_timeout = 5;

Run the following on each instance of each member cluster (direct). If it returns 0, the performance_schema reads in steps 3 and 6 return no rows. Then split sessions with SHOW PROCESSLIST instead: by user, and by statements that start with the /* tid= comment that the routing layer adds to routed statements.

SELECT @@performance_schema AS performance_schema_enabled;
Step 2: Measure data

Run on each member cluster (direct). The query uses statistics and doesn't open any table.

SELECT database_name, SUBSTRING_INDEX(table_name, '#', 1) AS table_name, SUM(n_rows) AS approx_rows, ROUND(SUM(clustered_index_size + sum_of_other_index_sizes) * @@innodb_page_size / 1048576) AS approx_mib FROM mysql.innodb_table_stats WHERE database_name IN (CLUSTER_DBS) GROUP BY database_name, SUBSTRING_INDEX(table_name, '#', 1) ORDER BY approx_mib DESC LIMIT 50;
Step 3: Find the object that carries the load

Run on each member cluster (direct).

SELECT SCHEMA_NAME, LEFT(DIGEST, 12) AS digest, COUNT_STAR AS execs, SUM_TIMER_WAIT DIV 1000000000 AS total_ms, LEFT(DIGEST_TEXT, 120) AS digest_text FROM performance_schema.events_statements_summary_by_digest WHERE SCHEMA_NAME IS NOT NULL ORDER BY SUM_TIMER_WAIT DESC LIMIT 25;

SCHEMA_NAME is the default database of the member cluster session. The routing layer sets it for a routed statement that goes to one member cluster when the client session has a default database, from USE or the database named when connecting, that the statement's tables, or that database's database-level mapping, resolve to on that member cluster. It then sets the member cluster's database name. A statement sent to several member clusters gets no default database. Otherwise a routed statement might have a NULL SCHEMA_NAME, or the one that an earlier statement left on that session. To include those statements, drop the WHERE SCHEMA_NAME IS NOT NULL condition, and read the database from DIGEST_TEXT. The routing layer rewrites every table name in a routed statement to the member cluster's database and table names.

To see which database carries the I/O, run the following on the busiest member cluster (direct). Map each name back to its router name with data_mappings.

SELECT OBJECT_SCHEMA, SUM(COUNT_STAR) AS io_events, SUM(SUM_TIMER_WAIT) DIV 1000000000 AS io_wait_ms FROM performance_schema.table_io_waits_summary_by_table WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema', 'information_schema', 'sys') GROUP BY OBJECT_SCHEMA ORDER BY io_wait_ms DESC LIMIT 20;
Step 4: Find hot keys

Run on the clone (direct).

SELECT k, n, ROUND(100 * n / total, 2) AS pct_of_rows FROM (SELECT ROUTING_KEY AS k, COUNT(*) AS n FROM CLUSTER_DB.TABLE GROUP BY ROUTING_KEY) per_key CROSS JOIN (SELECT COUNT(*) AS total FROM CLUSTER_DB.TABLE) t ORDER BY n DESC LIMIT 20;

To read the key's cardinality, run the following on the clone (direct). A key with few distinct values can't spread, whatever the routing function.

SELECT COUNT(*) AS n_rows, COUNT(DISTINCT ROUTING_KEY) AS distinct_values FROM CLUSTER_DB.TABLE;

Under MOD, to read the rows in each bucket for a divisor N, run the following on the clone (direct). The expression uses the signed remainder that the routing function uses, so a negative key falls in a negative bucket. The service decides HASH placement, so this query doesn't apply to HASH. Under PREFIX or COLUMN, group by the prefix or the key value instead, because each collocation lists the prefixes or key values that it takes.

SELECT MOD(ROUTING_KEY, N) AS bucket, COUNT(*) AS n_rows FROM CLUSTER_DB.TABLE GROUP BY bucket ORDER BY bucket;
Step 5: Compare the instances

Run on each instance endpoint of the busy member cluster (direct), not on the cluster endpoint. Label each plan with the instance that returned it.

SELECT @@hostname AS instance; EXPLAIN BUSIEST_STATEMENT_WITH_CLUSTER_NAMES;
Step 6: Split the load by origin

Run on each member cluster (direct).

SELECT IFNULL(src.ATTR_VALUE, '(none)') AS connection_source, COUNT(*) AS sessions FROM performance_schema.threads t LEFT JOIN performance_schema.session_connect_attrs src ON src.PROCESSLIST_ID = t.PROCESSLIST_ID AND src.ATTR_NAME = '_rds_connection_source' WHERE t.TYPE = 'FOREGROUND' AND t.PROCESSLIST_ID IS NOT NULL GROUP BY connection_source;

A session that the routing layer opens reports ROUTER. A direct session doesn't carry the attribute, so the query shows it as (none).

To check for a move in progress, run the following at the routing endpoint. The filter takes one literal value.

SELECT * FROM dbclustergroup_data_movement.move_info WHERE status = 'Running';

To check for a recent restart or memory pressure, read the member cluster's recent warnings and errors on each instance (direct).

SELECT LOGGED, PRIO, ERROR_CODE, LEFT(DATA, 200) AS message FROM performance_schema.error_log WHERE PRIO IN ('Warning', 'Error') ORDER BY LOGGED DESC LIMIT 50;

Choosing a remedy

First decide what you want the remedy to do: relieve a busy member cluster, or isolate a tenant. The following table lists each cause, its remedy, and the remedy's limit. You run each move with the tasks in Rebalancing member clusters and Moving data between member clusters.

Cause Remedy Limit
One busy instance Fix it on that instance: the plan, the statistics, or the instance parameters. Move direct reads elsewhere. No move or re-key helps
A noisy job, a direct connection, a missing index, or unequal parameters Fix that cause on the member cluster. None
A busy member cluster that holds several collocations Move some collocations to a quieter member cluster, one move at a time. See Rebalancing member clusters. Moving a single busy collocation moves only its load
One busy collocation or tenant Move its neighbors off, or raise the member cluster's capacity. See Relieving a busy member cluster. Limited by the member cluster's capacity
An object in the implicit collocation Give the object its own collocation: in one UPDATE, set its router_collocation_group to a new collocation and its member_cluster_alias to the current alias. Don't delete and insert the mapping again, because the router name doesn't route between the two statements. See Changing data mappings. Without its own collocation, the object moves only with the whole implicit collocation
A tenant that has outgrown a member cluster Give the tenant its own collocation, or convert the table that carries its load into a scaleout table. Both move rows, not only mappings. Under MOD or HASH, a tenant's bucket also holds other keys. Under COLUMN, a collocation that lists only the tenant's key holds only that tenant. For the routing functions, see Routing functions.
More collocations than member clusters, and every member cluster busy Add a member cluster, and move collocations onto it. See Spreading data onto a new member cluster. Helps only when the group has more collocations than member clusters
An uneven routing function map on the right key Split the rows again into a new scaleout table whose routing function spreads the keys over more collocations. See Changing a routing function. A routing function switch moves no rows, so it doesn't fix skew
The wrong routing key, or one key value that carries most of the load Split the rows into a new scaleout table with a better key, and backfill. See Running a keyed backfill. No move or routing function spreads one key value
A routing key that's too coarse, or that isn't in every statement Add a surrogate routing key. Test it on a clone against the statements that don't carry the key. The application must send the new key in its statements
Unequal capacity Align the member cluster's capacity with the others. Let one capacity change finish before you start the next. None

Raising every member cluster's capacity by the same amount doesn't fix data skew or query skew, because the hot member cluster stays the hottest. When one member cluster shows both, fix the data skew first, and then measure again, because the query skew can go away after you balance the rows. To add capacity for routed traffic, scale the writer. Routed statements run on the writer, so an added reader takes no routed reads.

The group runs one move at a time, so start the next move after the current one ends. Don't start a capacity change on a member cluster while another capacity change is applying there, or while a move involves it.

Give each tenant that is likely to grow its own collocation, and choose a key that keeps high cardinality as a tenant grows. After you apply a remedy, clear any session pin that you set, measure the member clusters side by side again, and keep watching for the next imbalance.

For related tasks and concepts, see the following pages: