From 878df30bbc26214c820bd0c8926094fde2488513 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Mon, 25 Feb 2019 15:04:05 +0800 Subject: [PATCH] =?UTF-8?q?LRU=E8=B7=AF=E7=94=B1=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=B8=8D=E5=8F=8A=E6=97=B6=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 3 ++- .../core/route/strategy/ExecutorRouteLFU.java | 14 ++++++++++++++ .../core/route/strategy/ExecutorRouteLRU.java | 15 ++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 8359da26..e6908506 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1427,7 +1427,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 13、执行器热部署时JobHandler重新初始化,修复由此导致的 "jobhandler naming conflicts." 问题; - 14、新增Class的加载缓存,解决频繁加载Class会使jvm的方法区空间不足导致OOM的问题; - 15、调整首页报表默认区间为本周,避免日志量太大查询缓慢; -- 16、[迭代中]任务线程隔离: +- 16、LRU路由更新不及时问题修复; +- 17、[迭代中]任务线程隔离: - 执行器测异步响应,不存在阻塞不需要隔离; - 调度中心共用单一调度线程池,可能导致调度阻塞需要线程隔离;调度线程池拆分为Fast/Slow两个,针对调度较慢的执行器地址请求,降级使用Slow线程池;考虑是否可以任务级隔离线程池; diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLFU.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLFU.java index 3bd8f370..e2289c8f 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLFU.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLFU.java @@ -33,11 +33,25 @@ public class ExecutorRouteLFU extends ExecutorRouter { lfuItemMap = new HashMap(); jobLfuMap.putIfAbsent(jobId, lfuItemMap); // 避免重复覆盖 } + + // put new for (String address: addressList) { if (!lfuItemMap.containsKey(address) || lfuItemMap.get(address) >1000000 ) { lfuItemMap.put(address, new Random().nextInt(addressList.size())); // 初始化时主动Random一次,缓解首次压力 } } + // remove old + List delKeys = new ArrayList<>(); + for (String existKey: lfuItemMap.keySet()) { + if (!addressList.contains(existKey)) { + delKeys.add(existKey); + } + } + if (delKeys.size() > 0) { + for (String delKey: delKeys) { + lfuItemMap.remove(delKey); + } + } // load least userd count address List> lfuItemList = new ArrayList>(lfuItemMap.entrySet()); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java index 1e01325e..f3acbb79 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java @@ -4,6 +4,7 @@ import com.xxl.job.admin.core.route.ExecutorRouter; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.TriggerParam; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -40,12 +41,24 @@ public class ExecutorRouteLRU extends ExecutorRouter { jobLRUMap.putIfAbsent(jobId, lruItem); } - // put + // put new for (String address: addressList) { if (!lruItem.containsKey(address)) { lruItem.put(address, address); } } + // remove old + List delKeys = new ArrayList<>(); + for (String existKey: lruItem.keySet()) { + if (!addressList.contains(existKey)) { + delKeys.add(existKey); + } + } + if (delKeys.size() > 0) { + for (String delKey: delKeys) { + lruItem.remove(delKey); + } + } // load String eldestKey = lruItem.entrySet().iterator().next().getKey();