master
parent
b8a0bb1eec
commit
0dfd92682c
|
@ -82,48 +82,44 @@ public class Timer {
|
|||
* @Param: []
|
||||
* @Return: void
|
||||
**/
|
||||
public void dynamicReduction() {
|
||||
//求出所有的节点ID
|
||||
List<String> nodeIds = gatewayNodeIdCache.get();
|
||||
|
||||
if (nodeIds.size() <= 1) {
|
||||
log.error("暂无节点可删除!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//先获取所有的负载列表
|
||||
List<IpAndLoadCount> 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<String> nodeIds = gatewayNodeIdCache.get();
|
||||
//
|
||||
// if (nodeIds.size() <= 1) {
|
||||
// log.error("暂无节点可删除!");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //先获取所有的负载列表
|
||||
// List<IpAndLoadCount> 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("暂时不需要缩容");
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue