Thinking of migrating MySQL databases to Aurora (RDS) and want to optimize read/write performance? This guide explores how ProxySQL can automate read-write splitting, reducing complexity and downtime.
We are going to see how to implement Proxysql for Amazon Aurora RDS, this would be next in series of ProxySQL blogs. Below is the list of our previous blogs on ProxySQL which provides deeper insights based on different use cases and different architecture.
- MySQL replication Read-Write Split up
- Replication Switchover using ProxySQL And MHA
- HA for ProxySQL with keepalived
- Mirroring MySQL Queries
- Handling Resource expensive Queries
- Percona Cluster/MariaDB cluster(Galera) Read-Write Split.
ProxySQL 2.0 comes with native support for AWS Aurora, and also with many exciting new features. We will be exploring it later in upcoming blogs. Amazon Aurora is highly performant and fault tolerant MySQL Compatible DBAAS provided by Amazon. To know more about Aurora you can check our previous blog here
For the purpose of this blog I have used Aurora cluster of size 2 (1 Master + 1 Replica), Aurora is not available within free tier usage of AWS, the smallest supported instance would be t2.small (1VCPU & 2GB RAM).
Now let’s see about the end-point provided by AWS while provisioning an Aurora Cluster.
Aurora Endpoints:
Endpoints are the connection URI’s provide by AWS to connect to the Aurora database. Listed below the endpoints provided for an Aurora cluster.
- Cluster Endpoint
- Reader Endpoint
- Instance Endpoint
Cluster Endpoint:
An endpoint for an Aurora DB cluster that connects to the current primary instance for that DB cluster. It provides failover support for read/write connections to the DB cluster. If the current primary instance of a DB cluster fails, Aurora automatically fails over to a new primary instance
Reader Endpoint:
An endpoint for an Aurora DB cluster that connects to one of the available Aurora Replicas for that DB cluster. Each Aurora DB cluster has a reader endpoint. The reader endpoint provides load balancing support for read-only connections to the DB cluster.
Instance Endpoint:
An endpoint for a DB instance in an Aurora DB cluster that connects to that specific DB instance. Each DB instance in a DB cluster, regardless of instance type, has its own unique instance endpoint
Among this different end-point, we will be using the “Instance Endpoint” ie., individual end-point in ProxySQL config.
The problem here is application should have read and writes split at the application layer. So that it can use the Reader and writer endpoints efficiently. But if a user migrates to Aurora for scalability then we need to have an intelligent proxy like Maxscale / ProxySQL, to have on the fly Read-Write split with almost Zero application level changes.
Now let’s see the configuration of ProxySQL for Aurora.
ProxySQL Version : proxysql-rc2-2.0.0-1-centos7.x86_64.rpm
OS version : Centos 7.3
Core : 1
RAM : 1G
Aurora Version: MySQL 5.7 compatible(aurora_version-2.03.1)
Instance End points: aurora.cbexxg6tsgtv.ap-south-1.rds.amazonaws.com, aurora-ap-south-1b.cbexxg6tsgtv.ap-south-1.rds.amazonaws.com
Below is the snap of my cluster
With the above end-points, I have the below host_group in ProxySQL
- 10(Writer Group)
- 11(Reader Group)
Adding servers to ProxySQL
Writer group:
Reader group:
Am inducing a replication lag threshold of 1secs, since its a cluster with a promised replication lag of less than 50Ms for query routing, This can be changed based on your use case and application criticalness.
Adding users:
You can have all your application user embedded into ProxySQL, Here am adding a single user for the purpose of the demo
Monitor user:
ProxySQL needs a monitoring user to ping the MySQL server, make replication checks, make sure to have “replication client” privilege for monitor user
You can proceed to check the monitor status from ProxySQL by running the below command.
Query Rules:
Am herewith adding the default query for RW-Split as below.
Now the configuration for Read-Write splitting is pretty much done.
How ProxySQL Monitors Aurora:
ProxySQL 2.0 comes with native monitoring for Aurora, by checking the variable “Innodb_read_only”, to determine the reader/Writer for the individual nodes, This info of check has to be added to the table “mysql_replication_hostgroups” in ProxySQL
Below is the structure of the table:
Table: mysql_replication_hostgroups
Here am making the check based on the hostgroup on the “INNODB_READ_ONLY” variable for each node in the hostgroup as below.
Now our setup of read-write split for Aurora is completely ready to accept traffic. We have made a read-write split with failover.
Failover handling With ProxySQL
I was just curious to note the fail-over and Switch-over with Aurora and ProxySQL to regroup the host group. So I induced a manual failover from the console as below
Before Fail-over below is the server status and host_group.
The ProxySQL Monitor makes checks within spans of few milliseconds as below. When it finds a consecutive fail of checks for three times, it makes the fail-over.
And next, it proceeds to remove the server from the writer group ‘10’ as below,
You can see a graceful shifting of servers across the host groups 10 as below.
Advantages of ProxySQL with Aurora
- On the wire query caching, With TTL
- Connection Multiplexing making efficient connection usage.
- Reduced CPU usage.
- Automated failover with Aurora end-points and query routing.
We are exploring more, See you soon with my new exciting upcoming blogs
Thanks for your continued support and Time !!
Need expert help with your MySQL to Aurora migration? Mydbops, our open-source database management service, offers comprehensive MySQL support, including ProxySQL implementation and performance tuning. Let our team of database specialists ensure a smooth and efficient migration to the cloud. Contact Mydbops today!
{{cta}}
Image Courtesy: Jouni Rajala on Unsplash