当前位置:网站首页>Mysql database: read write separation
Mysql database: read write separation
2022-06-29 22:44:00 【Full stack programmer webmaster】
One 、 The principle of separation of reading and writing :
1、 Realization principle :
The separation of reading and writing solves , data Library write operations , Affect the efficiency of the query , Suitable for scenarios where reading is far greater than writing . The implementation of read-write separation is based on master-slave replication , The master database uses master-slave replication to synchronize the changes of its own data to the slave database cluster , Then the master database is responsible for handling write operations ( Of course, you can also perform read operations ), From the database is responsible for processing read operations , Can't write . And according to the pressure , Deploy multiple slave databases to improve the speed of read operations , Reduce the pressure on the primary database , Improve the overall performance of the system .
2、 The reason why read-write separation improves performance :
(1) Add physical server , Load sharing ;
If we have 1 Lord 3 from , Suppose now 1 In minutes 10 The article writing ,150 Read . that ,1 Lord 3 From is equal to a total of 40 The article writing , And the total number of reads doesn't change , So on average, each server undertakes 10 Write and 50 Read ( The main library does not undertake the read operation ). therefore , Although the writing has not changed , But the read is greatly spread , Improved system performance . in addition , When the read is allocated , And indirectly improve the write performance . therefore , Overall performance improved , That is, the machine and bandwidth are exchanged for performance .
(2) The master and the slave are only responsible for their own writing and reading , A great deal of relief X Lock and S Lock contention ;
(3) Configurable from library MyISAM engine , Improve query performance and save system overhead ;
(4) Another major function of master-slave replication is to increase redundancy , Improve availability , When a database server goes down, it can restore service as fast as possible by adjusting another slave database .
3、Mysql The implementation of reading, writing and writing :
(1) Based on the internal implementation of program code :
In the code according to select 、insert Route classification , This kind of method is also the most widely used in the current production environment . The advantage is better performance , Because the program is implemented in code , There's no need to add extra hardware , The disadvantage is that it needs developers to implement , Operation and maintenance personnel have no way to start .
(2) Based on the intermediate agent layer :
The agent is generally between the application server and the database server , After receiving the request from the application server, the proxy database server forwards it to the back-end database according to the judgment , There are the following representative agent layers .
①mysql_proxy.mysql_proxy yes Mysql An open source project of , Through its own lua The script goes on sql Judge . ②Atlas. By qihoo 360, Web Platform Department infrastructure team development and maintenance based on MySQL Data middle tier project of the protocol . It's in mysql-proxy 0.8.2 Based on version , It's optimized , Added some new features .360 For internal use Atlas Running mysql Business , It carries billions of read and write requests every day . Support transactions and stored procedures . ③Amoeba. It is used by Chen Siru, an employee of Alibaba group java Language development , Alibaba group puts its users in the production environment , But it doesn't support things and stored procedures .
After the above simple comparison , Not all applications can implement read / write separation in program code , Like some big ones java application , If the separation of reading and writing is implemented in the program code, the code will be greatly changed , therefore , Applications like this generally consider using a proxy layer to implement .
Two 、 The construction of separation of reading and writing :
The steps for setting up read / write separation , You can read these two blogs :
https://blog.csdn.net/starlh35/article/details/78735510
https://blog.csdn.net/justdb/article/details/17331569
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/100074.html Link to the original text :https://javaforall.cn
边栏推荐
- Steady! The best posture for thousands of microservices to access Zadig (helm chart)
- 【多线程】 如何自己实现定时器
- 软件测试方法和技术知识点有哪些?
- Laravel creates its own facade extension geoip to obtain country, region and city information according to IP
- 2022年第一季度保险服务数字化跟踪分析
- MySQL backup database Linux
- Underlying principles of file operations (file descriptors and buffers)
- 深入解析kubernetes controller-runtime
- Spark cluster installation
- Does rapid software delivery really need to be at the cost of security?
猜你喜欢

Hezhou air32f103cbt6 development board hands-on Report

合宙AIR32F103CBT6开发板上手报告

5 - 1 Analyse de vulnérabilité du système

5-1系统漏洞扫描

Hidden worries behind the listing of shushulang: the performance has declined significantly, the market position is relatively backward, and the competitiveness is questionable

Gnawing down the big bone - sorting (I)

Daily question brushing record (VIII)

联通入库|需要各地联通公司销售其产品的都需要先入总库

AI scene Storage Optimization: yunzhisheng supercomputing platform storage practice based on juicefs
![Realizing deep learning framework from zero -- LSTM from theory to practice [theory]](/img/ac/164140eff1a6518d49ce25599d9c7b.png)
Realizing deep learning framework from zero -- LSTM from theory to practice [theory]
随机推荐
Steady! The best posture for thousands of microservices to access Zadig (helm chart)
Detailed description of gaussdb (DWS) complex and diverse resource load management methods
What are the software testing methods and technical knowledge points?
Basic use of Nacos configuration center
Static keyword continuation, inheritance, rewrite, polymorphism
Analyze apache SH script
Daily question brushing record (VIII)
【多线程】 如何自己实现定时器
Does Australia require that PVC plastic sheets comply with as/nzs 1530.3 with a flame spread index of 0?
The correct method for Navicat to connect to mysql8.0 (valid for personal testing)
Does rapid software delivery really need to be at the cost of security?
PhpSpreadsheet读写Excel文件
从零实现深度学习框架——LSTM从理论到实战【理论】
5-1系統漏洞掃描
The third day
英语没学好到底能不能做coder,别再纠结了先学起来
grpc的开发详解
Grep tool
联通入库|需要各地联通公司销售其产品的都需要先入总库
短视频平台搭建,淡入淡出 支持左滑右滑轮播图