Skip to content

Commit

Permalink
fix(qrm-plugins): do not hold lock while waiting for GetAdvice response
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-lgy committed Jan 3, 2025
1 parent ca380c9 commit accb311
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,7 @@ func (p *DynamicPolicy) createGetAdviceRequest() (*advisorapi.GetAdviceRequest,
func (p *DynamicPolicy) getAdviceFromAdvisor(ctx context.Context) (isImplemented bool, err error) {
startTime := time.Now()
general.Infof("called")
p.Lock()
defer func() {
p.Unlock()
general.InfoS("finished", "duration", time.Since(startTime))
}()

Expand Down Expand Up @@ -383,9 +381,7 @@ func (p *DynamicPolicy) lwCPUAdvisorServer(stopCh <-chan struct{}) error {
err, status.Code(err))
}

p.Lock()
err = p.allocateByCPUAdvisor(resp)
p.Unlock()
if err != nil {
general.Errorf("allocate by ListAndWatch response of CPUAdvisorServer failed with error: %v", err)
}
Expand All @@ -407,7 +403,9 @@ func (p *DynamicPolicy) allocateByCPUAdvisor(resp *advisorapi.ListAndWatchRespon
startTime := time.Now()
general.Infof("allocateByCPUAdvisor is called")
_ = p.emitter.StoreInt64(util.MetricNameHandleAdvisorRespCalled, 1, metrics.MetricTypeNameRaw)
p.Lock()
defer func() {
p.Unlock()
if err != nil {
_ = p.emitter.StoreInt64(util.MetricNameHandleAdvisorRespFailed, 1, metrics.MetricTypeNameRaw)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ func (p *DynamicPolicy) createGetAdviceRequest() (*advisorsvc.GetAdviceRequest,
func (p *DynamicPolicy) getAdviceFromAdvisor(ctx context.Context) (isImplemented bool, err error) {
startTime := time.Now()
general.Infof("called")
p.Lock()
defer func() {
p.Unlock()
general.InfoS("finished", "duration", time.Since(startTime))
}()

Expand Down Expand Up @@ -217,9 +215,7 @@ func (p *DynamicPolicy) lwMemoryAdvisorServer(stopCh <-chan struct{}) error {
err, status.Code(err))
}

p.Lock()
err = p.handleAdvisorResp(resp)
p.Unlock()
if err != nil {
general.Errorf("handle ListAndWatch response of MemoryAdvisorServer failed with error: %v", err)
}
Expand All @@ -239,7 +235,9 @@ func (p *DynamicPolicy) handleAdvisorResp(advisorResp *advisorsvc.ListAndWatchRe
startTime := time.Now()
general.Infof("called")
_ = p.emitter.StoreInt64(util.MetricNameHandleAdvisorRespCalled, 1, metrics.MetricTypeNameRaw)
p.Lock()
defer func() {
p.Unlock()
if retErr != nil {
_ = p.emitter.StoreInt64(util.MetricNameHandleAdvisorRespFailed, 1, metrics.MetricTypeNameRaw)
}
Expand Down

0 comments on commit accb311

Please sign in to comment.