Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unexpected score in look aside balancer #26213

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix unexpected score in look aside balancer
Signed-off-by: Wei Liu <wei.liu@zilliz.com>
  • Loading branch information
weiliu1031 committed Aug 8, 2023
commit c3baaf696080e0f1522dac7cf950b3dc89130061
16 changes: 14 additions & 2 deletions internal/proxy/look_aside_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,20 @@ func (b *LookAsideBalancer) calculateScore(node int64, cost *internalpb.CostAggr
}

executeSpeed := float64(cost.ResponseTime) - float64(cost.ServiceTime)
workload := math.Pow(float64(1+cost.TotalNQ+executingNQ), 3.0) * float64(cost.ServiceTime)
if workload < 0.0 {
if executingNQ < 0 {
log.Warn("unexpected executing nq value",
zap.Int64("executingNQ", executingNQ))
return executeSpeed
}

if cost.GetTotalNQ() < 0 {
log.Warn("unexpected total nq value",
zap.Int64("totalNq", cost.GetTotalNQ()))
return executeSpeed
}

workload := math.Pow(float64(1+cost.GetTotalNQ()+executingNQ), 3.0) * float64(cost.ServiceTime)
if workload < 0 {
return math.MaxFloat64
}

Expand Down
16 changes: 16 additions & 0 deletions internal/proxy/look_aside_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ func (suite *LookAsideBalancerSuite) TestCalculateScore() {
suite.balancer.metricsUpdateTs.Insert(1, time.Now().UnixMilli()-5000)
score11 := suite.balancer.calculateScore(1, costMetrics4, 0)
suite.Equal(float64(0), score11)

// test unexpected negative nq value
costMetrics6 := &internalpb.CostAggregation{
ResponseTime: 5,
ServiceTime: 1,
TotalNQ: -1,
}
score12 := suite.balancer.calculateScore(-1, costMetrics6, math.MaxInt64)
suite.Equal(float64(4), score12)
costMetrics7 := &internalpb.CostAggregation{
ResponseTime: 5,
ServiceTime: 1,
TotalNQ: 1,
}
score13 := suite.balancer.calculateScore(-1, costMetrics7, -1)
suite.Equal(float64(4), score13)
}

func (suite *LookAsideBalancerSuite) TestSelectNode() {
Expand Down
1 change: 1 addition & 0 deletions pkg/metrics/proxy_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func RegisterProxy(registry *prometheus.Registry) {
registry.MustRegister(UserRPCCounter)

registry.MustRegister(ProxyWorkLoadScore)
registry.MustRegister(ProxyExecutingTotalNq)
}

func CleanupCollectionMetrics(nodeID int64, collection string) {
Expand Down