当前位置:网站首页>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
边栏推荐
- Common modification commands of Oracle for tables
- 基于SSM框架实现的房屋租赁管理系统
- Competition between public and private chains in data privacy and throughput
- Random类的那些事
- GEO数据挖掘(三)使用DAVID数据库进行GO、KEGG富集分析
- A way of writing SQL, update when matching, or insert
- How to use vector_ How to use vector pointer
- Unity 颜色板|调色板|无级变色功能
- Devops can help reduce technology debt in ten ways
- Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
猜你喜欢
Building lease management system based on SSM framework
Introduction au GPIO
Hydrogen future industry accelerates | the registration channel of 2022 hydrogen energy specialty special new entrepreneurship competition is opened!
DAY FIVE
STM32 enters and wakes up the stop mode through the serial port
How rider uses nuget package offline
app通用功能测试用例
App general function test cases
Three application characteristics of immersive projection in offline display
After leaving a foreign company, I know what respect and compliance are
随机推荐
SQL的一种写法,匹配就更新,否则就是插入
Use source code compilation to install postgresql13.3 database
DevOps可以帮助减少技术债务的十种方式
DAY SIX
Newsletter L Huobi ventures is in-depth contact with genesis public chain
《LaTex》LaTex数学公式简介「建议收藏」
How does win11 restore the traditional right-click menu? Win11 right click to change back to traditional mode
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
服务器SMP、NUMA、MPP体系学习笔记。
编译logisim
Yaduo Sangu IPO
Wind chime card issuing network source code latest version - commercially available
Penetration test --- database security: detailed explanation of SQL injection into database principle
[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist
DAY SIX
2022 PMP project management examination agile knowledge points (9)
17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
What is a responsive object? How to create a responsive object?
Google, Baidu and Yahoo are general search engines developed by Chinese companies_ Baidu search engine URL
1000字精选 —— 接口测试基础