From 6b59ea55de4864f7298cd6d78a9418529d1a48f7 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Fri, 6 Sep 2019 16:30:04 -0700 Subject: [PATCH] Check cache is synced first before sleeping If a cache was already synced, cache.WaitForCacheSync would always take 100ms to complete because the PollUntil method will sleep first before checking the condition. Switching to PollImmediateUntil will ensure already synced caches will return immediately. For code that has, for example, 20 informers, the time to check the cache was in sync would take at least 2 seconds, but with this change it can be as fast as you can actually load the data. Signed-off-by: Darren Shepherd Kubernetes-commit: d2e0a25c2696aef4ea5445d9b856bad1ebec832b --- tools/cache/shared_informer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cache/shared_informer.go b/tools/cache/shared_informer.go index c37423b66..f59a0852f 100644 --- a/tools/cache/shared_informer.go +++ b/tools/cache/shared_informer.go @@ -209,7 +209,7 @@ func WaitForNamedCacheSync(controllerName string, stopCh <-chan struct{}, cacheS // if the controller should shutdown // callers should prefer WaitForNamedCacheSync() func WaitForCacheSync(stopCh <-chan struct{}, cacheSyncs ...InformerSynced) bool { - err := wait.PollUntil(syncedPollPeriod, + err := wait.PollImmediateUntil(syncedPollPeriod, func() (bool, error) { for _, syncFunc := range cacheSyncs { if !syncFunc() {