当前位置:网站首页>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 )
边栏推荐
- 发现了一个 MySQL 的巨坑:update 更新别再用影响行数做判断了!!!
- 【图像处理】图像直方图均衡化系统含GUI界面
- How to choose a product manager course when changing to a product manager?
- Vscode automatically formats code according to eslint specification
- 【编程强训】删除公共字符(哈希映射)+组队竞赛(贪心)
- Cadence OrCAD Capture “网络名”相同,但是未连接或连接错误的解放方案之nodename的用法
- [Electrical dielectric number] electrical dielectric number and calculation considering HVDC and facts components
- EasyNVS云管理平台功能重构:支持新增用户、修改信息等
- 運維管理系統,人性化操作體驗
- iNFTnews | 从《雪崩》到百度“希壤”,元宇宙30年的16件大事
猜你喜欢
![Those high-frequency written tests and interview questions in [Jianzhi offer & Niuke 101] - linked list](/img/9a/44976b5df5567a7aff315e63569f6a.png)
Those high-frequency written tests and interview questions in [Jianzhi offer & Niuke 101] - linked list

Pourquoi tant de gens sont - ils devenus des gestionnaires de produits? Quelles sont les perspectives de développement des gestionnaires de produits?

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

Paging in servlets and JSPS

redisson使用全解——redisson官方文檔+注釋(上篇)

Image style migration cyclegan principle

【深圳IO】精确食品称(汇编语言的一些理解)

【LINGO】求解二次规划

Apple账号密码自动填充
![[lingo] find the shortest path problem of undirected graph](/img/14/1ccae0f33f5857b546d7fd0aa74c35.png)
[lingo] find the shortest path problem of undirected graph
随机推荐
ctfshow-web355,356(SSRF)
Pourquoi tant de gens sont - ils devenus des gestionnaires de produits? Quelles sont les perspectives de développement des gestionnaires de produits?
比赛即实战!中国软件杯发布全新产业创新赛项,校企可联合参赛
【编程强训2】排序子序列+倒置字符串
Cadence OrCAD capture "network name" is the same, but it is not connected or connected incorrectly. The usage of nodeName of liberation scheme
Cadence OrCAD Capture “网络名”相同,但是未连接或连接错误的解放方案之nodename的用法
DC-4 target
[microservice openfeign] feign's log record
广发证券开户是安全可靠的么?怎么开广发证券账户
【FPGA帧差】基于VmodCAM摄像头的帧差法目标跟踪FPGA实现
Why did grayscale fall from the altar?
Understanding of Turing test and Chinese Room
The programmer of Beipiao posted a post for help late at night: I am lonely when my girlfriend is gone
[recommendation technology] matlab simulation of network information recommendation technology based on collaborative filtering
Stepsister becomes stepmother, son breaks off relationship with himself, and musk, the world's richest man, why is it so miserable?
How to choose a product manager course when changing to a product manager?
JSP - paging
[Tikhonov] image super-resolution reconstruction based on Tikhonov regularization
AI视频智能平台EasyCVR设备录像出现无法播放现象的问题修复
【分类模型】Q 型聚类分析