| SELECTs to slave, INSERTs to master by application? [message #822] |
Tue, 27 February 2007 09:48  |
soularis Messages: 1 Registered: February 2007 Location: Hamburg, Germany |
Junior Member |

|
|
Hi,
I have a question and would be very thankful on any helping comments whatsoever.
I am running a PHP web application on a two webserver cluster. I also have two master-slave-replicated MySQL 5x databases.
What I want to do now is to send read-only-queries to the slave and all others queries to the master, or, better yet, to send write-queries to the master only and read-only-queries to 70% to the slave and 30% to the master (as I expect around 90% read-only-queries after all).
I already tried the not-yet-documented "mysqli_slave_query" and "mysqli_master_query" functions, but it did not work. I also tried "mysqli_enable_rpl_parse", which at least did not put out any error messages but all queries were sent to the master.
Last thing I tried was to open two database connections and do the parsing myself, which led me into having only half the performance. Not good.
I also googled myself through thousends of sites but could not find any helpful advice, maybe I do here?
Thanks a lot!
Stefan.
|
|
|
|
|
| Re: SELECTs to slave, INSERTs to master by application? [message #1372 is a reply to message #822 ] |
Thu, 07 June 2007 05:42   |
erick_p Messages: 3 Registered: June 2007 |
Junior Member |
|
|
Hi,
I am new to this replication thing. I want a simple setup where the "master" is the DB where I do inserts, updates, etc. I want the "slave" to focus on selects. I want to keep them almost at the same level of update (i.e., in microseconds, so that when one updates a record, it is immediately available through the slave for selection too. But when I am doing updates on the master, and master is therefore blocked (due to the grand MYISAM table-locking idiocy), I want the slave to be available througout this update time.
Is this what replication is for? A search for things like "read-only mysql replication" comes up on google with NOTHING, not a single guide on the net that tells me how to do this. I'd like a simple step by step guide -- and I have only one dedicated server, although I have 5 IPs, so I don't have a physical "cluster" or anything, I just want two separate processes running. Would appreciate any pointers!
Thanks
.ep
[Updated on: Thu, 07 June 2007 05:43]
|
|
|
| Re: SELECTs to slave, INSERTs to master by application? [message #1375 is a reply to message #1372 ] |
Thu, 07 June 2007 18:57   |
sterin Messages: 324 Registered: March 2007 Location: Sweden |
Senior Member |
|
|
| erick_p wrote on Thu, 07 June 2007 11:42 | I want to keep them almost at the same level of update (i.e., in microseconds, so that when one updates a record, it is immediately available through the slave for selection too.
|
The replication is normally carried out as soon as possible. Which is when the query has been performed on the master and logged. More in the millisecond range than in the microsecond.
| erick_p wrote on Thu, 07 June 2007 11:42 |
But when I am doing updates on the master, and master is therefore blocked (due to the grand MYISAM table-locking idiocy), I want the slave to be available througout this update time.
|
You can't really do that because the exact same changes will be performed on the slave also and then the slave will be locked for reading while the updates is performed.
| erick_p wrote on Thu, 07 June 2007 11:42 |
and I have only one dedicated server, although I have 5 IPs, so I don't have a physical "cluster" or anything, I just want two separate processes running.
|
You don't want to do this because you loose more than you gain.
When you have two processes running it means that they can't share the same cache memory etc. And you also consuming CPU since these two processes needs replication to be in sync.
If you have run into the performance problem with SELECT's that take a long time and a lot of INSERT/UPDATE/DELETE's you should change to InnoDB table type instead.
It uses row level locking instead and then you avoid this problem.
[Updated on: Thu, 07 June 2007 19:00]
|
|
|
|
|
|
| Re: SELECTs to slave, INSERTs to master by application? [message #1382 is a reply to message #822 ] |
Fri, 08 June 2007 08:27  |
sterin Messages: 324 Registered: March 2007 Location: Sweden |
Senior Member |
|
|
Start by testing:
innodb_buffer_pool_size=2G
The famous 2GB limit might come in play here.
[Updated on: Fri, 08 June 2007 08:28]
|
|
|