Delay flush if the watch queue has pending items

Simple deferral of flush can reduce Syscalls when watch queues build up.
pull/6/head
Clayton Coleman 2016-05-23 12:35:36 -04:00
parent efc5bbc9e8
commit c4bec1585f
1 changed files with 5 additions and 2 deletions

View File

@ -168,13 +168,14 @@ func (s *WatchServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
flusher.Flush()
buf := &bytes.Buffer{}
ch := s.watching.ResultChan()
for {
select {
case <-cn.CloseNotify():
return
case <-timeoutCh:
return
case event, ok := <-s.watching.ResultChan():
case event, ok := <-ch:
if !ok {
// End of results.
return
@ -196,7 +197,9 @@ func (s *WatchServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// client disconnect.
return
}
if len(ch) == 0 {
flusher.Flush()
}
buf.Reset()
}