Skip to content
New issue

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

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

Already on GitHub? # to your account

频繁创建和销毁北极星SDK实例的时候导致CPU的使用持续飙升及内存泄漏风险 #1370

Open
pemako opened this issue Jul 16, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@pemako
Copy link
Contributor

pemako commented Jul 16, 2024

问题描述:
场景是在大量的定时任务脚本中会初始化北极星实例,定时任务一般是在分钟级别完成。一天大概会有20W的量级,服务发布3天发现 CPU再持续增长。

image image

分析:
通过 pprof 查看发现大部分时间耗费 healthcheck 中,对应的代码为值 https://github.com/polarismesh/polaris/blob/v1.17.5/service/healthcheck/check.go#L147

  1. 避免对 instance 的遍历会降低 CPU 的使用
func (c *CheckScheduler) processAdoptEvents(
	instances map[string]bool, add bool, checker plugin.HealthChecker) map[string]bool {
	instanceIds := make([]string, 0, len(instances))
        //  注释掉下面三行取消遍历会降低 CPU 的使用
	//for id := range instances {
	//	instanceIds = append(instanceIds, id)
	//}
	log.Debug("[Health Check][Check] adopt event", zap.Any("instances", instanceIds),
		zap.String("server", server.localHost), zap.Bool("add", add))
	return instances
}
  1. doAdopt 函数中 instancesToRemove 这个 mapsize 会一直增大,还是存在内存泄漏的问题
func (c *CheckScheduler) doAdopt(ctx context.Context) {
	instancesToAdd := make(map[string]bool)
	instancesToRemove := make(map[string]bool)
	var checker plugin.HealthChecker
	ticker := time.NewTicker(batchAdoptInterval)
        ....
}
  • 使用到的版本是 1.17.5
@pemako pemako added the bug Something isn't working label Jul 16, 2024
@shichaoyuan
Copy link
Member

实例没有deregister?

@chuntaojun
Copy link
Member

改代码最新的 main 分支中已经移除该逻辑

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants