diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Window.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Window.java index 9c0fea76..e5a87b04 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Window.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Window.java @@ -15,6 +15,8 @@ */ package com.alibaba.csp.sentinel.slots.statistic.base; +import com.alibaba.csp.sentinel.Constants; + /** * 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 rt = new LongAdder(); private final LongAdder success = new LongAdder(); - private final LongAdder minRt = new LongAdder(); + + private volatile long minRt; public Window() { initMinRt(); } private void initMinRt() { - minRt.add(4900); + this.minRt = Constants.TIME_DROP_VALVE; } /** @@ -49,7 +52,6 @@ public class Window { exception.reset(); rt.reset(); success.reset(); - minRt.reset(); initMinRt(); return this; } @@ -71,7 +73,7 @@ public class Window { } public long minRt() { - return minRt.longValue(); + return minRt; } public long success() { @@ -97,8 +99,9 @@ public class Window { public void addRT(long rt) { this.rt.add(rt); - if (minRt.longValue() > rt) { - minRt.internalReset(rt); + // Not thread-safe, but it's okay. + if (rt < minRt) { + minRt = rt; } } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/metric/ArrayMetric.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/metric/ArrayMetric.java index 6eb7df7e..433a681d 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/metric/ArrayMetric.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/metric/ArrayMetric.java @@ -18,6 +18,7 @@ package com.alibaba.csp.sentinel.slots.statistic.metric; import java.util.ArrayList; import java.util.List; +import com.alibaba.csp.sentinel.Constants; 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.WindowWrap; @@ -117,7 +118,7 @@ public class ArrayMetric implements Metric { @Override public long minRt() { data.currentWindow(); - long rt = 4900; + long rt = Constants.TIME_DROP_VALVE; List list = data.values(); for (Window window : list) { if (window.minRt() < rt) {