Fix update logic of minRt in bucket
- Fix incorrect usage. It's not thread-safe when comparing and updating `minRt`, but it's okay since the actual minimum RT often matches free load. Signed-off-by: Eric Zhao <sczyh16@gmail.com>
This commit is contained in:
parent
6392cb0336
commit
820160d542
|
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.alibaba.csp.sentinel.slots.statistic.base;
|
package com.alibaba.csp.sentinel.slots.statistic.base;
|
||||||
|
|
||||||
|
import com.alibaba.csp.sentinel.Constants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents metrics data in a period of time window.
|
* Represents metrics data in a period of time window.
|
||||||
*
|
*
|
||||||
|
|
@ -28,14 +30,15 @@ public class Window {
|
||||||
private final LongAdder exception = new LongAdder();
|
private final LongAdder exception = new LongAdder();
|
||||||
private final LongAdder rt = new LongAdder();
|
private final LongAdder rt = new LongAdder();
|
||||||
private final LongAdder success = new LongAdder();
|
private final LongAdder success = new LongAdder();
|
||||||
private final LongAdder minRt = new LongAdder();
|
|
||||||
|
private volatile long minRt;
|
||||||
|
|
||||||
public Window() {
|
public Window() {
|
||||||
initMinRt();
|
initMinRt();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMinRt() {
|
private void initMinRt() {
|
||||||
minRt.add(4900);
|
this.minRt = Constants.TIME_DROP_VALVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,7 +52,6 @@ public class Window {
|
||||||
exception.reset();
|
exception.reset();
|
||||||
rt.reset();
|
rt.reset();
|
||||||
success.reset();
|
success.reset();
|
||||||
minRt.reset();
|
|
||||||
initMinRt();
|
initMinRt();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -71,7 +73,7 @@ public class Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long minRt() {
|
public long minRt() {
|
||||||
return minRt.longValue();
|
return minRt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long success() {
|
public long success() {
|
||||||
|
|
@ -97,8 +99,9 @@ public class Window {
|
||||||
public void addRT(long rt) {
|
public void addRT(long rt) {
|
||||||
this.rt.add(rt);
|
this.rt.add(rt);
|
||||||
|
|
||||||
if (minRt.longValue() > rt) {
|
// Not thread-safe, but it's okay.
|
||||||
minRt.internalReset(rt);
|
if (rt < minRt) {
|
||||||
|
minRt = rt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package com.alibaba.csp.sentinel.slots.statistic.metric;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.alibaba.csp.sentinel.Constants;
|
||||||
import com.alibaba.csp.sentinel.node.metric.MetricNode;
|
import com.alibaba.csp.sentinel.node.metric.MetricNode;
|
||||||
import com.alibaba.csp.sentinel.slots.statistic.base.Window;
|
import com.alibaba.csp.sentinel.slots.statistic.base.Window;
|
||||||
import com.alibaba.csp.sentinel.slots.statistic.base.WindowWrap;
|
import com.alibaba.csp.sentinel.slots.statistic.base.WindowWrap;
|
||||||
|
|
@ -117,7 +118,7 @@ public class ArrayMetric implements Metric {
|
||||||
@Override
|
@Override
|
||||||
public long minRt() {
|
public long minRt() {
|
||||||
data.currentWindow();
|
data.currentWindow();
|
||||||
long rt = 4900;
|
long rt = Constants.TIME_DROP_VALVE;
|
||||||
List<Window> list = data.values();
|
List<Window> list = data.values();
|
||||||
for (Window window : list) {
|
for (Window window : list) {
|
||||||
if (window.minRt() < rt) {
|
if (window.minRt() < rt) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue