mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Optimize watchcache by not starting a gorotuine for all Get/List requests setting RV=0
This commit is contained in:
parent
6c45f6e32b
commit
37f93fc63d
@ -210,7 +210,7 @@ TestCase:
|
|||||||
break TestCase
|
break TestCase
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
w.Stop()
|
w.stopThreadUnsafe()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,7 +551,7 @@ func TestCacheWatcherStoppedInAnotherGoroutine(t *testing.T) {
|
|||||||
case <-time.After(time.Second):
|
case <-time.After(time.Second):
|
||||||
t.Fatal("expected received a event on ResultChan")
|
t.Fatal("expected received a event on ResultChan")
|
||||||
}
|
}
|
||||||
w.Stop()
|
w.stopThreadUnsafe()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,17 +420,27 @@ func (w *watchCache) List() []interface{} {
|
|||||||
// You HAVE TO explicitly call w.RUnlock() after this function.
|
// You HAVE TO explicitly call w.RUnlock() after this function.
|
||||||
func (w *watchCache) waitUntilFreshAndBlock(resourceVersion uint64, trace *utiltrace.Trace) error {
|
func (w *watchCache) waitUntilFreshAndBlock(resourceVersion uint64, trace *utiltrace.Trace) error {
|
||||||
startTime := w.clock.Now()
|
startTime := w.clock.Now()
|
||||||
go func() {
|
|
||||||
// Wake us up when the time limit has expired. The docs
|
// In case resourceVersion is 0, we accept arbitrarily stale result.
|
||||||
// promise that time.After (well, NewTimer, which it calls)
|
// As a result, the condition in the below for loop will never be
|
||||||
// will wait *at least* the duration given. Since this go
|
// satisfied (w.resourceVersion is never negative), this call will
|
||||||
// routine starts sometime after we record the start time, and
|
// never hit the w.cond.Wait().
|
||||||
// it will wake up the loop below sometime after the broadcast,
|
// As a result - we can optimize the code by not firing the wakeup
|
||||||
// we don't need to worry about waking it up before the time
|
// function (and avoid starting a gorotuine), especially given that
|
||||||
// has expired accidentally.
|
// resourceVersion=0 is the most common case.
|
||||||
<-w.clock.After(blockTimeout)
|
if resourceVersion > 0 {
|
||||||
w.cond.Broadcast()
|
go func() {
|
||||||
}()
|
// Wake us up when the time limit has expired. The docs
|
||||||
|
// promise that time.After (well, NewTimer, which it calls)
|
||||||
|
// will wait *at least* the duration given. Since this go
|
||||||
|
// routine starts sometime after we record the start time, and
|
||||||
|
// it will wake up the loop below sometime after the broadcast,
|
||||||
|
// we don't need to worry about waking it up before the time
|
||||||
|
// has expired accidentally.
|
||||||
|
<-w.clock.After(blockTimeout)
|
||||||
|
w.cond.Broadcast()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
w.RLock()
|
w.RLock()
|
||||||
if trace != nil {
|
if trace != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user