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

fix: time.Ticker没有关闭,导致cpu使用率过高 #478 #628

Merged
merged 3 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -359,6 +359,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 @@ -580,6 +581,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 @@ -83,6 +83,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 @@ -86,6 +86,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 @@ -76,6 +76,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 @@ -91,6 +91,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 @@ -467,6 +467,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 @@ -299,6 +299,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 @@ -609,6 +609,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 @@ -137,6 +137,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 @@ -187,6 +188,7 @@ func (e *bcsEventManager) discvstorage() {
func (e *bcsEventManager) handleEventQueue() {

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

var err error

Expand Down
Loading