perf(系统管理): 只有开启的资源池才获取剩余并发数
This commit is contained in:
parent
c03a7f181b
commit
d4655268f1
|
@ -170,10 +170,12 @@ public class TestResourcePoolService {
|
||||||
if (StringUtils.equalsIgnoreCase(pool.getType(), ResourcePoolTypeEnum.NODE.getName())) {
|
if (StringUtils.equalsIgnoreCase(pool.getType(), ResourcePoolTypeEnum.NODE.getName())) {
|
||||||
nodeMap.put(pool.getId(), testResourceDTO.getNodesList());
|
nodeMap.put(pool.getId(), testResourceDTO.getNodesList());
|
||||||
poolDTOMap.put(pool.getId(), testResourcePoolDTO);
|
poolDTOMap.put(pool.getId(), testResourcePoolDTO);
|
||||||
Set<String> nodeSet = testResourceDTO.getNodesList().stream()
|
if (pool.getEnable()) {
|
||||||
.map(node -> node.getIp() + ":" + node.getPort())
|
Set<String> nodeSet = testResourceDTO.getNodesList().stream()
|
||||||
.collect(Collectors.toSet());
|
.map(node -> node.getIp() + ":" + node.getPort())
|
||||||
nodeSets.addAll(nodeSet);
|
.collect(Collectors.toSet());
|
||||||
|
nodeSets.addAll(nodeSet);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//处理k8s资源池
|
//处理k8s资源池
|
||||||
testResourcePoolDTO.setMaxConcurrentNumber(testResourceDTO.getConcurrentNumber());
|
testResourcePoolDTO.setMaxConcurrentNumber(testResourceDTO.getConcurrentNumber());
|
||||||
|
@ -181,7 +183,7 @@ public class TestResourcePoolService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//处理node资源池
|
//处理node资源池
|
||||||
Map<String,Integer>lastConcurrentNumberMap = new HashMap<>();
|
Map<String, Integer> lastConcurrentNumberMap = new HashMap<>();
|
||||||
|
|
||||||
List<Future<Map<String, Integer>>> futures = new ArrayList<>();
|
List<Future<Map<String, Integer>>> futures = new ArrayList<>();
|
||||||
for (String nodeSet : nodeSets) {
|
for (String nodeSet : nodeSets) {
|
||||||
|
@ -189,7 +191,7 @@ public class TestResourcePoolService {
|
||||||
String[] split = nodeSet.split(":");
|
String[] split = nodeSet.split(":");
|
||||||
ResourcePoolNodeMetric nodeMetric = getNodeMetric(split[0], split[1]);
|
ResourcePoolNodeMetric nodeMetric = getNodeMetric(split[0], split[1]);
|
||||||
Map<String, Integer> resultMap = new HashMap<>();
|
Map<String, Integer> resultMap = new HashMap<>();
|
||||||
if (nodeMetric!=null) {
|
if (nodeMetric != null) {
|
||||||
resultMap.put(nodeSet, nodeMetric.getConcurrentNumber() - nodeMetric.getOccupiedConcurrentNumber());
|
resultMap.put(nodeSet, nodeMetric.getConcurrentNumber() - nodeMetric.getOccupiedConcurrentNumber());
|
||||||
}
|
}
|
||||||
return resultMap;
|
return resultMap;
|
||||||
|
@ -201,20 +203,22 @@ public class TestResourcePoolService {
|
||||||
lastConcurrentNumberMap.putAll(future.get());
|
lastConcurrentNumberMap.putAll(future.get());
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
// 处理异常
|
// 处理异常
|
||||||
LogUtils.error("获取剩余并发数失败:"+ e);
|
LogUtils.error("获取剩余并发数失败:" + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nodeMap.forEach((poolId,nodeList)->{
|
nodeMap.forEach((poolId, nodeList) -> {
|
||||||
int lastConcurrentNumber = 0;
|
int lastConcurrentNumber = 0;
|
||||||
int maxConcurrentNumber = 0;
|
int maxConcurrentNumber = 0;
|
||||||
for (TestResourceNodeDTO testResourceNodeDTO : nodeList) {
|
for (TestResourceNodeDTO testResourceNodeDTO : nodeList) {
|
||||||
if (lastConcurrentNumberMap.get(testResourceNodeDTO.getIp() + ":" + testResourceNodeDTO.getPort())!=null) {
|
if (lastConcurrentNumberMap.get(testResourceNodeDTO.getIp() + ":" + testResourceNodeDTO.getPort()) != null) {
|
||||||
lastConcurrentNumber = lastConcurrentNumber+lastConcurrentNumberMap.get(testResourceNodeDTO.getIp() + ":" + testResourceNodeDTO.getPort());
|
lastConcurrentNumber = lastConcurrentNumber + lastConcurrentNumberMap.get(testResourceNodeDTO.getIp() + ":" + testResourceNodeDTO.getPort());
|
||||||
}
|
}
|
||||||
maxConcurrentNumber = maxConcurrentNumber + testResourceNodeDTO.getConcurrentNumber();
|
maxConcurrentNumber = maxConcurrentNumber + testResourceNodeDTO.getConcurrentNumber();
|
||||||
}
|
}
|
||||||
TestResourcePoolDTO testResourcePoolDTO = poolDTOMap.get(poolId);
|
TestResourcePoolDTO testResourcePoolDTO = poolDTOMap.get(poolId);
|
||||||
testResourcePoolDTO.setLastConcurrentNumber(lastConcurrentNumber);
|
if (testResourcePoolDTO.getEnable()) {
|
||||||
|
testResourcePoolDTO.setLastConcurrentNumber(lastConcurrentNumber);
|
||||||
|
}
|
||||||
testResourcePoolDTO.setMaxConcurrentNumber(maxConcurrentNumber);
|
testResourcePoolDTO.setMaxConcurrentNumber(maxConcurrentNumber);
|
||||||
testResourcePoolDTOS.add(testResourcePoolDTO);
|
testResourcePoolDTOS.add(testResourcePoolDTO);
|
||||||
});
|
});
|
||||||
|
@ -353,7 +357,7 @@ public class TestResourcePoolService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
private void shutdownExecutor() {
|
public void shutdownExecutor() {
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue