瀏覽代碼

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>
master
Eric Zhao 6 年之前
父節點
當前提交
820160d542
共有 2 個檔案被更改,包括 11 行新增7 行删除
  1. +9
    -6
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Window.java
  2. +2
    -1
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/metric/ArrayMetric.java

+ 9
- 6
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;
}
}
}

+ 2
- 1
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<Window> list = data.values();
for (Window window : list) {
if (window.minRt() < rt) {


Loading…
取消
儲存