当前位置:网站首页>mysql 缓存策略和解决方案
mysql 缓存策略和解决方案
2022-07-17 05:08:00 【HjasnJH】
mysql的主从复制

1、主库Master节点,接受来自客户端的增、删、改请求,通过IO-thread写入到binlog
2、从库slave节点,请求读取主库的binlog,通过IO-thread写入本地的relay log(中继日志)
3、从库通过sql-thread读取relay-log,并把其中的增删改执行一遍。
mysql的读写分离

其中,读通过从节点读,写通过主节点写并同步到从节点,实现了读写分离
为什么需要mysql的缓存方案?
1、读多写少,内存的访问速度是磁盘访问速度的10万倍(数量级倍率),内存的访问速度⼤约是100ns,⽽⼀次磁盘访问⼤约是10ms;访问mysql时访问磁盘的次数跟b+树的⾼度相关;
2. ⼀般⼤部分项⽬中,数据库读操作是写操作的10倍左右;
缓冲层起到很好的提高读性能的作用
缓存层方案
将热点数据用redis缓存并数据库备份,将热点读操作转移到缓存数据库
可以很好的解决读性能。
引入了缓存层,如何解决一致性问题?
由以下几种情况:
1、mysql没有,缓存有
2、mysql有,缓存有,但不一致
3、mysql有,缓存没有
根据业务场景,看我们对一致性的要求:
最终一致性解决方案
如果项目想要做到最终一致性,我们的解决方案:
读:先读缓存,缓存有返回,没有则读mysql,再写redis
写:1、直接写mysql,等待mysql同步到redis
2、先写缓存redis,设置超时时间,再写mysql,最终mysql同步到redis。
强一致性解决方案
读:先读缓存,缓存存在直接返回,缓存不存在,访问mysql获取,再写redis
写:先删除缓存,再写mysql,等待mysql同步到缓存。
上面的方案,假定:mysql时最终的数据源。
同步方案

git clone https://gitee.com/mirrors/go-mysql-transfer.gitgo-mysql-transfer 实现对mysql数据同步到redis
边栏推荐
猜你喜欢

新手学习渗透测试的入门指南

C语言初学者之初识代码专项练习

Applet editor rich text editing and rich text parsing

ECS deployment web project

Ucharts chart, pie chart, bar chart and line chart are used in uniapp

MySQL optimization

无重复字符的最长字串

Email (including attachments, Netease, QQ)

How to deal with the mismatch between subtitle files and video files

Nacos配置管理
随机推荐
uniapp 使用uview实现折叠面板
【C语言—零基础第六课】输入输出语句格式与复合语句
Two methods of obtaining URL parameters and various methods of obtaining location objects
(elaborate) ES6 remaining parameters, ES6 built-in objects, template string content (detailed example Dictionary) and practical cases of flexible use of the project
Shell script configures root to login to other hosts without secret
Pat class B 1002: write this number
【AI】利用简单神经网络做动作识别——基于coco关键点
How to deal with the mismatch between subtitle files and video files
Get the multi-functional version of the maximum and minimum values of the internal values of the objects in the array and the full version of the roll call system, and show the effect
OpenDDS的QoS和自定义QoS(校时TimingQosPolicy)
LeetCode53. 最大子数组和
微信小程序获取年月日周及早上、中午、晚上
【C语言—零基础第十三课】字符串的奥秘
B域,M域,O域具体是指什么
uniapp中使用ucharts图表,饼状图,柱状图,折线图
Markdown notes and related shortcut keys of typora
BUUCTF web WarmUp
<script>标签内容详解
UML(用例图,类图,对象图,包图)
Es6 真实案例解构(多维数组对象)全新案例: