1

We have a system where we have a Master / Multiple Slaves .

Currently everything happens on the Master and the slaves are just here for backup .

We use Codeigniter as a development platform .

Now we decided to user the slaves for the Reads and the Master for the Write queries .

I have been told that this is not doable without modifying the source code because proxy can't know the type of the query .

Any idea how to proceed with this without causing too much damages for a perfectly working system ...

Tarek
  • 3,810
  • 3
  • 36
  • 62

3 Answers3

5

We will use this : http://dev.mysql.com/downloads/mysql-proxy/

It does exactly what we want :

enter image description here

More info here :

http://jan.kneschke.de/2007/8/1/mysql-proxy-learns-r-w-splitting/

http://www.infoq.com/news/2007/10/mysqlproxyrwsplitting

http://archive.oreilly.com/pub/a/databases/2007/07/12/getting-started-with-mysql-proxy.html

Tarek
  • 3,810
  • 3
  • 36
  • 62
1

something i was also looking, few month back i did something like this but i added 3 web server with master slave mysql servers, first web server enabled with mod_proxy to redirect request to read and write server all request will come to this server, if post,put or delete request come to server it will go to write server, all get or normal request will go to read server

here you can find mod_proxy setting which i used

http://pastebin.com/a30BRHFq

here you can read about load balancing http://www.rackspace.com/knowledge_center/article/simple-load-balancing-with-apache

still looking for better solution with less hardware involved

umefarooq
  • 4,540
  • 1
  • 29
  • 38
  • All our queries are ajax based and then processed by php to run the mysql query (Select / Insert / Delete / Update..) – Tarek Feb 12 '15 at 10:08
  • no problem ajax request also either get or post, if get it will go to readonly server for select queries, if request post, put, delete it will go to write only server where you will perform insert, update and delete – umefarooq Feb 12 '15 at 10:14
1

figure out another solution through CI, create two database connections in database.php file keep save mysql server as default database connection and other connection for write only server

you can use this base model extend

https://github.com/jamierumbelow/codeigniter-base-model

you need to extend your models with this model and need to extend you model with this, it has functionality for callbacks before and after insert,update, delete and get queries, only you need to add one custom method or callback change_db_group

//this method in MY_Model    
function change_db_group{
   $this->_database = $this->load->database('writedb', TRUE)
}

no your example model

class Example_Model extends MY_Model{

  protected $_table = 'example_table';
  protected $before_create = array('change_db_group');
  protected $before_update = array('change_db_group');
  protected $before_delete = array('change_db_group');

}

you database connection will be changed before executing insert,update or delete queries

umefarooq
  • 4,540
  • 1
  • 29
  • 38