enhance: Optimize param cost in search (#37738)

Signed-off-by: Wei Liu <wei.liu@zilliz.com>
pull/37794/head
wei liu 2024-11-19 10:14:40 +08:00 committed by GitHub
parent 6d86b9022e
commit fceff6ed7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 9 deletions

View File

@ -67,9 +67,10 @@ const (
)
type LBPolicyImpl struct {
getBalancer func() LBBalancer
clientMgr shardClientMgr
balancerMap map[string]LBBalancer
getBalancer func() LBBalancer
clientMgr shardClientMgr
balancerMap map[string]LBBalancer
retryOnReplica int
}
func NewLBPolicyImpl(clientMgr shardClientMgr) *LBPolicyImpl {
@ -77,18 +78,21 @@ func NewLBPolicyImpl(clientMgr shardClientMgr) *LBPolicyImpl {
balancerMap[LookAside] = NewLookAsideBalancer(clientMgr)
balancerMap[RoundRobin] = NewRoundRobinBalancer()
balancePolicy := params.Params.ProxyCfg.ReplicaSelectionPolicy.GetValue()
getBalancer := func() LBBalancer {
balancePolicy := params.Params.ProxyCfg.ReplicaSelectionPolicy.GetValue()
if _, ok := balancerMap[balancePolicy]; !ok {
return balancerMap[LookAside]
}
return balancerMap[balancePolicy]
}
retryOnReplica := Params.ProxyCfg.RetryTimesOnReplica.GetAsInt()
return &LBPolicyImpl{
getBalancer: getBalancer,
clientMgr: clientMgr,
balancerMap: balancerMap,
getBalancer: getBalancer,
clientMgr: clientMgr,
balancerMap: balancerMap,
retryOnReplica: retryOnReplica,
}
}
@ -230,12 +234,11 @@ func (lb *LBPolicyImpl) Execute(ctx context.Context, workload CollectionWorkLoad
}
// let every request could retry at least twice, which could retry after update shard leader cache
retryTimes := Params.ProxyCfg.RetryTimesOnReplica.GetAsInt()
wg, ctx := errgroup.WithContext(ctx)
for k, v := range dml2leaders {
channel := k
nodes := v
channelRetryTimes := retryTimes
channelRetryTimes := lb.retryOnReplica
if len(nodes) > 0 {
channelRetryTimes *= len(nodes)
}