I’m using an Amazon RDS instance to host MySQL databases for all of my 6 WordPress websites. The moment the largest site’s traffic peaked, the RDS instance has CPU ultilisation of 100% for over an hour.
I’m thinking of splitting the load for the database server by read activity. Most traffic to my websites is due to non-logged users. So, I would like to connect these non-logged users to a read replica RDS instance why the rest, to the source RDS instance, the current database connection I’m using.
How do I achieve that?
Scaling WordPress
As traffic on your website increases, you will experience more load on the servers as well. To keep up with your speed you have two possibilities:
scale up– increase the size of your box – this – especially at AWS – obviously has limits besides other disadvantages like downtime for a scaling in both directions.scale out: split the traffic and let several machines do the work.Just add a machine as your traffic increases over a threshold and remove a power when your traffic has a lower level.
Scaling in a usual setup can be done at either your webservers or your database servers. AWS helps you with both. Since the database is the common bottleneck and this question actually wants this to be addressed, I’ll talk about database scaling now.
Amazon RDS (managed MySQL SaaS) offers a one-click solution to create read-replicas of your database. In the world of databases the read replica is called replication slave. Every modifying query executed on your master server will be automatically replayed on your slave machine.
You can create as many read replicas as you need to serve your users.
Now comes the complicated part. We are speaking about READ replicas. This means, that you can’t simply balance your queries randomly over all instances. Only the master server takes writing queries.
Splitting query types and distributing load evenly could be achieved by a database proxy like MySQL proxy which will require an additional machine. Your application would talk to this proxy and would not need any changes by itself.
Although WordPress wasn’t designed for a master-slave setup and this is not supported natively we all know that there are plenty of blogs out there with a lot of traffic.
Fortunately there is a solution called HyperDB
http://wordpress.org/extend/plugins/hyperdb/
This is a WordPress plugin, which does
This plugin will replace the default database abstraction layer in WordPress.
It is developed and actively used by the WordPress team.
Just download and make sure to follow the installation instructions carefully.
Have fun!