parent
9c409d7ab5
commit
5f5972e6b3
|
@ -18,6 +18,6 @@ public class WorkGatewayNode {
|
||||||
/**
|
/**
|
||||||
* 分数
|
* 分数
|
||||||
*/
|
*/
|
||||||
private Double source;
|
private int weight;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class GatewayLoadServiceImpl implements GatewayLoadService {
|
||||||
.map(workGatewayNode ->
|
.map(workGatewayNode ->
|
||||||
WorkGatewayNodeSource.builder()
|
WorkGatewayNodeSource.builder()
|
||||||
.nodeId(workGatewayNode.getNodeId())
|
.nodeId(workGatewayNode.getNodeId())
|
||||||
.weight(Integer.parseInt(String.valueOf(vehicleOnlineNum / (nodeMaxNum - workGatewayNode.getSource()))))
|
.weight(Integer.parseInt(String.valueOf(vehicleOnlineNum / (nodeMaxNum - workGatewayNode.getWeight()))))
|
||||||
.build())
|
.build())
|
||||||
.toList();
|
.toList();
|
||||||
// 计算节点列表中所有节点的权重之和
|
// 计算节点列表中所有节点的权重之和
|
||||||
|
@ -164,7 +164,8 @@ public class GatewayLoadServiceImpl implements GatewayLoadService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 当所有节点权重为0时,跳出循环
|
// 当所有节点权重为0时,跳出循环
|
||||||
whFor:while (true) {
|
whFor:
|
||||||
|
while (true) {
|
||||||
// 遍历节点列表,将权重大于0的节点ID添加到loadNodeList中,并将节点权重减1
|
// 遍历节点列表,将权重大于0的节点ID添加到loadNodeList中,并将节点权重减1
|
||||||
for (WorkGatewayNodeSource workGatewayNodeSource : workGatewayNodeSources) {
|
for (WorkGatewayNodeSource workGatewayNodeSource : workGatewayNodeSources) {
|
||||||
int weight = workGatewayNodeSource.getWeight();
|
int weight = workGatewayNodeSource.getWeight();
|
||||||
|
@ -223,7 +224,33 @@ public class GatewayLoadServiceImpl implements GatewayLoadService {
|
||||||
log.info("实例id和公网ip存入redis");
|
log.info("实例id和公网ip存入redis");
|
||||||
|
|
||||||
} else if (loadRate.longValue() < 20L) {
|
} else if (loadRate.longValue() < 20L) {
|
||||||
|
if (nodeList.size() > 2) {
|
||||||
|
log.info("负载率:[{}]", loadRate);
|
||||||
|
|
||||||
|
log.info("负载为:[{]]过低,开始缩容", loadRate.longValue());
|
||||||
|
|
||||||
|
WorkGatewayNode minConnectionNode = null;
|
||||||
|
int minConnections = Integer.MAX_VALUE;
|
||||||
|
|
||||||
|
for (WorkGatewayNode node : nodeList) {
|
||||||
|
int nodeConnections = node.getWeight();
|
||||||
|
if (nodeConnections < minConnections) {
|
||||||
|
minConnections = nodeConnections;
|
||||||
|
minConnectionNode = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// minConnectionNode 现在存储了连接数最少的节点
|
||||||
|
log.info("连接数最少的节点为:[{}]", minConnectionNode.getNodeId());
|
||||||
|
|
||||||
|
//先删除zSet,不让车连接
|
||||||
|
gatewayZSetNodeCache.remove(minConnectionNode.getNodeId());
|
||||||
|
|
||||||
|
GatewayNodeInfo gatewayNodeInfo = gatewayNodeCache.get(minConnectionNode.getNodeId());
|
||||||
|
log.info("删除节点:[{}]",gatewayNodeInfo.getNodeId());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue