Skip to content

Commit

Permalink
Don't lookup LBs that don't exist in cache
Browse files Browse the repository at this point in the history
Running the LB predicate that matches on name takes a long time if the
LB table has many LBs. For example, looking up ~40 LBs in a table with
~200k rows took aproximately 3s.

The service controller has a second level cache and knows which LBs need
to be added and which need to be updated. Avoid this lookup for LBs that
are to be added.

Signed-off-by: Jaime Caamaño Ruiz <jcaamano@redhat.com>
(cherry picked from commit 0573fe5)
  • Loading branch information
jcaamano committed May 27, 2022
1 parent e490188 commit c4a539b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
19 changes: 19 additions & 0 deletions go-controller/pkg/libovsdbops/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ func BuildLoadBalancer(name string, protocol nbdb.LoadBalancerProtocol, selectio
}
}

// CreateLoadBalancersOps creates the provided load balancers returning the
// corresponding ops
func CreateLoadBalancersOps(nbClient libovsdbclient.Client, ops []libovsdb.Operation, lbs ...*nbdb.LoadBalancer) ([]libovsdb.Operation, error) {
opModels := make([]operationModel, 0, len(lbs))
for i := range lbs {
lb := lbs[i]
opModel := operationModel{
Model: lb,
OnModelUpdates: onModelUpdatesNone(),
ErrNotFound: false,
BulkOp: false,
}
opModels = append(opModels, opModel)
}

modelClient := newModelClient(nbClient)
return modelClient.CreateOrUpdateOps(ops, opModels...)
}

// CreateOrUpdateLoadBalancersOps creates or updates the provided load balancers
// returning the corresponding ops
func CreateOrUpdateLoadBalancersOps(nbClient libovsdbclient.Client, ops []libovsdb.Operation, lbs ...*nbdb.LoadBalancer) ([]libovsdb.Operation, error) {
Expand Down
13 changes: 12 additions & 1 deletion go-controller/pkg/ovn/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func EnsureLBs(nbClient libovsdbclient.Client, service *corev1.Service, LBs []LB
}

lbs := make([]*nbdb.LoadBalancer, 0, len(LBs))
existinglbs := make([]*nbdb.LoadBalancer, 0, len(LBs))
newlbs := make([]*nbdb.LoadBalancer, 0, len(LBs))
addLBsToSwitch := map[string][]*nbdb.LoadBalancer{}
removeLBsFromSwitch := map[string][]*nbdb.LoadBalancer{}
addLBsToRouter := map[string][]*nbdb.LoadBalancer{}
Expand All @@ -71,10 +73,14 @@ func EnsureLBs(nbClient libovsdbclient.Client, service *corev1.Service, LBs []LB
existingSwitches := sets.String{}
existingGroups := sets.String{}
if existingLB != nil {
blb.UUID = existingLB.UUID
existinglbs = append(existinglbs, blb)
toDelete.Delete(existingLB.UUID)
existingRouters = existingLB.Routers
existingSwitches = existingLB.Switches
existingGroups = existingLB.Groups
} else {
newlbs = append(newlbs, blb)
}
wantRouters := sets.NewString(lb.Routers...)
wantSwitches := sets.NewString(lb.Switches...)
Expand All @@ -87,7 +93,12 @@ func EnsureLBs(nbClient libovsdbclient.Client, service *corev1.Service, LBs []LB
mapLBDifferenceByKey(removeLBsFromGroups, existingGroups, wantGroups, blb)
}

ops, err := libovsdbops.CreateOrUpdateLoadBalancersOps(nbClient, nil, lbs...)
ops, err := libovsdbops.CreateOrUpdateLoadBalancersOps(nbClient, nil, existinglbs...)
if err != nil {
return err
}

ops, err = libovsdbops.CreateLoadBalancersOps(nbClient, ops, newlbs...)
if err != nil {
return err
}
Expand Down

0 comments on commit c4a539b

Please sign in to comment.