Skip to content

Commit

Permalink
Fix high CPU usage of instance-manager pod caused by for loop
Browse files Browse the repository at this point in the history
Longhorn 8496

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit authored and innobead committed May 7, 2024
1 parent cb2f1f3 commit 7e13b69
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 30 deletions.
13 changes: 3 additions & 10 deletions pkg/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,10 @@ func NewServer(ctx context.Context, spdkEnabled bool, spdkServiceAddress string)
}

func (s *Server) startMonitoring() {
done := false
for {
select {
case <-s.ctx.Done():
logrus.Infof("%s: stopped monitoring replicas due to the context done", types.DiskGrpcService)
done = true
default:
}
if done {
break
}
<-s.ctx.Done()
logrus.Infof("%s: stopped monitoring due to the context done", types.DiskGrpcService)
break
}
}

Expand Down
13 changes: 3 additions & 10 deletions pkg/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,10 @@ func NewServer(ctx context.Context, logsDir, processManagerServiceAddress, spdkS
}

func (s *Server) startMonitoring() {
done := false
for {
select {
case <-s.ctx.Done():
logrus.Infof("%s: stopped monitoring replicas due to the context done", types.InstanceGrpcService)
done = true
default:
}
if done {
break
}
<-s.ctx.Done()
logrus.Infof("%s: stopped monitoring due to the context done", types.InstanceGrpcService)
break
}
}

Expand Down
13 changes: 3 additions & 10 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,10 @@ func NewProxy(ctx context.Context, logsDir, diskServiceAddress, spdkServiceAddre
}

func (p *Proxy) startMonitoring() {
done := false
for {
select {
case <-p.ctx.Done():
logrus.Infof("%s: stopped monitoring replicas due to the context done", types.ProxyGRPCService)
done = true
default:
}
if done {
break
}
<-p.ctx.Done()
logrus.Infof("%s: stopped monitoring due to the context done", types.ProxyGRPCService)
break
}
}

Expand Down

0 comments on commit 7e13b69

Please sign in to comment.