Sample Header Ad - 728x90

MariaDB large number of sessions waiting on index_tree_rw_lock

0 votes
1 answer
729 views
I have a MariaDB RDS instance that is mostly saving batched insert statements to 4 tables. These inserts have batches of an average of 200/batch and each statement saves to a single table. However, the db keeps getting overloaded handling this load. From the performance schema, all of the sessions are waiting on synch/sxlock/innodb/index_tree_rw_lock and to a lesser extent synch/mutex/innodb/buf_pool_mutex. From the cpu statistics, the utilization doesn't get anywhere more than 10%, which makes me think the size of the instance is sufficient. Is there any way to tune the db to help with this or what else can be done to further diagnose the issue? The schema for the tables (the actual schema has around 30 columns, but I truncated the non-key ones):
CREATE TABLE table_name (
  id varchar(191) NOT NULL,
  datacenter varchar(191) NOT NULL,
  date date NOT NULL,
  type varchar(50) DEFAULT NULL,
  version smallint(6) DEFAULT NULL,
  shared tinyint(1) DEFAULT NULL,
  region varchar(15) DEFAULT NULL,
  country varchar(15) DEFAULT NULL,
  city varchar(100) DEFAULT NULL,
  zip_code varchar(15) DEFAULT NULL,
  ...
  PRIMARY KEY (id,datacenter,date),
  KEY idx_duid_daily_summary_date (date),
  KEY idx_duid_daily_summary_type (type),
  KEY idx_duid_daily_summary_version (version),
  KEY idx_duid_daily_summary_region (region),
  KEY idx_diod_daily_summary_country (country),
  KEY idx_duid_daily_summary_city (city),
  KEY idx_duid_daily_summary_zip_code (zip_code)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
This is the result of show engine innodb status with the transactions truncated
=====================================
2023-06-26 16:11:05 0x14fcd4e5b700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 1 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 0 srv_active, 0 srv_shutdown, 1711200 srv_idle
srv_master_thread log flush and writes: 1711074
----------
SEMAPHORES
----------
------------
TRANSACTIONS
------------
Trx id counter 116627587
Purge done for trxs n:o = DATE_SUB(CURDATE(), INTERVAL 1 WEEK)
	AND date '
) AS subquery;
` ``` SELECT AVG(price) FROM table_name WHERE city = AND date >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK) AND date | ALL | null | null | null | null | 1801110 | | | 2 | DERIVED | table\_name | ref | idx\_city | idx\_city | 103 | const | 1801110 | Using where; Using index | - Non-sub query varient: | id | select\_type | table | type | possible\_keys | key | key\_len | ref | rows | Extra | | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | | 1 | SIMPLE | table\_name | ref | idx\_city | idx\_city | 103 | const | 1801110 | Using where; Using index | As I was running these queries, multiple times the sub query has an average execution time of 550ms and an average fetching time of 15ms, while the non-sub query version has an average execution time of 800ms and average fetching time of 15ms. In total, across 4 tables, the space used is 780GB with 331GB data and 447GB index.
Asked by ryanrasa (1 rep)
Jun 26, 2023, 04:41 PM
Last activity: Jun 1, 2025, 11:03 PM