Skip to content

Commit

Permalink
fix: time.Ticker没有关闭,导致cpu使用率过高 TencentBlueKing#478
Browse files Browse the repository at this point in the history
  • Loading branch information
zmberg committed May 29, 2020
1 parent b82c781 commit 2ac888a
Show file tree
Hide file tree
Showing 68 changed files with 106 additions and 22 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 @@ -62,8 +62,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
2 changes: 2 additions & 0 deletions bcs-mesos/bcs-check/bcscheck/bcscheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (s *HealthCheckServer) regDiscover() {
blog.Info("DiscoverService(%s) succ", discvPath)

tick := time.NewTicker(180 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down Expand Up @@ -330,6 +331,7 @@ func (s *HealthCheckServer) regBcsDiscover() {
blog.Info("DiscoverService(%s) succ", discvPath)

tick := time.NewTicker(180 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (m *manager) StartExec(w http.ResponseWriter, r *http.Request, conf *types.
//})

ticker := time.NewTicker(pingPeriod)
defer ticker.Stop()
go func() {
for {
select {
Expand Down
2 changes: 2 additions & 0 deletions bcs-mesos/bcs-container-executor/app/bcs_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ func (executor *BcsExecutor) LaunchTaskGroup(driver exec.ExecutorDriver, taskGro
stopCh := make(chan struct{})
go func() {
ticker := time.NewTicker(time.Minute)
defer ticker.Stop()

for {
select {
Expand Down Expand Up @@ -572,6 +573,7 @@ func (executor *BcsExecutor) monitorPod() {
}()

tick := time.NewTicker(1 * time.Second)
defer tick.Stop()
reporting := 0
for {
select {
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-container-executor/connection/fakeconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (httpConn *FakeConnection) slaveSimulation() {
//send Shutdown in 10 second
//send KillTask in 10 second ?
tick := time.NewTicker(1 * time.Second)
defer tick.Stop()
fmt.Fprintln(os.Stdout, "enter slave message sending loop")
i := 0
for {
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-container-executor/container/cni/cni_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ func (p *CNIPod) containersWatch(cxt context.Context) {
}

tick := time.NewTicker(defaultPodWatchInterval * time.Second)
defer tick.Stop()
for {
select {
case <-cxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-container-executor/container/cnm/cnm_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ func (p *DockerPod) containersWatch(cxt context.Context) {
}

tick := time.NewTicker(defaultPodWatchInterval * time.Second)
defer tick.Stop()
//total := defaultErrTolerate * len(p.runningContainer)
for {
select {
Expand Down
2 changes: 2 additions & 0 deletions bcs-mesos/bcs-container-executor/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ func (driver *BcsExecutorDriver) Stop() (mesos.Status, error) {
logs.Infoln("ExecutorDriver is under connection, wait slave reply acknowledged")
//check all update info acknowledged
checkTick := time.NewTicker(500 * time.Microsecond)
defer checkTick.Stop()
timeoutTick := time.NewTicker(5 * time.Second)
defer timeoutTick.Stop()
for driver.updates != nil && driver.connected {
//if connection lost, no need to wait acknowledgement
select {
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-container-executor/healthcheck/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (check *CommandChecker) Start() {
check.check()

tick := time.NewTicker(time.Duration(int64(check.mechanism.IntervalSeconds)) * time.Second)
defer tick.Stop()
for {
select {
case <-check.cxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-container-executor/healthcheck/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (check *HTTPChecker) Start() {
check.check()

tick := time.NewTicker(time.Duration(int64(check.mechanism.IntervalSeconds)) * time.Second)
defer tick.Stop()
for {
select {
case <-check.cxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-container-executor/healthcheck/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (check *TCPChecker) Start() {
check.check()

tick := time.NewTicker(time.Duration(int64(check.mechanism.IntervalSeconds)) * time.Second)
defer tick.Stop()
for {
select {
case <-check.cxt.Done():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (auto *Autoscaler) Start() error {
//ticker list zk autoscalers and sync these autoscalers to workqueue
func (auto *Autoscaler) tickerSyncAutoscalerQueue() {
ticker := time.NewTicker(time.Second * time.Duration(auto.config.MetricsSyncPeriod))
defer ticker.Stop()

for {

Expand Down Expand Up @@ -162,6 +163,7 @@ func (auto *Autoscaler) tickerSyncAutoscalerQueue() {

func (auto *Autoscaler) tickerHandlerAutoscaler() {
ticker := time.NewTicker(time.Second * time.Duration(auto.config.MetricsSyncPeriod))
defer ticker.Stop()

for {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (collector *resourcesCollector) getMemoryMetricsInfo() metrics.TaskgroupMet

func (collector *resourcesCollector) tickerCollectorMetrics() {
ticker := time.NewTicker(time.Second * time.Duration(collector.collectMetricsWindow))
defer ticker.Stop()

for {
select {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (r *bcsMesosScaler) discvMesosdriver() {

blog.Infof("watch mesosdriver under (%s: %s)", MesosDiscv, discvPath)
tick := time.NewTicker(180 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down
2 changes: 2 additions & 0 deletions bcs-mesos/bcs-mesos-driver/mesosdriver/mesosdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func (m *MesosDriver) RegDiscover() {
blog.Info("DiscoverService(%s) succ", discvPath)

tick := time.NewTicker(180 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down Expand Up @@ -336,6 +337,7 @@ func (m *MesosDriver) DiscvScheduler() {
blog.Infof("watch scheduler under (%s: %s), current goroutine num(%d)", MesosDiscv, discvPath, runtime.NumGoroutine())

tick := time.NewTicker(180 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down
2 changes: 2 additions & 0 deletions bcs-mesos/bcs-mesos-watch/app/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func runServer(rdCxt context.Context, cfg *types.CmdConfig, storage storage.Stor

appRole := "slave"
tick := time.NewTicker(60 * time.Second)
defer tick.Stop()

for {
select {
Expand Down Expand Up @@ -439,6 +440,7 @@ func RefreshDCHost(rfCxt context.Context, cfg *types.CmdConfig, storage storage.
blog.Info("DiscoverService(%s) succ", discvPath)

tick := time.NewTicker(120 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/etcd/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (watch *ConfigMapWatch) Work() {

watch.ProcessAllConfigmaps()
tick := time.NewTicker(12 * time.Second)
defer tick.Stop()
for {
select {
case <-watch.cancelCxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/etcd/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (watch *DeploymentWatch) Work() {

watch.ProcessAllDeployments()
tick := time.NewTicker(10 * time.Second)
defer tick.Stop()
for {
select {
case <-watch.cancelCxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/etcd/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type EndpointWatch struct {
func (watch *EndpointWatch) Work() {
watch.ProcessAllEndpoints()
tick := time.NewTicker(10 * time.Second)
defer tick.Stop()
for {
select {
case <-watch.cancelCxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/etcd/exportservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (watch *ExportServiceWatch) worker(cxt context.Context) {
blog.Infof("ExportServiceWatch start work")

tick := time.NewTicker(120 * time.Second)
defer tick.Stop()
for {
select {
case <-cxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/etcd/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (watch *SecretWatch) Work() {

watch.ProcessAllSecrets()
tick := time.NewTicker(10 * time.Second)
defer tick.Stop()
for {
select {
case <-watch.cancelCxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/etcd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (watch *ServiceWatch) Work() {

watch.ProcessAllServices()
tick := time.NewTicker(8 * time.Second)
defer tick.Stop()
for {
select {
case <-watch.cancelCxt.Done():
Expand Down
2 changes: 2 additions & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/mesos/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (app *AppWatch) pathWatch(cxt context.Context, path string) {
app.handleAppList(cxt, path, children)

tick := time.NewTicker(240 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down Expand Up @@ -222,6 +223,7 @@ func (app *AppWatch) appNodeWatch(cxt context.Context, apppath string, ns string
blog.V(3).Infof("appwatch wath app ID(%s)", ID)

tick := time.NewTicker(240 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/mesos/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type ConfigMapWatch struct {
func (watch *ConfigMapWatch) Work() {
watch.ProcessAllConfigmaps()
tick := time.NewTicker(12 * time.Second)
defer tick.Stop()
for {
select {
case <-watch.cancelCxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/mesos/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type DeploymentWatch struct {
func (watch *DeploymentWatch) Work() {
watch.ProcessAllDeployments()
tick := time.NewTicker(10 * time.Second)
defer tick.Stop()
for {
select {
case <-watch.cancelCxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/mesos/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type EndpointWatch struct {
func (watch *EndpointWatch) Work() {
watch.ProcessAllEndpoints()
tick := time.NewTicker(10 * time.Second)
defer tick.Stop()
for {
select {
case <-watch.cancelCxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/mesos/exportservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (watch *ExportServiceWatch) postData(data *types.BcsSyncData) {

func (watch *ExportServiceWatch) worker(cxt context.Context) {
tick := time.NewTicker(120 * time.Second)
defer tick.Stop()
for {
select {
case <-cxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/mesos/mesos.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ func (ms *MesosCluster) Run(cxt context.Context) {

//ready to start zk connection monitor
tick := time.NewTicker(5 * time.Second)
defer tick.Stop()
for {
select {
case <-cxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/mesos/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type SecretWatch struct {
func (watch *SecretWatch) Work() {
watch.ProcessAllSecrets()
tick := time.NewTicker(10 * time.Second)
defer tick.Stop()
for {
select {
case <-watch.cancelCxt.Done():
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/mesos/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type ServiceWatch struct {
func (watch *ServiceWatch) Work() {
watch.ProcessAllServices()
tick := time.NewTicker(8 * time.Second)
defer tick.Stop()
for {
select {
case <-watch.cancelCxt.Done():
Expand Down
2 changes: 2 additions & 0 deletions bcs-mesos/bcs-mesos-watch/cluster/mesos/taskgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (task *TaskGroupWatch) pathWatch(cxt context.Context, path string) {

//watch children node event
tick := time.NewTicker(240 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down Expand Up @@ -208,6 +209,7 @@ func (task *TaskGroupWatch) taskGroupNodeWatch(cxt context.Context, taskpath str

ID := path.Base(taskpath)
tick := time.NewTicker(240 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down
1 change: 1 addition & 0 deletions bcs-mesos/bcs-mesos-watch/storage/cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func (cc *CCStorage) Run(cxt context.Context) error {
func (cc *CCStorage) Worker() {
blog.Info("CCStorage ready to go into worker!")
tick := time.NewTicker(120 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down
2 changes: 1 addition & 1 deletion bcs-mesos/bcs-mesos-watch/storage/channelproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ChannelProxy struct {
func (proxy *ChannelProxy) Run(cxt context.Context) {

tick := time.NewTicker(300 * time.Second)

defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ func (p *offerPool) setInnerOffersAttributes(offers []*mesos.Offer) {

func (p *offerPool) checkOffers() {
tick := time.NewTicker(1 * time.Second)
defer tick.Stop()

for {
select {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (e *bcsEventManager) discvstorage() {
blog.Infof("watch storage under (%s: %s), current goroutine num(%d)", e.bcsZk, discvPath, runtime.NumGoroutine())

tick := time.NewTicker(180 * time.Second)
defer tick.Stop()
for {
select {
case <-tick.C:
Expand Down Expand Up @@ -185,6 +186,7 @@ func (e *bcsEventManager) discvstorage() {
func (e *bcsEventManager) handleEventQueue() {

tick := time.NewTicker(time.Second * 10)
defer tick.Stop()

var err error

Expand Down
Loading

0 comments on commit 2ac888a

Please sign in to comment.