当前位置:网站首页>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
边栏推荐
- Unity 颜色板|调色板|无级变色功能
- App general function test cases
- Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
- 【自动化测试框架】关于unittest你需要知道的事
- ldap创建公司组织、人员
- 谷歌百度雅虎都是中国公司开发的通用搜索引擎_百度搜索引擎url
- DAY ONE
- 17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
- Oracle对表进行的常用修改命令
- Gradle knowledge generalization
猜你喜欢

Zero code and high return. How to use 40 sets of templates to meet 95% of the reporting needs in the work

【自动化测试框架】关于unittest你需要知道的事
![[unmanned aerial vehicle] multi unmanned cooperative task allocation program platform, including Matlab code](/img/4c/5d867437aac5faa299817e187602e1.png)
[unmanned aerial vehicle] multi unmanned cooperative task allocation program platform, including Matlab code

matplotlib画柱状图并添加数值到图中

DAY THREE

ldap创建公司组织、人员

陀螺仪的工作原理

【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤

Rider离线使用Nuget包的方法

DevOps可以帮助减少技术债务的十种方式
随机推荐
DAY TWO
【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤
rancher集成ldap,实现统一账号登录
MySQL master-slave multi-source replication (3 master and 1 slave) setup and synchronization test
How to find out if the U disk file of the computer reinstallation system is hidden
Devops can help reduce technology debt in ten ways
Matplotlib draws a histogram and adds values to the graph
快讯 l Huobi Ventures与Genesis公链深入接洽中
Supersocket 1.6 creates a simple socket server with message length in the header
Introduction au GPIO
What is AVL tree?
数据运营平台-数据采集[通俗易懂]
app通用功能測試用例
kubernetes部署ldap
Automatic test tool katalon (WEB) test operation instructions
How does win11 restore the traditional right-click menu? Win11 right click to change back to traditional mode
Why is bat still addicted to 996 when the four-day working system is being tried out in Britain?
Server SMP, NUMA, MPP system learning notes.
Local deployment Zeppelin 0.10.1
Three sentences to briefly introduce subnet mask