Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to netlink.RouteListFilteredIter() API #9139

Merged
merged 7 commits into from
Aug 30, 2024

Conversation

fasaxc
Copy link
Member

@fasaxc fasaxc commented Aug 15, 2024

Description

Optimise RouteTable resync methods:

  • Add benchmark for resync with various numbers of routes.

  • Switch to netlink.RouteListFilteredIter() API, which avoids a series of large slice allocations.

  • Use benchmark to find more wins:

    • Use deltatracker.WithValuesEqualFn, DeepEquals is the default and it was much slower.
    • Pre-allocate the seenKeys set, saves the expense of copying it multiple times as it grows.
    • Copy the netlink Route once per loop to a scratch variable to avoid escape to the heap.

Overall, significantly reduces allocations from when there are many routes to resync and significantly increases performance.

Benchmarks for resyncing 64k routes; 50% reduction in resync time; 80% saving in bytes allocated; GC-included CPU usage down by 60%.

v3.28:

BenchmarkResync65536-12    	       7	 156498055 ns/op	 242857143 ncpu/op	203556697 B/op	  790473 allocs/op

master:

BenchmarkResync65536-12    	       7	 143550698 ns/op	 270000000 ncpu/op	208147700 B/op	  724999 allocs/op

This PR: 

BenchmarkResync65536-12    	      13	  84051862 ns/op	 108461538 ncpu/op	36912350 B/op	  526080 allocs/op

Related issues/PRs

Follow on from #8979
CORE-10626

Todos

  • Tests
  • Documentation
  • Release note

Release Note

Felix's route resync logic has been optimised; it now uses 50% less CPU time and 80% less memory.

Reminder for the reviewer

Make sure that this PR has the correct labels and milestone set.

Every PR needs one docs-* label.

  • docs-pr-required: This change requires a change to the documentation that has not been completed yet.
  • docs-completed: This change has all necessary documentation completed.
  • docs-not-required: This change has no user-facing impact and requires no docs.

Every PR needs one release-note-* label.

  • release-note-required: This PR has user-facing changes. Most PRs should have this label.
  • release-note-not-required: This PR has no user-facing changes.

Other optional labels:

  • cherry-pick-candidate: This PR should be cherry-picked to an earlier release. For bug fixes only.
  • needs-operator-pr: This PR is related to install and requires a corresponding change to the operator.

@marvin-tigera marvin-tigera added this to the Calico v3.29.0 milestone Aug 15, 2024
@marvin-tigera marvin-tigera added release-note-required Change has user-facing impact (no matter how small) docs-pr-required Change is not yet documented labels Aug 15, 2024
@fasaxc fasaxc force-pushed the netlink-iter branch 6 times, most recently from 8f10407 to 47229b8 Compare August 21, 2024 15:36
@fasaxc fasaxc added docs-not-required Docs not required for this change and removed docs-pr-required Change is not yet documented labels Aug 22, 2024
@fasaxc fasaxc marked this pull request as ready for review August 22, 2024 08:47
@fasaxc fasaxc requested a review from a team as a code owner August 22, 2024 08:47
Copy link
Contributor

@aaaaaaaalex aaaaaaaalex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one potential change, might be nothing

felix/routetable/bench_test.go Show resolved Hide resolved
felix/routetable/route_table.go Show resolved Hide resolved
@fasaxc
Copy link
Member Author

fasaxc commented Aug 27, 2024

Just holding this back until I've got the RouteTable merge to Enterprise done. Might want to upstream some of the fixes there and I don't want this to conflict...

fasaxc added 7 commits August 30, 2024 11:38
Should significantly reduce allocations from netlink
when there are many routes.
Noticed the default DeepEquals option was a hot spot
when profiling RouteTable.
Allocate one scrate netlink.Route and re-use to avoid spilling
every route to the heap.
Saves copies as the set size grows.
Get is less expensive so it's worth it if the route hasn't
changed (the mainline).
@fasaxc fasaxc merged commit 8ee6be2 into projectcalico:master Aug 30, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required Docs not required for this change release-note-required Change has user-facing impact (no matter how small)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants