当前位置:网站首页>Distributed lock
Distributed lock
2022-07-03 06:59:00 【W_ Meng_ H】
Catalog
Two 、Zookeeper Distributed lock
3、 ... and 、Redis Distributed lock
Why do I need distributed locks ?
Distributed projects , Each project is independent . The lock needs to be independent of each service , Not in service .
One 、 database
- Using primary key conflict control, only one thread can obtain the lock at a time , Non blocking 、 Do not reenter 、 Single point 、 Failure time, etc .
Two 、Zookeeper Distributed lock
zk Through temporary nodes , Solved the deadlock problem , Once the client gets the lock, it suddenly hangs up (Session Connection is broken ), Then the temporary node will be deleted automatically , Other clients automatically acquire locks , Temporary sequential nodes to solve the group shock effect ( In multiple processes / When multiple threads wait for the same resource , There will also be surprises . That is, when a resource is available , Multiple processes / The thread will wake up , Compete for resources . This is the surprise group in the operating system ).
3、 ... and 、Redis Distributed lock
settnx, Single threaded processing of network requests , There is no need to consider concurrency security , All service nodes have the same settings key, return 0, Lock acquisition fails .
setnx problem :
- Earlier versions did not have a timeout parameter , It needs to be set separately , There is a deadlock problem ( Halfway down ).
- Later versions provide atomic operations of locking and setting time , But there is a task timeout , Lock release , Causes concurrency problems , Locking and releasing locks are not the same thread problem .
Delete lock : Determine the unique ID of the thread , And then delete .
Reentry and lock renewal are not realized , adopt Redisson solve ( similar AQS The implementation of the )
redlock:redis Ensure high availability through sentinel mode , If this master For some reason, the node has switched from master to slave , Then the lock will be lost (redis Synchronization may cause data loss ).redlock Apply for locks from multiple nodes , When more than half of the nodes succeed , Lock is success ,Redisson There is a corresponding implementation .
边栏推荐
- Hands on redis master-slave replication, sentinel master-slave switching, cluster sharding
- Unit test framework + Test Suite
- 如何迁移或复制VMware虚拟机系统
- Integration test practice (1) theoretical basis
- Machine learning | simple but feature standardization methods that can improve the effect of the model (comparison and analysis of robustscaler, minmaxscaler, standardscaler)
- Asynchronous programming: async/await in asp Net
- [classes and objects] explain classes and objects in simple terms
- golang操作redis:写入、读取hash类型数据
- Laravel frame step pit (I)
- [set theory] partition (partition | partition example | partition and equivalence relationship)
猜你喜欢

【类和对象】深入浅出类和对象

2022 East China Normal University postgraduate entrance examination machine test questions - detailed solution

In depth analysis of reentrantlock fair lock and unfair lock source code implementation

Reading notes of "learn to ask questions"

10000小时定律不会让你成为编程大师,但至少是个好的起点

Personally design a highly concurrent seckill system

卡特兰数(Catalan)的应用场景

Yolov3 learning notes

The pressure of large institutions in the bear market has doubled. Will the giant whales such as gray scale, tether and micro strategy become 'giant thunder'?

Operation principle of lua on C: Foundation
随机推荐
Journal quotidien des questions (11)
【无标题】
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
The essence of interview
Daily question brushing record (11)
mysql误删root账户导致无法登录
Software testing learning - day 3
Yolov1 learning notes
Summary of UI module design and practical application of agent mode
php安装composer
MySQL transaction rollback, error points record
What are the characteristics and functions of the scientific thinking mode of mechanical view and system view
(翻译)异步编程:Async/Await在ASP.NET中的介绍
php artisan
How does the insurance company check hypertension?
Yolov3 learning notes
万卷书 - 价值投资者指南 [The Education of a Value Investor]
Laravel Web框架
[untitled]
Gridome + strapi + vercel + PM2 deployment case of [static site (3)]