Scale With Maxscale – Part 3 (Replication)

This blog post is continuation of series of blog post on Maxscale, Part-1 which provides detailed introductory to Maxscale, Part-2 deals about the operation and administration of Maxscale. In this we will discusses, How Maxscale can be efficiently used for read scaling with mysql replication (Master – Slave).

Replication is a great feature which is having a great journey along with mysql history. With the introduction of row based replication in 5.1 replication capabilities has stabilised and now with the latest 5.7 we can have enhance multi-threaded replication , semi-synchronous replication.

Speaking of great performance improvement in replication, Even today most of the replication slaves are just used for backup and DR purposes this makes the resource and the money spent on the hardware to be wasted or kept idle most of the time.

To make valuable usage of the underlying slave resource, we can have Maxscale as a load balancer to route the read queries by monitoring the underlying state of the slave.

The installation part is already covered in the previous blog post.

We will now discuss about the configuration.

The monitor module used to monitor replication is “mysqlmon” below is the snippet of the monitor configuration.

Screen Shot 2017-08-24 at 12.42.07 PM.png

The monitor module monitors the node and status of replication between the master and slave, Monitor provides the status information to Maxscale core to make decision for query routing.

Now will proceed to configure the router module, The router which is used is “readwritesplit” for efficient splitting and balancing of writes and reads between master and slave server, below is the snippet of the router configuration

Screen Shot 2017-08-24 at 12.53.40 PM.png

The important feature of Maxscale with regards to replication is, we can set the acceptable replication lag for reads, here i have defined the value as ’30’ when the slave lag goes beyond ’30’, the queries will be routed back to the master or the other slave with lag less than 30 secs.

Next we would be defining a listener for router (readwritesplit), listener is nothing but a network end-point (port), through which the application interacts with Queries to and from DB via maxscale.

below is the listener configuration.

Screen Shot 2017-08-24 at 3.50.12 PM.png

Protocol defines the way in which the DB server is being interacted. here we use “MySQLClient”, which is pretty much equivalent to the mysql-client program.

Along with the above configuration the servers information has to be provided in the config as defined in the part-1 of this serial blog.

Restart maxscale after completion of configuration as below.

#service maxscale restart

Now you can connect your application to Maxscale IP ( Load Balancer IP ) on port 3306, as per this configuration for effect usage of the underlying slave, below is the snippet taken from live production server.

Screen Shot 2017-08-24 at 4.02.29 PM.png

As you can see above load is being equally shared between the master and slave, maxscale also supports many administrative and operation tasks like taking node out of replication, without interrupting the application.

Maxscale can also integrate fail-over script like MHA, mysqlfailover,etc for promoting a slave in-case of disaster, which is beyond the scope of this document.

Untitled drawing-6.jpg

Note : In the above Maxscale is a SPOF ( Single Point Of Failure ). But a High availability solution can be implemented via Keepalived.


2 thoughts on “Scale With Maxscale – Part 3 (Replication)

  1. Hi Shanthanu,

    In this case consider if a slave goes down or there is replication lag beyond the acceptable value, the queries will be routed to the other available slaves or to the master.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s