当前位置:网站首页>MySQL数据库:读写分离
MySQL数据库:读写分离
2022-06-29 13:05:00 【全栈程序员站长】
一、读写分离的原理:
1、实现原理:
读写分离解决的是,数据库的写操作,影响了查询的效率,适用于读远大于写的场景。读写分离的实现基础是主从复制,主数据库利用主从复制将自身数据的改变同步到从数据库集群中,然后主数据库负责处理写操作(当然也可以执行读操作),从数据库负责处理读操作,不能执行写操作。并可以根据压力情况,部署多个从数据库提高读操作的速度,减少主数据库的压力,提高系统总体的性能。
2、读写分离提高性能的原因:
(1)增加物理服务器,负荷分摊;
假如我们有1主3从,假设现在1分钟内有10条写入,150条读取。那么,1主3从相当于共计40条写入,而读取总数没变,因此平均下来每台服务器承担了10条写入和50条读取(主库不承担读取操作)。因此,虽然写入没变,但是读取大大分摊了,提高了系统性能。另外,当读取被分摊后,又间接提高了写入的性能。所以,总体性能提高了,也就是拿机器和带宽换性能。
(2)主从只负责各自的写和读,极大程度的缓解X锁和S锁争用;
(3)从库可配置MyISAM引擎,提升查询性能以及节约系统开销;
(4)主从复制另外一大功能是增加冗余,提高可用性,当一台数据库服务器宕机后能通过调整另外一台从库来以最快的速度恢复服务。
3、Mysql读写分写的实现方式:
(1)基于程序代码内部实现:
在代码中根据select 、insert进行路由分类,这类方法也是目前生产环境下应用最广泛的。优点是性能较好,因为程序在代码中实现,不需要增加额外的硬件开支,缺点是需要开发人员来实现,运维人员无从下手。
(2)基于中间代理层实现:
代理一般介于应用服务器和数据库服务器之间,代理数据库服务器接收到应用服务器的请求后根据判断后转发到后端数据库,有以下代表性的代理层。
①mysql_proxy。mysql_proxy是Mysql的一个开源项目,通过其自带的lua脚本进行sql判断。 ②Atlas。是由 奇虎360, Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目。它是在mysql-proxy 0.8.2版本的基础上,对其进行了优化,增加了一些新的功能特性。360内部使用Atlas运行的mysql业务,每天承载的读写请求数达几十亿条。支持事务以及存储过程。 ③Amoeba。由阿里巴巴集团在职员工陈思儒使用序java语言进行开发,阿里巴巴集团将其用户生产环境下,但是他并不支持事物以及存储过程。
经过上述简单的比较,不是所有的应用都能够在基于程序代码中实现读写分离,像一些大型的java应用,如果在程序代码中实现读写分离对代码的改动就较大,所以,像这种应用一般会考虑使用代理层来实现。
二、读写分离的搭建:
有关读写分离的搭建步骤,可以阅读这两篇博客:
https://blog.csdn.net/starlh35/article/details/78735510
https://blog.csdn.net/justdb/article/details/17331569
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/100074.html原文链接:https://javaforall.cn
边栏推荐
- The node command in the script does not print the execution log on the console
- 测试用例设计方法之等价类划分方法
- golang7_TCP编程
- I talked about exception handling for more than half an hour during the interview yesterday
- [high concurrency] cache idea
- Hundreds of CVPR people were recruited as new champions. Emoji became a "court witness". M2 MBP was exposed that the hard disk speed was reduced. Today, more big news is here
- WinDbg debugging tool introduction
- Discard Tkinter! Simple configuration to quickly generate cool GUI!
- Wechat applet: Yunkai publishes white wall wechat applet source code download server free and domain name support traffic main revenue
- Teach you how to install the latest version of mysql8.0 database on windows, nanny level teaching
猜你喜欢

Cloud native (31) | kubernetes chapter kubernetes platform basic pre installed resources

Summary of binary tree exercises

Application of ansvc reactive power compensation device in a shopping mall in Hebei

win11怎么看cpu几核几线程? win11查看cpu是几核几线程的教程

微信小程序:全新独家云开发微群人脉

测试用例设计方法之等价类划分方法

Hundreds of CVPR people were recruited as new champions. Emoji became a "court witness". M2 MBP was exposed that the hard disk speed was reduced. Today, more big news is here

weserver發布地圖服務

微信小程序:大红喜庆版UI猜灯谜又叫猜字谜

Applet Wechat: un nouveau réseau exclusif de microgroupes de développement de Cloud
随机推荐
I talked about exception handling for more than half an hour during the interview yesterday
weserver发布地图服务
golang7_TCP编程
Unity SplashImage 缩放问题
手把手教你在windows上安装mysql8.0最新版本数据库,保姆级教学
grep 精确匹配
[high concurrency] 28000 words' summary of callable and future interview knowledge points. After reading it, I went directly to ByteDance. Forgive me for being a little drifting (middle)
Introduction to reverse commissioning -pe file section table and block 03/07
Open source machine learning platform
The node command in the script does not print the execution log on the console
Appkey when applying for offline packaging of uniapp
Dynamic feedback load balancing strategy based on Cluster
关于MongoDB报错:connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
文物数字藏品,开启文化传承的新方式
HTAP X 云原生: TiDB 加速释放数据价值,实现数据敏捷
MySQL 1146 error [easy to understand]
ES6 array method
动荡的中介生意,不安的租房人
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?大部分人都会答错!
中康控股开启招股:拟募资净额3.95亿港元,预计7月12日上市