mirror of https://github.com/k3s-io/k3s
Delay flush if the watch queue has pending items
Simple deferral of flush can reduce Syscalls when watch queues build up.pull/6/head
parent
efc5bbc9e8
commit
c4bec1585f
|
@ -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
|
||||
}
|
||||
flusher.Flush()
|
||||
if len(ch) == 0 {
|
||||
flusher.Flush()
|
||||
}
|
||||
|
||||
buf.Reset()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue