Php + sqlrelay + mysql implements connection pool and read/write load balancing. in large web applications, databases often become a bottleneck for concurrent access. to effectively solve the bottleneck of concurrent access, the master-slave mode of multiple databases is used to increase the concurrent web access volume.
The master-slave mode is used for data synchronization.
Sqlrelay solves connection pool problems and implements load balancing for read/write splitting.
Sqlrelay is configured with three instances A/B/C. A is responsible for reading data from Master and slave, B is responsible for writing data, and only writes data to Master. C is the router and is responsible for application scheduling.
Php connects to the database through A or B.
In the actual configuration, because the master performs read and write operations, you can slightly reduce the connection from the Master in the configuration of instance, this balances the number of connections that read data from the slave connection by slightly increasing.
1. MySQL master/slave configuration
################
# Mster/slave configuration
################
Master: 192.168.1.51
Slave: 192.168.1.50
1. master configuration
/Etc/my. cnf
Binlog-do-db = book is the database name
Ensure
Server-id = 1
Log-bin = mysql-bin
Authorize the rep user to perform the copy operation
Grant replication slave on book. * TO rep@192.168.1.50 identified by '2013 ';
Restart the master service
2. configure slave
Vi/etc/my. cnf
Set the following four lines
Server-id = 2
Master-host = 192.168.1.51
Master-user = rep
Masters-password = 123456
Restart slave
3. import the original master data to slave.
II. sqlrelay configuration
Almost all popular connection pool solutions in the industry do not support php. after many attempts, I finally found an open-source connection pool technology -------- sqlrelay.
Languages supported by sqlreplay:
C ++ Perl Python PHP Ruby Java TCL Zope
Databases supported by sqlreplay:
Oracle MySQL mSQL PostgreSQL Sybase ms SQL Server IBM DB2 Interbase Sybase SQLite ODBC MS Access
Sqlreplay website
Http://sqlrelay.sourceforge.net /.
Basic ideas:
1. configure two instances for final business processing
Clubs-read
Clubi-write
The read instance is configured with two connections respectively, and the two connections start equal connections.
2. configure an instance to schedule read/write operations, that is, clubr
You can use a router to differentiate read/write connections to different mysql databases.