Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RIP-70-3]Extract adaptive lock mechanism #8663

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from

Conversation

3424672656
Copy link
Contributor

@3424672656 3424672656 commented Sep 7, 2024

Which Issue(s) This PR Fixes

Fixes #8442

Brief Description

How Did You Test This Change?

Test document :https://shimo.im/docs/ZzkLMQ4RwwUa87AQ/

@codecov-commenter
Copy link

codecov-commenter commented Sep 7, 2024

Codecov Report

Attention: Patch coverage is 62.40602% with 50 lines in your changes missing coverage. Please review.

Project coverage is 47.36%. Comparing base (daf3d1a) to head (56606d3).

Files with missing lines Patch % Lines
...e/rocketmq/store/lock/AdaptiveBackOffLockImpl.java 56.62% 31 Missing and 5 partials ⚠️
...ache/rocketmq/store/config/MessageStoreConfig.java 37.50% 5 Missing ⚠️
...rg/apache/rocketmq/store/lock/BackOffSpinLock.java 84.37% 4 Missing and 1 partial ⚠️
...main/java/org/apache/rocketmq/store/CommitLog.java 66.66% 0 Missing and 2 partials ⚠️
...pache/rocketmq/store/lock/AdaptiveBackOffLock.java 33.33% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #8663      +/-   ##
=============================================
- Coverage      47.51%   47.36%   -0.16%     
+ Complexity     11591    11578      -13     
=============================================
  Files           1282     1285       +3     
  Lines          89848    89979     +131     
  Branches       11557    11579      +22     
=============================================
- Hits           42692    42617      -75     
- Misses         41931    42109     +178     
- Partials        5225     5253      +28     
Flag Coverage Δ
47.36% <62.40%> (-0.16%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@fuyou001 fuyou001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR need

Comment on lines 97 to 114
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is RetreatLock? Is it a misspelling of reentrant lock?

private final List<AtomicInteger> numberOfRetreat;

public CollisionRetreatLock() {
this.initOptimalDegree = 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd better make these numbers as constants, like OPTIMAL_DEGREE = 1000, MAX_OPTIMAL_DEGREE = 10000

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RIP-70] Optimizing Lock Mechanisms
4 participants