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