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)
(cherry picked from commit c4a539b)
  • Loading branch information
jcaamano committed Jul 7, 2022
1 parent 3ce4a28 commit 3369d38
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
21 changes: 21 additions & 0 deletions go-controller/pkg/libovsdbops/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,27 @@ func createOrUpdateLoadBalancerOps(nbClient libovsdbclient.Client, ops []libovsd
return ops, nil
}

// 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) {
if ops == nil {
ops = []libovsdb.Operation{}
Expand Down
4 changes: 4 additions & 0 deletions go-controller/pkg/libovsdbops/model_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (m *ModelClient) WithClient(client client.Client) *ModelClient {
return &cl
}

func onModelUpdatesNone() []interface{} {
return nil
}

/*
CreateOrUpdate performs idempotent operations against libovsdb according to the
following logic:
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 @@ -51,6 +51,8 @@ func EnsureLBs(nbClient libovsdbclient.Client, externalIDs map[string]string, 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 @@ -67,10 +69,14 @@ func EnsureLBs(nbClient libovsdbclient.Client, externalIDs map[string]string, 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 @@ -83,7 +89,12 @@ func EnsureLBs(nbClient libovsdbclient.Client, externalIDs map[string]string, 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 3369d38

Please sign in to comment.