Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: 主机与主机关系事件处理优化 #1145 #1146

Merged
merged 6 commits into from
Jul 27, 2022

Conversation

jsonwan
Copy link
Collaborator

@jsonwan jsonwan commented Jul 26, 2022

  1. 主机缓存更新策略优化;
  2. 主机、主机关系事件监听代码重构。

主机缓存更新策略优化;
主机事件监听代码重构。
代码重构:去除多个eventsHandler逻辑。
增加主机关系事件处理流水日志。
@jsonwan jsonwan requested a review from wangyu096 July 26, 2022 12:29
log.info("start to handle host event:{}", JsonUtils.toJson(event));
handleOneEventIndeed(event);
} catch (Throwable t) {
log.error(String.format("Fail to handle hostEvent:%s", event), t);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. String.format有性能问题,不推荐在日志中使用
  2. 日志格式化尽量保证全局统一,少用%s这种方式

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

重构代码时老代码中直接拿过来的,已修改

} catch (Throwable t) {
log.error(String.format("Fail to handle hostEvent:%s", event), t);
} finally {
log.info("end to handle host event");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句日志是否有必要?如果真的有必要,那么需要输出对应的事件,不然根本无法区分对应的是哪个

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已去除

hostInfoDTO.setIp(ip);
if (!ip.contains(":")) {
String cloudIp = cloudAreaId + ":" + ip;
hostInfoDTO.setGseAgentAlive(queryAgentStatusClient.getAgentStatus(cloudIp).status == 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

魔鬼数字,我记得应该有常量调试agent状态

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

String cloudIp = cloudAreaId + ":" + ip;
hostInfoDTO.setGseAgentAlive(queryAgentStatusClient.getAgentStatus(cloudIp).status == 1);
} else {
hostInfoDTO.setGseAgentAlive(queryAgentStatusClient.getAgentStatus(ip).status == 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

魔鬼数字

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

log.debug("handle hostRelationEvent:" + watch.prettyPrint());
}
} catch (Throwable t) {
log.error(String.format("Fail to handle hostRelationEvent of appId %d, event:%s", appId, event), t);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议使用String.format

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

} catch (Throwable t) {
log.error(String.format("Fail to handle hostRelationEvent of appId %d, event:%s", appId, event), t);
} finally {
log.info("end to handle host relation event");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有具体的事件信息

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已去除

updateHostCacheWhenRelCreated(hostTopoDTO);
break;
case ResourceWatchReq.EVENT_TYPE_UPDATE:
log.warn("Unexpected event:hostRelation Update");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果不需要处理的话,能否直接忽略?而不是打印一个warn日志,反而容易引起误解(比如外部合作方会经常认为warn日志跟他们的问题有关)。我看default直接break就可以了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已去除

"cannot find hostInfo by hostId:{}, wait for host event or sync",
hostTopoDTO.getHostId()
);
log.warn(msg.getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接 log.warn("cannot find hostInfo by hostId:{}, wait for host event or sync", hostTopoDTO.getHostId()) 就可以了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

);
hostRelationWatchRedisKeyHeartBeatThread.setName("hostRelationWatchRedisKeyHeartBeatThread");
hostRelationWatchRedisKeyHeartBeatThread.start();
RedisKeyHeartBeatThread relationWatchBeatThread = startRedisKeyHeartBeatThread();
log.info("start watch hostRelation at {},{}", TimeUtil.getCurrentTimeStr("HH:mm:ss"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeUtil.getCurrentTimeStr,已经包含了当前时间的意思了,为啥还要传入一个System.currentTimeInMills()??

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另外,DateUtil已经包含了该方法了

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看下时间的操作类能否整合下,比如改成DateTimeUtil

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TimeUtil.getCurrentTimeStr,已经包含了当前时间的意思了,为啥还要传入一个System.currentTimeInMills()??

已简化

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看下时间的操作类能否整合下,比如改成DateTimeUtil

两者使用场景不同,虽然有一些功能交集,但是整合在一起会更加臃肿,不建议整合

@wangyu096 wangyu096 merged commit 0dddcb4 into TencentBlueKing:master Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants