You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func (s*Controller) mainLoop(stop<-chanstruct{}) {
vartimeChan<-chan time.TimevarstartDebounce time.TimevarlastResourceUpdateTime time.TimepushCounter:=0debouncedEvents:=0for {
select {
case<-stop:
breakcasee:=<-s.pushChannel:
log.Debugf("Receive event from push chanel : %v", e)
lastResourceUpdateTime=time.Now()
ifdebouncedEvents==0 {
log.Debugf("This is the first debounced event")
startDebounce=lastResourceUpdateTime
}
eventDelay:=time.Since(startDebounce)
debouncedEvents++// it has been too long since the first debounced event or quiet enough since the last debounced eventifeventDelay>=debounceMax {
timeChan=time.After(0)
} else {
timeChan=time.After(debounceAfter)
}
case<-timeChan:
log.Debugf("Receive event from time chanel")
eventDelay:=time.Since(startDebounce)
quietTime:=time.Since(lastResourceUpdateTime)
pushCounter++log.Infof("Push debounce stable[%d] %d: %v since last change, %v since last push",
pushCounter, debouncedEvents, quietTime, eventDelay)
err:=s.pushConsulService2APIServer()
iferr!=nil {
log.Errorf("Failed to synchronize consul services to Istio: %v", err)
// Retry if faileds.pushChannel<-&ChangeEvent{}
}
debouncedEvents=0
}
}
}
The text was updated successfully, but these errors were encountered:
你好,我在看源码的时候对
mainLoop
方法的实现有一些疑惑,还望解答。按照我的理解,
mainLoop
方法的作用是从pushChannel
接收 consul 服务的变化事件,对事件进行去抖动(debounce),然后触发pushConsulService2APIServer
方法。第一个是在这段代码对 pushChannel 的处理中
consul2istio/pkg/controller.go
Lines 109 to 117 in 4e4ed84
如果持续有小于
debounceAfter
间隔的事件触发,会出现最终调用pushConsulService2APIServer
方法的时间超过debounceMax
的情况。这里是否有其他的考虑呢?第二个是在这段代码中的条件判断
consul2istio/pkg/controller.go
Lines 123 to 138 in 4e4ed84
什么情况下会走到 else 中的分支呢?这里如果进入了
case <-timeChan
,那必然是满足eventDelay >= debounceMax || quietTime >= debounceAfter
的条件的。基于以上,修改的代码如下
The text was updated successfully, but these errors were encountered: