Recently learned about the use of MySQL data implementation of the principle of the active structure, in the previous concurrent access to a low scene, generally a high performance of the server as a MySQL data, can meet the business of add and delete to change the scene, but with the increase of network users
In the case of high concurrency, high QPS, a MySQL is difficult to support this scenario, according to the current distributed processing architecture, processing in the use of Redis this efficient cache database, in fact, can also be targeted at the database side of the distributed processing, that is, the original
Same as Redis, using the distributed master-slave architecture, through master and Slave to achieve read and write analysis, data using the principle of master-slave replication, the use of read-write analysis, while reading the Slave machine can be configured in multiple configurations, greatly increased the stability and satisfaction of the background
High-concurrency scenarios;
The following principles are analyzed:
Brief procedure Description of the configuration:
MySQL configuration file "set in Spring"
Configuration of the data source:
Master data Source:
Slave data Source:
The source code can be implemented in a way that is based on custom annotations:
1, use a Select class, used to configure the selection method;
The configuration of the system requires a routing configuration:
Register the data source in spring "match the corresponding data source through the master and slave keywords":
Using annotations to achieve automatic matching via annotations on the Mapper interface, the effect is as follows:
Implementation of custom annotations: Using AspectJ's proxy mode AOP principle:
Match annotations to specific implementations:
Configure registration in Spring:
Configuration Complete!
MySQL database implements distributed master-slave architecture