[RIP-70-3]Extract adaptive lock mechanism#8663
[RIP-70-3]Extract adaptive lock mechanism#8663RongtongJin merged 65 commits intoapache:developapache/rocketmq:developfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #8663 +/- ##
=============================================
- Coverage 47.39% 47.37% -0.03%
- Complexity 11628 11645 +17
=============================================
Files 1290 1294 +4
Lines 90293 90424 +131
Branches 11609 11627 +18
=============================================
+ Hits 42795 42834 +39
- Misses 42231 42306 +75
- Partials 5267 5284 +17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
# Conflicts: # store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveLockImpl.java # store/src/main/java/org/apache/rocketmq/store/lock/CollisionRetreatLock.java
| if (this.adaptiveLock instanceof CollisionRetreatLock) { | ||
| CollisionRetreatLock lock = (CollisionRetreatLock) this.adaptiveLock; | ||
| int base = Math.min(200 + tps / 200, 500); | ||
| if (lock.getNumberOfRetreat(slot) * base >= tps) { | ||
| if (lock.isAdapt()) { | ||
| lock.adapt(true); | ||
| } else { | ||
| this.tpsSwapCriticalPoint = tps; | ||
| needSwap = true; | ||
| } | ||
| } else if (lock.getNumberOfRetreat(slot) * base * 3 / 2 <= tps) { | ||
| lock.adapt(false); | ||
| } | ||
| lock.setNumberOfRetreat(slot, 0); | ||
| } else { | ||
| if (tps <= this.tpsSwapCriticalPoint * 4 / 5) { | ||
| needSwap = true; | ||
| } |
There was a problem hiding this comment.
Too many magic numbers, it should be optimized.
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| public class CollisionRetreatLock implements AdaptiveBackOffLock { |
There was a problem hiding this comment.
What is RetreatLock? Is it a misspelling of reentrant lock?
| private final List<AtomicInteger> numberOfRetreat; | ||
|
|
||
| public CollisionRetreatLock() { | ||
| this.initOptimalDegree = 1000; |
There was a problem hiding this comment.
You'd better make these numbers as constants, like OPTIMAL_DEGREE = 1000, MAX_OPTIMAL_DEGREE = 10000
|
|
||
| public interface AdaptiveBackOffSpinLock extends PutMessageLock { | ||
|
|
||
| void lock(); |
There was a problem hiding this comment.
The PutMessageLock class includes methods for locking and unlocking.
| }; | ||
| this.putMessageLock = messageStore.getMessageStoreConfig().isUseReentrantLockWhenPutMessage() ? new PutMessageReentrantLock() : new PutMessageSpinLock(); | ||
|
|
||
| AdaptiveBackOffSpinLock adaptiveBackOffSpinLock = new AdaptiveBackOffSpinLockImpl(); |
There was a problem hiding this comment.
PutMessageLock adaptiveBackOffSpinLock = new AdaptiveBackOffSpinLockImpl() may be better
| } | ||
| } | ||
|
|
||
| if (needSwap) { |
There was a problem hiding this comment.
Add some comments to explain the principles and the rationale behind these numbers.
|
|
||
| public AdaptiveBackOffSpinLockImpl() { | ||
| this.locks = new HashMap<>(); | ||
| this.locks.put("Reentrant", new BackOffReentrantLock()); |
There was a problem hiding this comment.
These strings use class constants.
… adaptive_lock # Conflicts: # store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java
# Conflicts: # store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java
* extract the adaptive lock * extract the adaptive lock * feat(): perfect the adaptive lock * feat(): perfect the adaptive lock * Optimized code type * Optimized code type * Optimized code type * fix fail test * Optimize the adaptive locking mechanism logic * Optimize the adaptive locking mechanism logic * feat:Adaptive locking mechanism adjustment * feat:Adaptive locking mechanism adjustment * feat:Adaptive locking mechanism adjustment * Optimize the adaptive locking mechanism logic * Optimize the adaptive locking mechanism logic * Optimize the adaptive locking mechanism logic * feat:Supports the hot activation of ABS locks * feat:Supports the hot activation of ABS locks * feat:Supports the hot activation of ABS locks * feat:Supports the hot activation of ABS locks * Optimize code style * Optimize code style * Optimize code style * Optimize code style * Optimize code style * Optimize code style * Updated the locking mechanism name * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * delete unused import * Optimize the logic of switching to spin locks * Revert "Optimize the logic of switching to spin locks" This reverts commit 1d7bac5. * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimize the logic of switching to spin locks * Optimized locking logic * Optimized locking logic * Optimized locking logic * fix test * fix test * fix test * fix test * Optimize code style * Optimize code style * fix test * fix test * optimize client rebalancing logic --------- Co-authored-by: wanghuaiyuan <wanghuaiyuan@xiaomi.com>
Which Issue(s) This PR Fixes
Fixes #8442
Brief Description
How Did You Test This Change?
Test document :https://shimo.im/docs/ZzkLMQ4RwwUa87AQ/