当前位置:网站首页>Redisson watchdog mechanism, redisson watchdog performance problems, redisson source code analysis
Redisson watchdog mechanism, redisson watchdog performance problems, redisson source code analysis
2022-07-01 07:19:00 【Bald and weak.】
List of articles
redisson The watchdog mechanism
Website to explain
Redisson Inside a watchdog lock is provided , Its function is to Redisson Before the instance is closed , Keep extending the validity of lock . By default , The timeout for the watchdog to check the lock is 30 Second , You can also modify Config.lockWatchdogTimeout To specify otherwise .
Watchdog open condition
We can see ,leaseTime != -1 when , Only execute tryLockInnerAsync Method , In other cases, the following code will be executed , and leaseTime That's what we call
lock(10, TimeUnit.SECONDS); The time parameter passed in by the method .
Thus we can see that :redisson If you just use lock.lock(); If the expiration time is not transmitted , Will activate the watchdog mechanism , If you send the expiration time , The watchdog mechanism will not be activated .
// org.redisson.RedissonLock#tryAcquireAsync
private <T> RFuture<Long> tryAcquireAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId) {
if (leaseTime != -1) {
return tryLockInnerAsync(waitTime, leaseTime, unit, threadId, RedisCommands.EVAL_LONG);
}
RFuture<Long> ttlRemainingFuture = tryLockInnerAsync(waitTime,
commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout(),
TimeUnit.MILLISECONDS, threadId, RedisCommands.EVAL_LONG);
// future Pattern , After grabbing the lock, open the watchdog
ttlRemainingFuture.onComplete((ttlRemaining, e) -> {
if (e != null) {
return;
}
// lock acquired
if (ttlRemaining == null) {
scheduleExpirationRenewal(threadId); // Open the watchdog
}
});
return ttlRemainingFuture;
}
How the watchdog opens
The following code is the way to open the watchdog , We can see , It starts a TimerTask Count down , The default countdown time is internalLockLeaseTime / 3, Which is the default 10 Second ( The default expiration time is 30 second ).
// org.redisson.RedissonLock#renewExpiration
private void renewExpiration() {
ExpirationEntry ee = EXPIRATION_RENEWAL_MAP.get(getEntryName());
if (ee == null) {
return;
}
Timeout task = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
ExpirationEntry ent = EXPIRATION_RENEWAL_MAP.get(getEntryName());
if (ent == null) {
return;
}
Long threadId = ent.getFirstThreadId();
if (threadId == null) {
return;
}
// Key methods , Use lua Script refresh expiration time
RFuture<Boolean> future = renewExpirationAsync(threadId);
future.onComplete((res, e) -> {
if (e != null) {
log.error("Can't update lock " + getName() + " expiration", e);
return;
}
if (res) {
// reschedule itself
renewExpiration(); // Constantly calling yourself , Refresh expiration time
}
});
}
}, internalLockLeaseTime / 3, TimeUnit.MILLISECONDS);
ee.setTimeout(task);
}
The performance of the watchdog
Many kids think that the watchdog is very performance consuming , In fact, there will be some performance consumption , But not many .
A few days ago, a little friend threw a question : Suppose every thread starts one TimerTask To constantly refresh the expiration time , Isn't it that the server will soon “ Fried ”?
It's not , Only the thread that preempts the lock will open the watchdog , Not every waiting thread will open a watchdog . in other words —— Basically, each lock corresponds to a watchdog , Instead of each thread corresponding to a watchdog .
So it looks like , Isn't there a lot of performance waste ?
In fact, the watchdog mechanism is mainly used for the execution time of business code varying from long to short , If a business code , We're sure it's 10 The execution will be completed in seconds , This watchdog mechanism can be completely abolished , To improve some performance .
Powerful redisson
redisson Very powerful , It perfectly solves many problems under the distributed system .
Please refer to the document for details :
redisson Use the total solution ——redisson Official documents + notes ( Part 1 )
redisson Use the total solution ——redisson Official documents + notes ( medium-length )
redisson Use the total solution ——redisson Official documents + notes ( The next part )
边栏推荐
- Chinese explanation of common rclone subcommands
- [lingo] solve quadratic programming
- 如何进入互联网行业,成为产品经理?没有项目经验如何转行当上产品经理?
- Is the account opening of GF Securities safe and reliable? How to open GF Securities Account
- AI视频智能平台EasyCVR设备录像出现无法播放现象的问题修复
- Is it safe and reliable for Huatai Securities to open an account? How to open Huatai Securities Account
- How to choose a product manager course when changing to a product manager?
- [image processing] image histogram equalization system with GUI interface
- redisson看门狗机制,redisson看门狗性能问题,redisson源码解析
- 为什么这么多人转行产品经理?产品经理发展前景如何?
猜你喜欢

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)

【Flutter 问题系列第 72 篇】在 Flutter 中使用 Camera 插件拍的图片被拉伸问题的解决方案

Warm congratulations on the successful listing of five elements hehe liquor

电脑有网络,但所有浏览器网页都打不开,是怎么回事?

C # read and write customized config file

How to draw a product architecture diagram?

redisson使用全解——redisson官方文档+注释(上篇)

北漂程序员深夜emo发帖求助:女朋友走了我很孤独 ......

Understanding of Turing test and Chinese Room

Stepsister becomes stepmother, son breaks off relationship with himself, and musk, the world's richest man, why is it so miserable?
随机推荐
微软宣布开源 (GODEL) 语言模型聊天机器人
Redisson utilise la solution complète - redisson Documents officiels + commentaires (Partie 1)
Is the account opening of GF Securities safe and reliable? How to open GF Securities Account
go-etcd
ctfshow-web352,353(SSRF)
运维管理系统,人性化操作体验
ctfhub-端口扫描(SSRF)
Is it suitable for girls to study product manager? What are the advantages?
redisson看门狗机制,redisson看门狗性能问题,redisson源码解析
Which securities company is better or safer for mobile phone account opening
Those high-frequency written tests and interview questions in [Jianzhi offer & Niuke 101] - linked list
Subclasses call methods and properties of the parent class with the same name
Why are so many people turning to product managers? What is the development prospect of product manager?
Open source! Wenxin large model Ernie tiny lightweight technology, accurate and fast, full effect
[recommendation technology] matlab simulation of network information recommendation technology based on collaborative filtering
Detailed explanation of weback5 basic configuration
浏览器本地存储
转行做产品经理,如何挑选产品经理课程?
广发证券开户是安全可靠的么?怎么开广发证券账户
1286_FreeRTOS的任务优先级设置实现分析