当前位置:网站首页>Architecture solutions
Architecture solutions
2022-06-24 01:00:00 【ruochen】
1、 Local cache 、 Out of heap memory off-heap、
3、redis (jedis cluster Of sharding jedisCluster Reading and writing lettuce Read / write separation )
4、 Multi level cache ( atypism Local cache update policy Penetrating thinking )
5、 Deduct inventory problems ( Row lock redis Optimism lock redis+lua Sync to db alisql)
One 、 Local cache
shortcoming : Occupy system memory oom、 There are consistency problems , When the distributed cache has a single point problem , In combination with
example :hibernate For caching Ehcatch, Yes jdbc encapsulation
Two 、 Out of heap memory off-heap
Avoid hot data , Occupy system memory
1、 advantage : 1) Reduce gc frequency Reduce pause time 2) Expand and use more memory 3) Eliminate physical memory and heap Copy between
2、 TaoBao jdk Realization : Long life objects from heap Move in and out , gc Unable to manage .ps: Escape analysis technology is mature , It can also be allocated on the stack
3、 How to use physical memory : Capacity can be limited , beyond oom
4、 When to release
DirectByteBuffer The object is gc when , The off heap memory is released together
3、 ... and 、redis
The local cache cannot be expanded ,cluster Capacity can be extended indefinitely
1、 be based on jedis Client operation :
2、cluster Of sharding
1)hash Algorithm : Capacity expansion , All historical data should be migrated
2) Uniformity hash Algorithm : No need to migrate all , but node When you are young , Meeting Data skew , At the node ip/ Add... After the host name Number , Let it be evenly distributed
3) Slotting : In between ,slot Fix , Always be routed to the same
3、 be based on jedisCluster Read and write operations
A single node can be specified
4、 be based on lettuce Read / write separation of the client
jedis Cluster read / write separation is not supported ,lettuce Can be synchronized / asynchronous , Bottom based nio Model netty
advantage : Levels increase , Infinite extension , There is no need to manually adjust the connection maxTotal, Avoid local cache penetration
Four 、 Multi level cache
Local : Share in-process heap, Save hotspot data
cdn: Save product pictures 、 video
1. Inconsistency
Due to time difference , allow Dirty reading , Display sold out when deducting inventory
2. Local cache update policy ( Lord / passive )
1) Passive update : Return to the source after expiration , Ensure single thread , Avoid invalidating a large number of requests , Penetration causes avalanches
guava
2) Active update : After modification , Write to the queue asynchronously , Update cache
3、 Cache penetration thinking
Get familiar with the hot spots from the operation before the promotion key, In the configuration center
5、 ... and 、 Deduct inventory problems
1、 Row lock
In the table version, Traffic spikes cause a large number of threads to compete for row locks , influence db tps,rt rising , Cause an avalanche
2、redis Optimism lock
(1) Basic commands
1) watch : monitor key( Can be more ), Before the event key Change change , Transaction rule Failure
2) multi : Set multiple items in a transaction command , In order of precedence Put it in line
3) exec : Finally atomicity Submit for execution
(2)watch Internal implementation principles
How the client perceives : Every db All are redis.h/redis.db Structural representation , Since the internal storage watch_keys( The target being monitored key)
multi.c/touchWatchKey function Yes watch_keys Dictionary check
, There are changes key Marked as redis_dirty_cas, Subsequent commit transactions are interrupted
(3)jedis Optimism lock
(4) The default routing implementation
shortcoming : The more concurrent ,watch The greater the probability of collision , solve : Reading and writing compose one command , The embedded lua Script
3、redis+lua ( Best performance )
redis2.6 after , built-in lua Interpreter , but eval / evalsha When the order is executed ,redis Make it a A single item is in execution
(1)lua Script
(2)eval / evalsha The embedded redis perform
1) eval: Repeat to redis Same transmission lua Script , Network overhead is high
2) evalsha : from redis Get cached scripts , save . But with evalsha front , First use script load The command to load
lua To cache in , etc. redis Will wait sha1 Check code , Follow up time , Just send the check code
use evalsha perform lua Script
4、 How to synchronize inventory changes to db
synchronized: It is better to use it in the fierce competition
cas:https://www.jianshu.com/p/6d1f3b2a3ac0 Will retry indefinitely , Take up too much cpu
5、AliSQL
Do... For hot data hash, Collect all inventory and submit at one time ( Set the threshold )
边栏推荐
- skywalking 安装部署实践
- 【Flutter】如何使用Flutter包和插件
- What do NLP engineers do? What is the work content?
- [image detection saliency map] calculation of fish eye saliency map based on MATLAB distortion prompt [including Matlab source code 1903]
- Theoretical analysis of countermeasure training: adaptive step size fast countermeasure training
- 飞桨产业级开源模型库:加速企业AI任务开发与应用
- 【小程序】实现双列商品效果
- 所见之处都是我精准定位的范畴!显著图可视化新方法开源
- Handwritten digit recognition using SVM, Bayesian classification, binary tree and CNN
- An accident caused by a MySQL misoperation, and the "high availability" cannot withstand it!
猜你喜欢

分别用SVM、贝叶斯分类、二叉树、CNN实现手写数字识别

Common core resource objects of kubernetes

Alibaba interview question: multi thread related

Arm learning (7) symbol table and debugging

Shardingsphere-proxy-5.0.0 implementation of capacity range partition (V)

【Redis进阶之ZipList】如果再有人问你什么是压缩列表?请把这篇文章直接甩给他。

Social recruitment interview is indispensable -- 1000 interview questions for Android engineers from Internet companies

What should I pay attention to in the interview of artificial intelligence technology?

使用worker报错:Uncaught DOMException: Failed to construct ‘Worker’: Script at***

智能制造时代下,MES管理系统需要解决哪些问题
随机推荐
分别用SVM、贝叶斯分类、二叉树、CNN实现手写数字识别
【ICPR 2021】遥感图中的密集小目标检测:Tiny Object Detection in Aerial Images
ShardingSphere-proxy-5.0.0容量范围分片的实现(五)
[CVPR 2022] high resolution small object detection: cascaded sparse query for accelerating high resolution smal object detection
Efficient integration of heterogeneous single cell transcriptome with scanorama
[CVPR 2020 oral] a physics based noise formation model for extreme low light raw denoising
Everything I see is the category of my precise positioning! Open source of a new method for saliency map visualization
Echo framework: automatically add requestid
对抗训练理论分析:自适应步长快速对抗训练
Apple iphone14 is equipped with Beidou navigation system. What are the advantages of Beidou vs GPS?
【虹科案例】3D数据如何成为可操作的信息?– 对象检测和跟踪
想开户炒股,通过网上进行股票开户安全吗?-
Pad User Guide
Installation and use of winscp and putty
杂乱的知识点
Empty encoded password警告原因
Google Earth engine (GEE) - verification results used by NDVI, NDWI and NDBI to increase classification accuracy (random forest and cart classification)
C language: recursively implementing factorial of n
牛学长周年庆活动:软件大促限时抢,注册码免费送!
【ICCV Workshop 2021】基于密度图的小目标检测:Coarse-grained Density Map Guided Object Detection in Aerial Images