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()
|
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
|
||||||
}
|
}
|
||||||
|
if len(ch) == 0 {
|
||||||
flusher.Flush()
|
flusher.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue