From 47d9070a4a0a73bffb92b713b86fce80bdd7996b Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Mon, 30 Jul 2018 18:10:56 +0800 Subject: [PATCH] Fixes #9: Use named thread factory for identification (#10) * Use named thread factory with all thread pools for identification Signed-off-by: Eric Zhao --- .../csp/sentinel/slots/block/degrade/DegradeRule.java | 3 ++- .../csp/sentinel/slots/block/flow/FlowRuleManager.java | 4 +++- .../csp/sentinel/slots/system/SystemRuleManager.java | 4 +++- .../csp/sentinel/dashboard/metric/MetricFetcher.java | 7 ++++--- .../csp/sentinel/datasource/AutoRefreshDataSource.java | 4 +++- .../sentinel/transport/init/HeartbeatSenderInitFunc.java | 4 +++- .../sentinel/transport/command/NettyHttpCommandCenter.java | 4 +++- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java index 48b9a810..44f51c4f 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java @@ -20,6 +20,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; +import com.alibaba.csp.sentinel.concurrent.NamedThreadFactory; import com.alibaba.csp.sentinel.context.Context; import com.alibaba.csp.sentinel.node.ClusterNode; import com.alibaba.csp.sentinel.node.DefaultNode; @@ -56,7 +57,7 @@ public class DegradeRule extends AbstractRule { private static final int RT_MAX_EXCEED_N = 5; private static ScheduledExecutorService pool = Executors.newScheduledThreadPool( - Runtime.getRuntime().availableProcessors()); + Runtime.getRuntime().availableProcessors(), new NamedThreadFactory("sentinel-degrade-reset-task", true)); /** * RT threshold or exception ratio threshold count. diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java index decc6c2e..631b7b89 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java @@ -23,6 +23,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import com.alibaba.csp.sentinel.concurrent.NamedThreadFactory; import com.alibaba.csp.sentinel.log.RecordLog; import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.context.Context; @@ -54,7 +55,8 @@ import com.alibaba.csp.sentinel.slots.block.flow.controller.WarmUpController; public class FlowRuleManager { private static final Map> flowRules = new ConcurrentHashMap>(); - private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, + new NamedThreadFactory("sentinel-metrics-record-task", true)); private final static FlowPropertyListener listener = new FlowPropertyListener(); private static SentinelProperty> currentProperty = new DynamicSentinelProperty>(); diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java index c8e6378b..21f6ee4f 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import com.alibaba.csp.sentinel.Constants; import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.concurrent.NamedThreadFactory; import com.alibaba.csp.sentinel.log.RecordLog; import com.alibaba.csp.sentinel.property.DynamicSentinelProperty; import com.alibaba.csp.sentinel.property.SentinelProperty; @@ -82,7 +83,8 @@ public class SystemRuleManager { private final static SystemPropertyListener listener = new SystemPropertyListener(); private static SentinelProperty> currentProperty = new DynamicSentinelProperty>(); - private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, + new NamedThreadFactory("sentinel-system-status-record-task", true)); static { checkSystemStatus.set(false); diff --git a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java index b0345b3e..630c66ef 100755 --- a/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java +++ b/sentinel-dashboard/src/main/java/com/taobao/csp/sentinel/dashboard/metric/MetricFetcher.java @@ -83,7 +83,8 @@ public class MetricFetcher { private AppManagement appManagement; private CloseableHttpAsyncClient httpclient; - private ScheduledExecutorService fetchScheduleService = Executors.newScheduledThreadPool(1); + private ScheduledExecutorService fetchScheduleService = Executors.newScheduledThreadPool(1, + new NamedThreadFactory("sentinel-dashboard-metrics-fetch-task")); private ExecutorService fetchService; private ExecutorService fetchWorker; @@ -94,10 +95,10 @@ public class MetricFetcher { RejectedExecutionHandler handler = new DiscardPolicy(); fetchService = new ThreadPoolExecutor(cores, cores, keepAliveTime, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(queueSize), - new NamedThreadFactory("fetchService"), handler); + new NamedThreadFactory("sentinel-dashboard-metrics-fetchService"), handler); fetchWorker = new ThreadPoolExecutor(cores, cores, keepAliveTime, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(queueSize), - new NamedThreadFactory("fetchWorker"), handler); + new NamedThreadFactory("sentinel-dashboard-metrics-fetchWorker"), handler); IOReactorConfig ioConfig = IOReactorConfig.custom() .setConnectTimeout(3000) .setSoTimeout(3000) diff --git a/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/AutoRefreshDataSource.java b/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/AutoRefreshDataSource.java index bff3d588..645c4180 100755 --- a/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/AutoRefreshDataSource.java +++ b/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/AutoRefreshDataSource.java @@ -19,6 +19,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import com.alibaba.csp.sentinel.concurrent.NamedThreadFactory; import com.alibaba.csp.sentinel.log.RecordLog; /** @@ -48,7 +49,8 @@ public abstract class AutoRefreshDataSource extends AbstractDataSource