You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/10/18 05:52:26 UTC

[GitHub] [servicecomb-service-center] x-xy-y opened a new issue #1161: KvCacher 的 handleDeferEvents 可能导致 watch 的推送延迟

x-xy-y opened a new issue #1161:
URL: https://github.com/apache/servicecomb-service-center/issues/1161


   我在调查 watch 的推送延迟问题, 阅读代码 (版本 abed95307df6cb1ef61b5d123ff8d308c337e7ee) 看到
   
   datasource/etcd/state/etcd/cacher_kv.go:  KvCacher.handleDeferEvents 函数
   ```
   func (c *KvCacher) handleDeferEvents(ctx context.Context) {
   	defer log.Recover()
   	var (
   		evts = make([]kvstore.Event, sdcommon.EventBlockSize)
   		i    int
   	)
   	interval := 300 * time.Millisecond
   	timer := time.NewTimer(interval)
   	defer timer.Stop()
   	for {
   		select {
   		case <-ctx.Done():
   			return
   		case evt, ok := <-c.Cfg.DeferHandler.HandleChan():
   			if !ok {
   				log.Error("replay channel is closed", nil)
   				return
   			}
   
   			if i >= sdcommon.EventBlockSize {
   				c.onEvents(evts[:i])
   				evts = make([]kvstore.Event, sdcommon.EventBlockSize)
   				i = 0
   			}
   
   			evts[i] = evt
   			i++
   
   			timeutil.ResetTimer(timer, interval)
   		case <-timer.C:
   			timer.Reset(interval)
   
   			if i == 0 {
   				continue
   			}
   
   			c.onEvents(evts[:i])
   			evts = make([]kvstore.Event, sdcommon.EventBlockSize)
   			i = 0
   		}
   	}
   }
   ```
   不是很理解这里的机制
   
   1. 首先是为什么需要做缓冲,再批量调 onEvents ?问题在于,onEvents 好像没有聚合 evts 的逻辑,就是说,如果 onEvents 里也是对所有事件逐行处理的话,与在 KvCacher 不做缓冲直接调,效果是一样的,而且现在这样产生了额外的延迟。
   1.1 这个缓冲的大小  EventBlockSize = 800 及 300ms 的延迟是如何选择的?我的疑惑是,什么业务场景或测试用例下,会用满 800 的缓冲,从而无须走到 300ms 延迟后的分支里?
   2. 为什么这里要调 timeutil.ResetTimer  重置计时器,如果每 50 ms 产生一个事件,连续 100 个事件,由于这个计时器一直重置,第一个事件至少要 5 秒才会传到 onEvents ?感觉正是由于这一行代码,导致了极大的延迟。
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-service-center] little-cui commented on issue #1161: KvCacher 的 handleDeferEvents 可能导致 watch 的推送延迟

Posted by GitBox <gi...@apache.org>.
little-cui commented on issue #1161:
URL: https://github.com/apache/servicecomb-service-center/issues/1161#issuecomment-945725878


   第一个问题:在1.x版本中提供一个实例异常下线保护功能(2.x中已经不启用),保护的场景当计数周期出现大批量实例下线,会进入缓冲逻辑。这里是其中一部分代码,
   
   第二个问题:reset原因是再等待一个周期是否还有剩余需要保护的事件。
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org