From 6fb09e7027ded6911609a7ae0271048acc34cf34 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Fri, 24 May 2024 10:16:48 +0200 Subject: [PATCH] Use normal Mutex instead of RWMutex There is no benefit of having RWMutex as we have one reader and multiple writers. In such cases RWMutex has worse performance than Mutex. Kubernetes-commit: 544ea424826ef60d703c5f4fb91b2c6a95f303aa --- pkg/storage/cacher/watch_progress.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/storage/cacher/watch_progress.go b/pkg/storage/cacher/watch_progress.go index 0946eecc2..4c7121f14 100644 --- a/pkg/storage/cacher/watch_progress.go +++ b/pkg/storage/cacher/watch_progress.go @@ -42,7 +42,7 @@ func newConditionalProgressRequester(requestWatchProgress WatchProgressRequester requestWatchProgress: requestWatchProgress, contextMetadata: contextMetadata, } - pr.cond = sync.NewCond(pr.mux.RLocker()) + pr.cond = sync.NewCond(&pr.mux) return pr } @@ -59,7 +59,7 @@ type conditionalProgressRequester struct { requestWatchProgress WatchProgressRequester contextMetadata metadata.MD - mux sync.RWMutex + mux sync.Mutex cond *sync.Cond waiting int stopped bool @@ -82,8 +82,8 @@ func (pr *conditionalProgressRequester) Run(stopCh <-chan struct{}) { defer timer.Stop() for { stopped := func() bool { - pr.mux.RLock() - defer pr.mux.RUnlock() + pr.mux.Lock() + defer pr.mux.Unlock() for pr.waiting == 0 && !pr.stopped { pr.cond.Wait() } @@ -97,8 +97,8 @@ func (pr *conditionalProgressRequester) Run(stopCh <-chan struct{}) { case <-timer.C(): timer.Reset(progressRequestPeriod) shouldRequest := func() bool { - pr.mux.RLock() - defer pr.mux.RUnlock() + pr.mux.Lock() + defer pr.mux.Unlock() return pr.waiting > 0 && !pr.stopped }() if !shouldRequest {