calico icon indicating copy to clipboard operation
calico copied to clipboard

[RFC] Exact match for index

Open yunhjiang opened this issue 3 years ago • 2 comments

When a selector is used to choose the resource, some match operartor will decide the maxiumum scope of the resource.

For example, considering followed selector: a=='a1' && b in {'b1', 'b2'}

All the result is sure to meet a=='a1' requirement. If we index all the resource through the value for label 'a', the the flow will be:

  1. Use the index to find all the resource that meet a=='a1' through O(1) search,
  2. Evaluate all the result from step 1 with b in {'b1', 'b2'}

Such search is sure to be much faster than the current full scan.

This patch includes:

  1. Create an index for selector and an index for endpoint. Please notice that if the value is not found, then an empty value is used.

  2. When matching a selector to a endpoint, check if any exact match is specified in the selector. If yes, get the value and use that value as index to figure out all the endpoint with the corresponding label/value pair.

  3. When matching an endpoint to a selector, check if any exact match is specified in the endpoint's labels. If yes, get the value and use the value to find out all the selector. Please notice that we will search both selector with the corresponding value, or selector wit empty value, i.e. selector does not specify this label. This can be enhanced in future but let's keep it simple, since this matching is not the heaviest one.

On a LNP environment with 200k neteworkset and 200k networkpolicies, 60M extra memory added on the node on top of 2G.

Description

Related issues/PRs

Todos

  • [ ] Tests
  • [ ] Documentation
  • [ ] Release note

Release Note

None required

yunhjiang avatar Mar 31 '22 20:03 yunhjiang

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 31 '22 20:03 CLAassistant

@caseydavenport was this one on your radar?

lmm avatar Jun 14 '22 16:06 lmm