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.
This commit is contained in:
@@ -42,7 +42,7 @@ func newConditionalProgressRequester(requestWatchProgress WatchProgressRequester
|
|||||||
requestWatchProgress: requestWatchProgress,
|
requestWatchProgress: requestWatchProgress,
|
||||||
contextMetadata: contextMetadata,
|
contextMetadata: contextMetadata,
|
||||||
}
|
}
|
||||||
pr.cond = sync.NewCond(pr.mux.RLocker())
|
pr.cond = sync.NewCond(&pr.mux)
|
||||||
return pr
|
return pr
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ type conditionalProgressRequester struct {
|
|||||||
requestWatchProgress WatchProgressRequester
|
requestWatchProgress WatchProgressRequester
|
||||||
contextMetadata metadata.MD
|
contextMetadata metadata.MD
|
||||||
|
|
||||||
mux sync.RWMutex
|
mux sync.Mutex
|
||||||
cond *sync.Cond
|
cond *sync.Cond
|
||||||
waiting int
|
waiting int
|
||||||
stopped bool
|
stopped bool
|
||||||
@@ -82,8 +82,8 @@ func (pr *conditionalProgressRequester) Run(stopCh <-chan struct{}) {
|
|||||||
defer timer.Stop()
|
defer timer.Stop()
|
||||||
for {
|
for {
|
||||||
stopped := func() bool {
|
stopped := func() bool {
|
||||||
pr.mux.RLock()
|
pr.mux.Lock()
|
||||||
defer pr.mux.RUnlock()
|
defer pr.mux.Unlock()
|
||||||
for pr.waiting == 0 && !pr.stopped {
|
for pr.waiting == 0 && !pr.stopped {
|
||||||
pr.cond.Wait()
|
pr.cond.Wait()
|
||||||
}
|
}
|
||||||
@@ -97,8 +97,8 @@ func (pr *conditionalProgressRequester) Run(stopCh <-chan struct{}) {
|
|||||||
case <-timer.C():
|
case <-timer.C():
|
||||||
timer.Reset(progressRequestPeriod)
|
timer.Reset(progressRequestPeriod)
|
||||||
shouldRequest := func() bool {
|
shouldRequest := func() bool {
|
||||||
pr.mux.RLock()
|
pr.mux.Lock()
|
||||||
defer pr.mux.RUnlock()
|
defer pr.mux.Unlock()
|
||||||
return pr.waiting > 0 && !pr.stopped
|
return pr.waiting > 0 && !pr.stopped
|
||||||
}()
|
}()
|
||||||
if !shouldRequest {
|
if !shouldRequest {
|
||||||
|
Reference in New Issue
Block a user