From 4be8d0f7e2564d954e2bb7547217e5abce495cb0 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 11 Sep 2023 15:34:11 -0500 Subject: [PATCH] conf: reduce readiness file stat() initial interval Sometimes even if the readiness file exists the os.Stat() call will return "file not found". This causes GetReadinessIndicatorFile() to wait 1 second during performance critical operations, even if the os.Stat() would have returned success quickly after the first failure. Add a short backoff up to 1.2s before falling back to the longer intervals. The exponential backoff shouldn't add too much stress to the filesystem, but should allow quicker detection of the readiness file on each container operation. Signed-off-by: Dan Williams --- pkg/types/conf.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/types/conf.go b/pkg/types/conf.go index 8295bd9c6..7fba78ebf 100644 --- a/pkg/types/conf.go +++ b/pkg/types/conf.go @@ -615,6 +615,21 @@ func CheckSystemNamespaces(namespace string, systemNamespaces []string) bool { // GetReadinessIndicatorFile waits for readinessIndicatorFile func GetReadinessIndicatorFile(readinessIndicatorFile string) error { + // Quick first backoff up to ~1 second + backoff := utilwait.Backoff{ + Steps: 5, + Duration: 75 * time.Millisecond, + Factor: 2.0, + Jitter: 0.1, + } + if utilwait.ExponentialBackoff(backoff, func() (bool, error) { + _, err := os.Stat(readinessIndicatorFile) + return err == nil, nil + }) == nil { + return nil + } + + // Otherwise wait a longer time until the file exists pollDuration := 1000 * time.Millisecond pollTimeout := 45 * time.Second return utilwait.PollImmediate(pollDuration, pollTimeout, func() (bool, error) {