Problem/Motivation
In large Drupal systems database performance becomes application performance bottleneck. So far I havent come across any viable solutions.
What I have been looking into are:
- setting some views to use replica - no big gain in utilizing reader database
- Try out https://www.drupal.org/project/autoslave 8.x branch but that ended with weird UI issues probably because of syncing
In December 2023 AWS launched 'Local Write Forwarding' which allows to send DQL (SELECT) and DML (INSERT, UPDATE, DELETE) to reader instance and guarantee data coherence in reader which is required for Drupal. DDL (ALTER, CREATE etc) and other queries need to directly to writer.
Steps to reproduce
Enabling Local Write Forwarding - https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-mysq...
Proposed resolution
As solution I've decided to patch core mysql module. Insert, delete, update, select classes are switched to reader thus anything else is going to writer.
In Connection class I'm detecting for transactions as local write forwarding does not support SAVEPOINTS. We'll switch everything to writer if these are started.
In setting's I've defined the extra connection
$databases['default']['replica'] = [
'driver' => 'mysql',
'database' => 'db',
'username' => 'db',
'password' => 'db',
'host' => 'db',
'port' => 3306,
'init_commands' => [
'isolation_level' => 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
],
];
At the time of writing this issue, we are testing the solution in development environments. So far it has been successful.
I wanted to ask what do you think of the solution?