当前位置:网站首页>Redis (IX) - enterprise level solution (II)
Redis (IX) - enterprise level solution (II)
2022-06-30 18:03:00 【Zhaoliwen is a pig】
Redis( Nine )—— Enterprise solutions ( Two )
List of articles
3、 Cache breakdown
Database server crash (2)
- During the smooth operation of the system
- Number of database connections An instant surge
- Redis There's not a lot of servers key Be overdue
- Redis Memory smooth , No fluctuations
- Redis The server CPU normal
- Database crash
Troubleshoot problems
- Redis in Some key Be overdue , The key There's a lot of traffic
- Multiple data requests are pressed directly from the server to Redis after , All miss
- Redis A large number of accesses to the same data in the database are initiated in a short time
Problem analysis
- Single key High heat data
- key Be overdue
Solution ( Technique )
Preset
Take e-commerce for example , Each business according to the store level , Specify a number of key products , During the Shopping Festival , enlarge Such information key Of Expiration time
Be careful : Shopping day is not just about the day , And the next few days , The peak value of access is gradually decreasing
On site adjustment
- Monitoring traffic , Extend the expiration time or set to permanent for data with natural traffic surge key
Background refresh data
- Start timing task , Before the peak , Refresh data validity period , Make sure you don't lose
Second level cache
- Set different failure times , It's not going to be eliminated at the same time
Lock Distributed lock , To prevent breakdown , But it's also a performance bottleneck , Be careful !
summary
Cache breakdown is The moment when a single hot data expires , Large amount of data access , Not hit redis after , Initiated a large number of database queries on the same data , Causing pressure on the database server . Coping strategies should be in business data analysis and prevention , Cooperate with operation monitoring test and real-time adjustment strategy , After all, single key It's difficult to monitor the overdue data , Combined with avalanche treatment strategy
4、 Cache penetration
Malicious request
The primary keys in our database are from 0 At the beginning , Even if we put all the data in the database into the cache . When someone uses id=-1 To happen Malicious request when , because redis There's no data in , Will directly access the database , This is called cache penetration
terms of settlement
- Check the validity of data in the program , If it's illegal, go back
- Use The bloon filter
Brief introduction of bloon filter
Want to avoid cache penetration as much as possible , One way is to... The data Pre calibration , In the face of Redis Before operating with the database ,** First check whether the data exists , If it doesn't exist, go straight back .** If we want to query whether an element exists , To ensure query efficiency , You can choose HashSet, But if there is 10 Billion data , Use both HashSet For storage , Memory must not be able to hold . Then you need a bloom filter
The bloon filter ( English :Bloom Filter) yes 1970 Proposed by bron in . It's actually a very long binary vector (bit Array ) And a series of random mapping functions (hash). The bloom filter can be used to retrieve whether an element is in a collection
Because it's based on Digit group and hash function Of , So it's advantage yes Space efficiency and query The time is much longer than the general algorithm . but shortcoming Is also evident , That is, there is a certain false recognition rate and deletion difficulty . But by increasing the size of the digit group and increasing hash Number of functions to Reduce False recognition rate ( Can only lower , Can't be avoided )
Put in the process
After the bloom filter is initialized , The values in the digit group are 0. When a variable is going to be put into the bloom filter , Will pass through multiple hash Function maps to each bit of the bit group , then Set the corresponding position to 1
The query process
The query is still through multiple hash Function maps to each bit of the bit group , If each bit is 1, Describe the element Possible , Note that there may be !!. But if through mapping , The digit group corresponds to the upper digit Not for 1, Then the element must not exist
Put in the process diagram
For example, one of our Bloom filters 8 The number group of bits , And there are 3 individual hash function Calculate the elements , Map to each bit in the array
We will string ”Nyima” Put it in a bloom filter
Next, the string ”Cpower” Put it in a bloom filter
Query process diagram
For example, we need to query the string ”Cpower” Whether there is , adopt 3 individual hash The function maps to three positions of the digit group , All three positions are 1, Then the String may exist
For example, we need to query the string ”SWPU” Whether there is , adopt 3 individual hash The function maps to the three positions of the digit group , Found a location that is not 1, Then the The string must not exist
For example, we need to query the string ”Hulu” Whether there is , adopt 3 individual hash The function maps to the three positions of the digit group , Found that all locations are 1, But we didn't put the string ”Hulu” Put it in a bloom filter , So here There was a miscarriage of justice
Increase the size and size of the digit group hash The number of functions can reduce the misjudgment rate , But there is no way to avoid misjudgment
边栏推荐
- Redis (I) - data type
- Hyper-V: enable SR-IOV in virtual network
- 【剑指Offer】52. 两个链表的第一个公共节点
- 【二叉树】前序遍历构造二叉搜索树
- Daily interview 1 question - how to prevent CDN protection from being bypassed
- 6 张图带你搞懂 TCP 为什么是三次握手?
- IEEE TBD SCI影响因子提升至4.271,位列Q1区!
- [binary tree] preorder traversal to construct binary search tree
- [Architecture] 1366- how to draw an excellent architecture diagram
- 腾讯云安装mysql数据库
猜你喜欢
![[Netease Yunxin] playback demo build: unable to convert parameter 1 from](/img/6e/41e1eafd4c863c9e5f3a545b69a257.png)
[Netease Yunxin] playback demo build: unable to convert parameter 1 from "asyncmodalrunner *" to "std:: nullptr\u T"**

Booking UI effect implemented by svg

MIT science and Technology Review released the list of innovators under the age of 35 in 2022, including alphafold authors, etc

Vue3 reactive database

基于SSH的通讯网络电子计费系统

后渗透之文件系统+上传下载文件

What did Tongji and Ali study in the CVPR 2022 best student thesis award? This is an interpretation of yizuo

Plane intersection and plane equation

中基协:推荐使用电子合同

Develop those things: how to add text watermarks to videos?
随机推荐
广电5G正式启航,黄金频段将如何应用引关注
Horizontal visual error effect JS special effect code
[Architecture] 1366- how to draw an excellent architecture diagram
[bjdctf2020]the mystery of ip|[ciscn2019 southeast China division]web11|ssti injection
2022上半年盘点:20+主流数据库重大更新及技术要点汇总
NFT铸造交易平台开发详情
MIT科技评论2022年35岁以下创新者名单发布,含AlphaFold作者等
Shortcut keys for the rainbow brackets plug-in
【剑指Offer】52. 两个链表的第一个公共节点
IEEE TBD SCI影响因子提升至4.271,位列Q1区!
Nielseniq welcomes dawn E. Norvell, head of retail lab, to accelerate the expansion of global retail strategy
Exch:完整性检查 Database Integrity Checking
[machine learning] K-means clustering analysis
6 张图带你搞懂 TCP 为什么是三次握手?
【网易云信】播放demo构建:无法将参数 1 从“AsyncModalRunner *”转换为“std::nullptr_t”**
ABAP-发布Restful服务
A tough battle for Tencent cloud
Ardunio esp32 DH11 real time uploading temperature and humidity Alibaba cloud self built mqtt
Word中添加代码块(转载)
Exch:exchange server 2013 is about to end support




