1、定位并解决收益未自动生成问题。
2、优化服务器列表筛选条件查询速度。
This commit is contained in:
+36
-12
@@ -68,21 +68,45 @@ public class RmMtrPolicyConfigServiceImpl implements IRmMtrPolicyConfigService
|
|||||||
* 辅助方法,给ip集合赋值
|
* 辅助方法,给ip集合赋值
|
||||||
* @param mtrPolicyConfig
|
* @param mtrPolicyConfig
|
||||||
*/
|
*/
|
||||||
public void setServerip(RmMtrPolicyConfig mtrPolicyConfig){
|
public void setServerip(RmMtrPolicyConfig mtrPolicyConfig) {
|
||||||
StringJoiner resultJoiner = new StringJoiner(";");
|
StringJoiner resultJoiner = new StringJoiner(";");
|
||||||
String serverGroupStr = mtrPolicyConfig.getServerGroup().replace("\n",",");
|
String serverGroupStr = mtrPolicyConfig.getServerGroup().replace("\n", ",");
|
||||||
RmNetworkInterfaceRemote query = new RmNetworkInterfaceRemote();
|
String[] serverIds = serverGroupStr.split(",");
|
||||||
query.setClientIds(serverGroupStr);
|
|
||||||
R<List<RmNetworkInterfaceRemote>> networkList = remoteRocketMqService.getNetworkInterfaceList(query, SecurityConstants.INNER);
|
// 分批次处理,每批200个
|
||||||
if(networkList != null && networkList.getData() != null){
|
int batchSize = 200;
|
||||||
List<RmNetworkInterfaceRemote> rmNetworkInterfaceRemoteList = networkList.getData();
|
for (int i = 0; i < serverIds.length; i += batchSize) {
|
||||||
if(!rmNetworkInterfaceRemoteList.isEmpty()){
|
int end = Math.min(i + batchSize, serverIds.length);
|
||||||
for (RmNetworkInterfaceRemote rmNetworkInterfaceRemote : rmNetworkInterfaceRemoteList) {
|
|
||||||
String publicIp = rmNetworkInterfaceRemote.getPublicIp();
|
// 构建当前批次的id字符串
|
||||||
resultJoiner.add(publicIp);
|
StringBuilder batchIds = new StringBuilder();
|
||||||
|
for (int j = i; j < end; j++) {
|
||||||
|
if (batchIds.length() > 0) {
|
||||||
|
batchIds.append(",");
|
||||||
}
|
}
|
||||||
mtrPolicyConfig.setServeripGroup(resultJoiner.toString());
|
batchIds.append(serverIds[j].trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询当前批次
|
||||||
|
RmNetworkInterfaceRemote query = new RmNetworkInterfaceRemote();
|
||||||
|
query.setClientIds(batchIds.toString());
|
||||||
|
R<List<RmNetworkInterfaceRemote>> networkList = remoteRocketMqService.getNetworkInterfaceList(query, SecurityConstants.INNER);
|
||||||
|
|
||||||
|
// 处理结果
|
||||||
|
if (networkList != null && networkList.getData() != null) {
|
||||||
|
for (RmNetworkInterfaceRemote rmNetworkInterfaceRemote : networkList.getData()) {
|
||||||
|
String publicIp = rmNetworkInterfaceRemote.getPublicIp();
|
||||||
|
if (publicIp != null && !publicIp.trim().isEmpty()) {
|
||||||
|
resultJoiner.add(publicIp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置最终结果
|
||||||
|
String result = resultJoiner.toString();
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
mtrPolicyConfig.setServeripGroup(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
@@ -289,6 +289,7 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
|||||||
log.error("计算{}的95带宽值失败,详情:{}", interfaceName.getClientId(), e.getMessage());
|
log.error("计算{}的95带宽值失败,详情:{}", interfaceName.getClientId(), e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
log.info("服务器95带宽值计算完成,总计{}台设备",snList.size());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 计算金山95带宽值/日
|
* 计算金山95带宽值/日
|
||||||
@@ -755,6 +756,7 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
|||||||
calculateSegment95(queryParam, dailyStartTime, dailyEndTime, calculationMode);
|
calculateSegment95(queryParam, dailyStartTime, dailyEndTime, calculationMode);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
queryParam.setBusinessId(null);
|
||||||
calculateNormalDeviceBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode);
|
calculateNormalDeviceBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+53
-44
@@ -166,6 +166,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
|||||||
@Override
|
@Override
|
||||||
public List<RmResourceRegistration> selectRmResourceRegistrationList(RmResourceRegistration rmResourceRegistration) {
|
public List<RmResourceRegistration> selectRmResourceRegistrationList(RmResourceRegistration rmResourceRegistration) {
|
||||||
List<RmResourceRegistration> allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
List<RmResourceRegistration> allData = rmResourceRegistrationMapper.getRegistrationTableInfoList(rmResourceRegistration);
|
||||||
|
batchSetNetWorkMsg(allData);
|
||||||
|
|
||||||
// 获取参数
|
// 获取参数
|
||||||
String queryParam = rmResourceRegistration.getQueryParam();
|
String queryParam = rmResourceRegistration.getQueryParam();
|
||||||
@@ -189,7 +190,6 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
|||||||
// 处理全部数据
|
// 处理全部数据
|
||||||
for (RmResourceRegistration item : filteredList) {
|
for (RmResourceRegistration item : filteredList) {
|
||||||
if (item.getClientId() != null) {
|
if (item.getClientId() != null) {
|
||||||
setNetWorkMsg(item);
|
|
||||||
setBandwidthYestoday(item);
|
setBandwidthYestoday(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -287,61 +287,70 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
|||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// 收集所有需要查询的clientId,用逗号分隔
|
// 设置每批大小
|
||||||
String clientIdsStr = pageList.stream()
|
int batchSize = 200;
|
||||||
.map(RmResourceRegistration::getClientId)
|
int totalBatches = (int) Math.ceil((double) pageList.size() / batchSize);
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.distinct()
|
|
||||||
.collect(Collectors.joining(","));
|
|
||||||
|
|
||||||
if (StringUtils.isBlank(clientIdsStr)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("批量查询网络信息,clientIds: {}", clientIdsStr);
|
for (int batchNum = 0; batchNum < totalBatches; batchNum++) {
|
||||||
|
int fromIndex = batchNum * batchSize;
|
||||||
|
int toIndex = Math.min(fromIndex + batchSize, pageList.size());
|
||||||
|
List<RmResourceRegistration> batchList = pageList.subList(fromIndex, toIndex);
|
||||||
|
|
||||||
try {
|
|
||||||
// 使用批量查询接口
|
|
||||||
RmNetworkInterfaceRemote queryParam = new RmNetworkInterfaceRemote();
|
|
||||||
queryParam.setClientIds(clientIdsStr); // 这里是逗号分隔的字符串
|
|
||||||
queryParam.setNewFlag(1);
|
|
||||||
|
|
||||||
R<List<RmNetworkInterfaceRemote>> result = remoteRocketMqService.getNetworkInterfaceList(queryParam, SecurityConstants.INNER);
|
// 收集当前批次需要查询的clientId
|
||||||
|
String clientIdsStr = batchList.stream()
|
||||||
if (result == null || result.getData() == null || result.getData().isEmpty()) {
|
.map(RmResourceRegistration::getClientId)
|
||||||
log.warn("批量查询网络信息返回为空,clientIds: {}", clientIdsStr);
|
.filter(Objects::nonNull)
|
||||||
// 回退到单条查询
|
.distinct()
|
||||||
// fallbackSetNetworkInfo(pageList);
|
.collect(Collectors.joining(","));
|
||||||
return;
|
if (StringUtils.isBlank(clientIdsStr)) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<RmNetworkInterfaceRemote> networkList = result.getData();
|
|
||||||
|
|
||||||
// 按clientId分组
|
try {
|
||||||
Map<String, List<RmNetworkInterfaceRemote>> networkMap = networkList.stream()
|
// 使用批量查询接口
|
||||||
.filter(Objects::nonNull)
|
RmNetworkInterfaceRemote queryParam = new RmNetworkInterfaceRemote();
|
||||||
.filter(item -> item.getClientId() != null)
|
queryParam.setClientIds(clientIdsStr);
|
||||||
.collect(Collectors.groupingBy(RmNetworkInterfaceRemote::getClientId));
|
queryParam.setNewFlag(1);
|
||||||
|
|
||||||
// 批量设置
|
R<List<RmNetworkInterfaceRemote>> result = remoteRocketMqService.getNetworkInterfaceList(queryParam, SecurityConstants.INNER);
|
||||||
for (RmResourceRegistration registration : pageList) {
|
|
||||||
String clientId = registration.getClientId();
|
if (result == null || result.getData() == null || result.getData().isEmpty()) {
|
||||||
if (clientId != null) {
|
continue;
|
||||||
List<RmNetworkInterfaceRemote> clientNetworks = networkMap.get(clientId);
|
}
|
||||||
if (clientNetworks != null && !clientNetworks.isEmpty()) {
|
|
||||||
// 调用原有的setNetWorkMsg方法
|
List<RmNetworkInterfaceRemote> networkList = result.getData();
|
||||||
setNetWorkMsgWithNetworkList(registration, clientNetworks);
|
|
||||||
|
// 按clientId分组
|
||||||
|
Map<String, List<RmNetworkInterfaceRemote>> networkMap = networkList.stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(item -> item.getClientId() != null)
|
||||||
|
.collect(Collectors.groupingBy(RmNetworkInterfaceRemote::getClientId));
|
||||||
|
|
||||||
|
// 批量设置当前批次
|
||||||
|
for (RmResourceRegistration registration : batchList) {
|
||||||
|
String clientId = registration.getClientId();
|
||||||
|
if (clientId != null) {
|
||||||
|
List<RmNetworkInterfaceRemote> clientNetworks = networkMap.get(clientId);
|
||||||
|
if (clientNetworks != null && !clientNetworks.isEmpty()) {
|
||||||
|
setNetWorkMsgWithNetworkList(registration, clientNetworks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("第{}批查询网络信息异常", batchNum + 1, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("批量处理网络信息完成,耗时: {}ms, 处理{}条记录, 返回{}条网络信息",
|
// 添加小延迟,避免对下游服务造成压力
|
||||||
System.currentTimeMillis() - startTime, pageList.size(), networkList.size());
|
if (batchNum < totalBatches - 1) {
|
||||||
|
try {
|
||||||
} catch (Exception e) {
|
Thread.sleep(10);
|
||||||
log.error("批量查询网络信息异常", e);
|
} catch (InterruptedException e) {
|
||||||
// 回退到单条查询
|
Thread.currentThread().interrupt();
|
||||||
// fallbackSetNetworkInfo(pageList);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
<fileNamePattern>${log.path}/debug.%d{yyyy-MM-dd}.log</fileNamePattern>
|
<fileNamePattern>${log.path}/debug.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
<maxHistory>7</maxHistory> <!-- debug日志只保留7天 -->
|
<maxHistory>30</maxHistory> <!-- debug日志只保留30天 -->
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>${log.pattern}</pattern>
|
<pattern>${log.pattern}</pattern>
|
||||||
|
|||||||
+1
-1
@@ -166,7 +166,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
|
|
||||||
<!-- 批量插入接口名称 -->
|
<!-- 批量插入接口名称 -->
|
||||||
<insert id="batchInsert" parameterType="java.util.List">
|
<insert id="batchInsert" parameterType="java.util.List">
|
||||||
INSERT IGNORE INTO all_interface_name
|
INSERT INTO all_interface_name
|
||||||
(
|
(
|
||||||
interface_name,
|
interface_name,
|
||||||
client_id,
|
client_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user