当前位置:网站首页>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 )
边栏推荐
- AI视频智能平台EasyCVR设备录像出现无法播放现象的问题修复
- [microservice openfeign] feign's log record
- How to create an exclusive vs Code theme
- Microsoft announces open source (Godel) language model chat robot
- 热烈祝贺五行和合酒成功挂牌
- redisson使用全解——redisson官方文档+注释(中篇)
- 為什麼這麼多人轉行產品經理?產品經理發展前景如何?
- 【微服务|openfeign】Feign的日志记录
- Stepsister becomes stepmother, son breaks off relationship with himself, and musk, the world's richest man, why is it so miserable?
- ctfshow-web351(SSRF)
猜你喜欢

1286_FreeRTOS的任务优先级设置实现分析

Servlet 和 JSP 中的分页

Are there any practical skills for operation and maintenance management

Félicitations pour l'inscription réussie de wuxinghe

C# 读写自定义的Config文件

Ctfhub port scan (SSRF)

redisson使用全解——redisson官方文档+注释(中篇)
![[matlab] solve nonlinear programming](/img/2e/7a1f520b602b7539be479efb198f6a.png)
[matlab] solve nonlinear programming

DC-4 target

redisson使用全解——redisson官方文檔+注釋(上篇)
随机推荐
atguigu----脚手架--02-使用脚手架(2)
2022电工(中级)复训题库及答案
Ctfhub port scan (SSRF)
[image processing] image histogram equalization system with GUI interface
组件的自定义事件①
JSP - 分页
用手机在指南针上开户靠谱吗?这样有没有什么安全隐患
Is it safe and reliable for Huatai Securities to open an account? How to open Huatai Securities Account
在券商账户上买基金安全吗
运维管理有什么实用的技巧吗
DC-4靶机
【Tikhonov】基于Tikhonov正则化的图像超分辨率重建
【目标检测】目标检测界的扛把子YOLOv5(原理详解+修炼指南)
go-etcd
redisson使用全解——redisson官方文档+注释(中篇)
运维管理系统,人性化操作体验
Autosar 学习记录(1) – EcuM_Init
C language implementation [minesweeping game] full version (implementation source code)
Do securities account opening affect the security of account opening
DC-4 target