Skip to content

Commit

Permalink
Optimize code style
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghuaiyuan committed Sep 27, 2024
1 parent 61a9354 commit c7abdd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public class MessageStoreConfig {
/**
* Use AdaptiveBackOffLock
**/
private boolean isUseABSLock = true;
private boolean isUseABSLock = false;

public int getBatchWriteKvCqSize() {
return batchWriteKvCqSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public class AdaptiveBackOffLockImpl implements AdaptiveBackOffLock {
//state
private AtomicBoolean state = new AtomicBoolean(true);

private final static float SWAP_MUTEX_LOCK_RATIO = 0.8f;
private final static float SWAP_SPIN_LOCK_RATIO = 0.8f;

private final static float SPIN_LOCK_ADAPTIVE_RATIO = 1.5f;

private final static int BASE_SWAP_LOCK_RATIO = 200;

private Map<String, AdaptiveBackOffLock> locks;

private final List<AtomicInteger> tpsTable;
Expand Down Expand Up @@ -91,7 +93,7 @@ public void swap() {
return;
}
boolean needSwap = false;
int slot = LocalTime.now().getSecond() % 2 - 1 >= 0 ? 0 : 1;
int slot = 1 - LocalTime.now().getSecond() % 2;
int tps = this.tpsTable.get(slot).get() + 1;
this.tpsTable.get(slot).set(-1);
if (tps == 0) {
Expand All @@ -100,20 +102,19 @@ public void swap() {

if (this.adaptiveLock instanceof BackOffSpinLock) {
BackOffSpinLock lock = (BackOffSpinLock) this.adaptiveLock;
int base = Math.min(200 + tps / 200, 500);
if (lock.getNumberOfRetreat(slot) * base >= tps) {
if (lock.getNumberOfRetreat(slot) * BASE_SWAP_LOCK_RATIO >= tps) {
if (lock.isAdapt()) {
lock.adapt(true);
} else {
this.tpsSwapCriticalPoint = tps;
needSwap = true;
}
} else if (lock.getNumberOfRetreat(slot) * base * SPIN_LOCK_ADAPTIVE_RATIO <= tps) {
} else if (lock.getNumberOfRetreat(slot) * BASE_SWAP_LOCK_RATIO * SPIN_LOCK_ADAPTIVE_RATIO <= tps) {
lock.adapt(false);
}
lock.setNumberOfRetreat(slot, 0);
} else {
if (tps <= this.tpsSwapCriticalPoint * SWAP_MUTEX_LOCK_RATIO) {
if (tps <= this.tpsSwapCriticalPoint * SWAP_SPIN_LOCK_RATIO) {
needSwap = true;
}
}
Expand Down

0 comments on commit c7abdd3

Please sign in to comment.