当前位置:网站首页>Core knowledge of distributed cache
Core knowledge of distributed cache
2022-07-07 00:12:00 【chandfy】
Write it at the front
This is the core knowledge of distributed cache , It can be used to review the eight part essay , It can also be used to deepen knowledge , It is suggested that you read in the mode of breaking through the barrier , Then check and fill in the gaps according to the content , Welcome to ask questions and learn from each other .
It's done before
- new edition javase Essential core knowledge , Click to learn
- Necessary core knowledge of concurrent programming , Click to learn
- Message queue of middleware
- Mysql Core knowledge
- http Core knowledge of the agreement
- Spring-Mybatis Core knowledge
Each relevant article has the latest learning gains , Will make corresponding updates and modifications
Distributed cache core knowledge article knowledge overview
Why redis, Why not use other caches , such as memcached Well
Redis What are the common data structures ? What are the usage scenarios of these structures
redis A single thread , Why so soon? ?
redis Persistence of , And the difference between them
Common cache elimination strategies
Cache breakdown 、 through 、 The difference and solution of avalanche
Why redis, Why not use other caches , such as memcached Well
redis Data structure ratio memcached Richer , Basically, it can completely replace
redis The community is more active , Performance is also powerful , It also supports functions such as persistence
The most important thing is to integrate with the business
Redis What are the common data structures ? What are the usage scenarios of these structures
String
ordinary kv Storage , Use scenarios :hash
Store the object , One key There are multiple values , Use scenarios :list
Tabular data 、 Message queuing, etc , Use scenarios :set
unordered set 、 duplicate removal , intersection 、 And set etc. , For example, check your common friends , In terms of social relationships 、 Data duplication, etc. can be usedsroted set
Ordered set , duplicate removal , Make a list
redis A single thread , Why so soon? ?
Memory based , Most requests are purely memory operations ,CPU No Redis Bottleneck ( Single thread reason )
Avoid unnecessary CPU Context switching and other competitive conditions , Such as lock operation, etc
The bottom layer is the use of multiple channels I/O Reuse model , Non blocking IO
Redis6 Support multithreading after , But it is not enabled by default
redis Persistence of , And the difference between them
Support AOF and RDB Persistence
AOF
Log every write processed by the server 、 Delete operation , The query operation will not record , Record as text
Support second level persistence 、 Compatibility is good. , For the same number of data sets ,AOF Files are usually larger than RDB file , So recovery is better than RDB slow
RDB
Write the data set snapshot in memory to disk within the specified time interval , You can specify a time to archive data , But you can't do real-time persistence
The files are compact , Small volume , For disaster recovery ,RDB It's a very good choice , Compared with AOF Mechanism , If the data set is large ,RDB Speed ratio when recovering large data sets AOF It's faster to recover
Common cache elimination strategies
fifo (FIFO)First In,First Out
Newly accessed data insertion FIFO Queue tail , The data is in FIFO Move in sequence in the queue , Eliminate FIFO Data in the queue headerRecently at least use (LRU) Least recently used
The data is eliminated according to the historical access record of the data , If the data has been accessed recently , So the chances of being interviewed in the future are higher
Insert new data into linked list header , Whenever cached data is accessed , Move the data to the head of the linked list , When the list is full , Discard the data at the end of the list .Not often used recently (LFU) Least Frequently Used
Eliminate data based on its historical access frequency , If data has been accessed more than once , So the frequency of future visits will be higher
Add data to the linked list , Sort by frequency , A data has been accessed , Take its frequency +1, When elimination occurs , Eliminate those with low frequency
Cache breakdown 、 through 、 The difference and solution of avalanche
Cache breakdown ( Some hot spot key Cache failed )
There's no data in the cache, but there's data in the database , If it's hot data , that key At the moment the cache expires , There are a lot of requests at the same time , All of these requests go to DB, Cause instantaneous DB A lot of requests 、 Pressure builds up .
The difference between cache avalanche and cache avalanche is that this is for a certain key cache , The latter are many key.
The prevention of : Set hotspot data not to expire , Scheduled tasks regularly update the cache , Or set a mutex
Cache penetration ( Query data does not exist )
Query a nonexistent data , Because the cache is not hit , And for the sake of fault tolerance , If initiated as id by “-1” Nonexistent data
If the data cannot be found from the storage layer, it will not be written to the cache, which will cause the nonexistent data to be queried from the storage layer every request , It loses the meaning of caching . There are a lot of data that does not exist for query , Probably DB It's gone , This is also a non-existent way for hackers to take advantage of key A way to attack applications frequently .
The prevention of : Verification is added to the interface layer , Data rationality verification , Cache unreachable data , In the database, there is no access to , At this time, you can also key-value Write as key-null, Set a shorter expiration time , Prevent the same key Being attacked all the time
Cache avalanche ( Multiple hotspots key It's all overdue )
a large number of key Set the same expiration time , This causes all caches to fail at the same time , Cause instantaneous DB A lot of requests 、 The pressure surged , Cause an avalanche
The prevention of : The expiration time of stored data is set randomly , Prevent a large number of data expiration at the same time , Set hotspot data never to expire , Scheduled tasks are updated regularly
边栏推荐
- 【精品】pinia 基于插件pinia-plugin-persist的 持久化
- Devops can help reduce technology debt in ten ways
- Pinia module division
- Introduction au GPIO
- 《LaTex》LaTex数学公式简介「建议收藏」
- Quickly use various versions of PostgreSQL database in docker
- DAY SIX
- 自动化测试工具Katalon(Web)测试操作说明
- web渗透测试是什么_渗透实战
- 基于jsp+servlet+mysql框架的旅游管理系统【源码+数据库+报告】
猜你喜欢
Wind chime card issuing network source code latest version - commercially available
从外企离开,我才知道什么叫尊重跟合规…
Gradle knowledge generalization
陀螺仪的工作原理
【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤
Zero code and high return. How to use 40 sets of templates to meet 95% of the reporting needs in the work
沉浸式投影在线下展示中的三大应用特点
DAY TWO
DAY FOUR
互动滑轨屏演示能为企业展厅带来什么
随机推荐
How about the order management of okcc call center
刘永鑫报告|微生物组数据分析与科学传播(晚7点半)
2022 PMP project management examination agile knowledge points (9)
MATLIB从excel表中读取数据并画出函数图像
GPIO簡介
MVC and MVVM
零代码高回报,如何用40套模板,能满足工作中95%的报表需求
DAY ONE
DAY FIVE
Three sentences to briefly introduce subnet mask
How does win11 restore the traditional right-click menu? Win11 right click to change back to traditional mode
ldap创建公司组织、人员
2022年PMP项目管理考试敏捷知识点(9)
[CVPR 2022] target detection sota:dino: Detr with improved detecting anchor boxes for end to end object detection
Supersocket 1.6 creates a simple socket server with message length in the header
MIT 6.824 - raft Student Guide
PostgreSQL highly available repmgr (1 master 2 slave +1witness) + pgpool II realizes master-slave switching + read-write separation
SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
Random类的那些事
matplotlib画柱状图并添加数值到图中