Php + sqlrelay + mysql implements connection pool and read/write load balancer _ MySQL

Source: Internet
Author: User
Tags dbase ibm db2 sybase
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.




















Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.