Sunday, November 6, 2011

Liferay database load balancing and sharding

If you are considering optimizations at the database level, you should be aware of 2 things :


Technique that scales your database along portal instances : Database Sharding. Not that I have used it already, I haven't found a use case for this yet, so I'm setting up liferay-maven-plugin to call ServiceBuilder with these properties, so that it doesn't generate file shard-data-source-spring.xml


   I just wanted to mention it for those that are wondering what the shard-data-source-spring.xml is about. So that they don't think of it as "shared" type but that database shard is a known technique of horizontal partitioning of database design.

   I am also turning generation of dynamic-data-source-spring.xml off, because the solutions I've been developing didn't expect any massive load, so that  Read-write split technique is not needed either .

Read-write Split

Read-write split targets database replication. Not in the terms of a bulk file transfer, but rather a proxy mechanism that sends update/delete statements to multiple database servers, that is to say, having a database update against one server reflected on another server(s) in a real-time fashion. Databases use so called master-slave model where the master keeps a log of all transactions that it has performed and slave connects to it and performs the updates as it reads the log entries. The slave updates its position in the master's transaction log and waits for another one.
    For load balancing the best setup would be having two servers that are slaved to each other, which results in a slave-slave or master-master configuration. Transactions are reflected and there is no difference in the role of those servers.
    For instance MySQL database can be configured for this scenario quite easily and Liferay is quite ready for various requirements. Dynamic data sourcing for instance lets you have 2 data sources, one for READs and the second for WRITEs.
I have't needed this yet, as I said, so I'm turning it off as well in liferay-maven-plugin. The less files in my project, the better.

Anyway, some years of Liferay experience always come handy when you need to deal with stuff like this :-)

No comments: