From 5f5443a546fe5a053a0846d8b2ebdc4e4cbe6926 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Thu, 27 Sep 2018 14:28:05 +0800 Subject: [PATCH] Update sample count for ParameterMetric Signed-off-by: Eric Zhao --- .../slots/block/flow/param/ParameterMetric.java | 2 +- .../sentinel/slots/statistic/data/ParamMapBucket.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetric.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetric.java index b0a4530e..2623eac4 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetric.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/param/ParameterMetric.java @@ -51,7 +51,7 @@ public class ParameterMetric { // putIfAbsent if (rollingParameters.get(index) == null) { rollingParameters.put(index, new HotParameterLeapArray( - 1000 / 2, IntervalProperty.INTERVAL)); + 1000 / SampleCountProperty.SAMPLE_COUNT, IntervalProperty.INTERVAL)); } } } diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/data/ParamMapBucket.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/data/ParamMapBucket.java index 9691436b..dba6fd5e 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/data/ParamMapBucket.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/data/ParamMapBucket.java @@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger; import com.alibaba.csp.sentinel.slots.block.flow.param.RollingParamEvent; import com.alibaba.csp.sentinel.slots.statistic.cache.CacheMap; import com.alibaba.csp.sentinel.slots.statistic.cache.ConcurrentLinkedHashMapWrapper; +import com.alibaba.csp.sentinel.util.AssertUtil; /** * Represents metric bucket of frequent parameters in a period of time window. @@ -32,12 +33,17 @@ public class ParamMapBucket { private final CacheMap[] data; - @SuppressWarnings("unchecked") public ParamMapBucket() { + this(DEFAULT_MAX_CAPACITY); + } + + @SuppressWarnings("unchecked") + public ParamMapBucket(int capacity) { + AssertUtil.isTrue(capacity > 0, "capacity should be positive"); RollingParamEvent[] events = RollingParamEvent.values(); this.data = new CacheMap[events.length]; for (RollingParamEvent event : events) { - data[event.ordinal()] = new ConcurrentLinkedHashMapWrapper(DEFAULT_MAX_CAPACITY); + data[event.ordinal()] = new ConcurrentLinkedHashMapWrapper(capacity); } }