From 0dfd92682ced7ce7f33a95b521ce92b61bd1494c Mon Sep 17 00:00:00 2001 From: liuyunhu <3286117488@qq.com> Date: Fri, 19 Apr 2024 11:53:46 +0800 Subject: [PATCH] 11 --- src/main/java/com/lyh/job/Timer.java | 80 +++++++++++++--------------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/lyh/job/Timer.java b/src/main/java/com/lyh/job/Timer.java index 88bf63a..4d5315c 100644 --- a/src/main/java/com/lyh/job/Timer.java +++ b/src/main/java/com/lyh/job/Timer.java @@ -82,48 +82,44 @@ public class Timer { * @Param: [] * @Return: void **/ - public void dynamicReduction() { - //求出所有的节点ID - List nodeIds = gatewayNodeIdCache.get(); - - if (nodeIds.size() <= 1) { - log.error("暂无节点可删除!"); - return; - } - - - //先获取所有的负载列表 - List ipAndLoadCounts = gatewayIpAndLoadCountCache.get(); - if (ipAndLoadCounts.size() <= 1) { - log.error("负载列表为空!"); - return; - } - - //计算所有节点的负载 - int connectSize = ipAndLoadCounts.stream().mapToInt(IpAndLoadCount::getLoadCount).sum(); - - //求出平均值 - int avg = connectSize / ipAndLoadCounts.size(); - - if (avg <= 30) { - String request = ""; - - for (String nodeId : nodeIds) { - request = nodeId + ","; - } - - request = request.substring(0, request.length() - 1); - - //执行节点缩容 - try { - aliYunEcsService.releaseInstances(request); - } catch (Exception e) { - throw new RuntimeException("节点缩容失败!" + e.getMessage()); - } - } else { - log.info("暂时不需要缩容"); - } - } +// public void dynamicReduction() { +// //求出所有的节点ID +// List nodeIds = gatewayNodeIdCache.get(); +// +// if (nodeIds.size() <= 1) { +// log.error("暂无节点可删除!"); +// return; +// } +// +// +// //先获取所有的负载列表 +// List ipAndLoadCounts = gatewayIpAndLoadCountCache.get(); +// if (ipAndLoadCounts.size() <= 1) { +// log.error("负载列表为空!"); +// return; +// } +// +// //计算所有节点的负载 +// int connectSize = ipAndLoadCounts.stream().mapToInt(IpAndLoadCount::getLoadCount).sum(); +// +// //求出平均值 +// int avg = connectSize / ipAndLoadCounts.size(); +// +// if (avg <= 30) { +// +// +// request = request.substring(0, request.length() - 1); +// +// //执行节点缩容 +// try { +// aliYunEcsService.releaseInstances(request); +// } catch (Exception e) { +// throw new RuntimeException("节点缩容失败!" + e.getMessage()); +// } +// } else { +// log.info("暂时不需要缩容"); +// } +// } }