Skip to content

perf(hscontrol): fixes latency due to loading machines from db#6

Open
amitsingh21 wants to merge 4 commits into
rr-release-0.22.3from
perf/prefetch-machines
Open

perf(hscontrol): fixes latency due to loading machines from db#6
amitsingh21 wants to merge 4 commits into
rr-release-0.22.3from
perf/prefetch-machines

Conversation

@amitsingh21
Copy link
Copy Markdown

  • read the CONTRIBUTING guidelines
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

When expandAlias falls through to getIPsForUser for a non-user alias
(e.g. CIDR destinations like "10.81.48.0/24"), filterMachinesByUser
returns an empty slice. The subsequent excludeCorrectlyTaggedNodes
call then iterates every entry in aclPolicy.TagOwners (1502 in our
prod policy) and allocates a fresh tags slice, only to operate on
an empty machine set. Short-circuit before that wasteful work.

Output is bit-identical: excludeCorrectlyTaggedNodes returns an empty
slice when given empty nodes, which already hits the
"if len(filteredMachines) == 0" branch below. The new check just
avoids the wasted iteration and allocations in between.

Measured on io-prod (perf-iter4 -> perf-iter5):
- Pod CPU: 4.6 -> 3.0 cores (-33%, -1.5 cores) sustained.
- runtime.scanobject (GC): -63%.
- gcBgMarkWorker: -46%.

Local bench against real prod data (901 machines, 1502-rule policy):
- ns/op:     85.1 ms -> 59.0 ms  (-31%)
- B/op:      30.2 MB -> 7.49 MB  (-75%)
- allocs/op: 456,485 -> 50,659   (-89%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant