master
parent
b8a0bb1eec
commit
0dfd92682c
|
@ -82,48 +82,44 @@ public class Timer {
|
||||||
* @Param: []
|
* @Param: []
|
||||||
* @Return: void
|
* @Return: void
|
||||||
**/
|
**/
|
||||||
public void dynamicReduction() {
|
// public void dynamicReduction() {
|
||||||
//求出所有的节点ID
|
// //求出所有的节点ID
|
||||||
List<String> nodeIds = gatewayNodeIdCache.get();
|
// List<String> nodeIds = gatewayNodeIdCache.get();
|
||||||
|
//
|
||||||
if (nodeIds.size() <= 1) {
|
// if (nodeIds.size() <= 1) {
|
||||||
log.error("暂无节点可删除!");
|
// log.error("暂无节点可删除!");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
//先获取所有的负载列表
|
// //先获取所有的负载列表
|
||||||
List<IpAndLoadCount> ipAndLoadCounts = gatewayIpAndLoadCountCache.get();
|
// List<IpAndLoadCount> ipAndLoadCounts = gatewayIpAndLoadCountCache.get();
|
||||||
if (ipAndLoadCounts.size() <= 1) {
|
// if (ipAndLoadCounts.size() <= 1) {
|
||||||
log.error("负载列表为空!");
|
// log.error("负载列表为空!");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//计算所有节点的负载
|
// //计算所有节点的负载
|
||||||
int connectSize = ipAndLoadCounts.stream().mapToInt(IpAndLoadCount::getLoadCount).sum();
|
// int connectSize = ipAndLoadCounts.stream().mapToInt(IpAndLoadCount::getLoadCount).sum();
|
||||||
|
//
|
||||||
//求出平均值
|
// //求出平均值
|
||||||
int avg = connectSize / ipAndLoadCounts.size();
|
// int avg = connectSize / ipAndLoadCounts.size();
|
||||||
|
//
|
||||||
if (avg <= 30) {
|
// if (avg <= 30) {
|
||||||
String request = "";
|
//
|
||||||
|
//
|
||||||
for (String nodeId : nodeIds) {
|
// request = request.substring(0, request.length() - 1);
|
||||||
request = nodeId + ",";
|
//
|
||||||
}
|
// //执行节点缩容
|
||||||
|
// try {
|
||||||
request = request.substring(0, request.length() - 1);
|
// aliYunEcsService.releaseInstances(request);
|
||||||
|
// } catch (Exception e) {
|
||||||
//执行节点缩容
|
// throw new RuntimeException("节点缩容失败!" + e.getMessage());
|
||||||
try {
|
// }
|
||||||
aliYunEcsService.releaseInstances(request);
|
// } else {
|
||||||
} catch (Exception e) {
|
// log.info("暂时不需要缩容");
|
||||||
throw new RuntimeException("节点缩容失败!" + e.getMessage());
|
// }
|
||||||
}
|
// }
|
||||||
} else {
|
|
||||||
log.info("暂时不需要缩容");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue