Skip to content

Commit

Permalink
fix: time.Ticker没有关闭,导致cpu使用率过高 #478
Browse files Browse the repository at this point in the history
  • Loading branch information
zmberg committed Oct 19, 2020
1 parent 1e77a92 commit 4ba4aba
Show file tree
Hide file tree
Showing 65 changed files with 828 additions and 2 deletions.
4 changes: 3 additions & 1 deletion bcs-common/common/blog/glog/glog.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,9 @@ const flushInterval = 30 * time.Second

// flushDaemon periodically flushes the log file buffers.
func (l *loggingT) flushDaemon() {
for _ = range time.NewTicker(flushInterval).C {
ticker := time.NewTicker(flushInterval)
defer ticker.Stop()
for _ = range ticker.C {
l.lockAndFlushAll()
}
}
Expand Down
3 changes: 3 additions & 0 deletions bcs-common/pkg/master/zookeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ func (zk *ZookeeperMaster) masterLoop() {
func (zk *ZookeeperMaster) healthLoop() {
masterTick := time.NewTicker(time.Second * 2)
selfTick := time.NewTicker(time.Second * 30)
defer masterTick.Stop()
defer selfTick.Stop()

for {
select {
case <-zk.exitCxt.Done():
Expand Down
2 changes: 2 additions & 0 deletions bcs-common/pkg/reflector/reflector.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ func (r *Reflector) Run() {
blog.V(3).Infof("%s first resynchronization & watch success, register all ticker", r.name)
//create ticker for data object resync
syncTick := time.NewTicker(r.syncPeriod)
defer syncTick.Stop()
//create ticker check stable watcher
watchTick := time.NewTicker(time.Second * 2)
defer watchTick.Stop()
for {
select {
case <-r.cxt.Done():
Expand Down
2 changes: 2 additions & 0 deletions bcs-common/pkg/storage/zookeeper/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (n *Node) Run() {
go n.childrenLoop()
}
tick := time.NewTicker(time.Second * 3)
defer tick.Stop()
for {
if n.isStopped {
return
Expand Down Expand Up @@ -208,6 +209,7 @@ func (n *Node) selfLoop() {
}
//wait for next event
forceTick := time.NewTicker(time.Second * 300)
defer forceTick.Stop()
for {
select {
case <-n.watchCxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-k8s/bcs-k8s-csi-tencentcloud/driver/cbs/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func (ctrl *cbsController) CreateVolume(ctx context.Context, req *csi.CreateVolu
disk := new(cbs.Disk)

ticker := time.NewTicker(time.Second * 5)
defer ticker.Stop()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*120)
defer cancel()
Expand Down

0 comments on commit 4ba4aba

Please sign in to comment.