Skip to content

Conversation

joamaki
Copy link
Contributor

@joamaki joamaki commented Nov 11, 2024

This makes the maglev implementation a bit more generic by not depending on the loadbalancer.Backend type directly, but instead just taking in the bare minimum. To avoid temporary data structures the backend infos are passed as a iter.Seq. This allows #35430 to avoid the sillyness of converting experimental.Backend into loadbalancer.Backend and having to build up temporary hash maps.

To make sure the refactoring does not introduce any changes the TestReproducible hard-codes the expected maglev table to check against.

maglev: Add benchmarks for more values of 'm'

    Benchmark also the more realistic smaller sizes. Results from my machine:

    goos: linux goarch: amd64 pkg: github.com/cilium/cilium/pkg/maglev cpu: 13th Gen Intel(R) Core(TM) i9-13950HX
    BenchmarkGetMaglevTable/2039-32                      681           1746071 ns/op          130665 B/op        151 allocs/op
    BenchmarkGetMaglevTable/4093-32                      367           2793396 ns/op          212250 B/op        151 allocs/op
    BenchmarkGetMaglevTable/16381-32                     135           8171612 ns/op         1192045 B/op        151 allocs/op
    BenchmarkGetMaglevTable/131071-32                     22          52912588 ns/op         1138965 B/op        151 allocs/op

    Signed-off-by: Jussi Maki <jussi@isovalent.com>

maglev: Add reproducibility test

    Add a test to maglev to make sure the generated table is always the same with the default configuration. This ensures we
    don't accidentally change the algorithm and end up with differing maglev tables on nodes when upgrading.

    Signed-off-by: Jussi Maki <jussi@isovalent.com>

maglev: Refactor into cell to allow concurrent use in tests

    Parallel test cases in pkg/loadbalancer/experimental are causing racy access to the maglev permutations array.

    Refactor the maglev package into a cell with its own configuration to allow safely using it in parallel tests with
    potentially different configurations.

    To avoid needless copying and construction of temporary data structures, pass the backends as a sequence to GetLookupTable.

    Benchmark results: 
    goos: linux goarch: amd64 pkg: github.com/cilium/cilium/pkg/maglev cpu: 13th Gen Intel(R) Core(TM) i9-13950HX
    BenchmarkGetMaglevTable/2039-32                      724           1668577 ns/op           55210 B/op        146 allocs/op
    BenchmarkGetMaglevTable/4093-32                      456           2624453 ns/op          112473 B/op        146 allocs/op
    BenchmarkGetMaglevTable/16381-32                     135           8564586 ns/op         1060573 B/op        146 allocs/op
    BenchmarkGetMaglevTable/131071-32                     25          49359121 ns/op          548535 B/op        146 allocs/op

    Signed-off-by: Jussi Maki <jussi@isovalent.com>

@joamaki joamaki requested review from a team as code owners November 11, 2024 11:02
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Nov 11, 2024
@joamaki joamaki requested a review from rgo3 November 11, 2024 11:02
@joamaki
Copy link
Contributor Author

joamaki commented Nov 11, 2024

/test

@joamaki joamaki added the release-note/misc This PR makes changes that have no direct user impact. label Nov 11, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Nov 11, 2024
Copy link
Contributor

@rgo3 rgo3 left a comment

Choose a reason for hiding this comment

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

Loader changes LGTM

Copy link
Contributor

@tommyp1ckles tommyp1ckles left a comment

Choose a reason for hiding this comment

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

ack for CLI changes.

@joamaki joamaki force-pushed the pr/joamaki/maglev-cleanup branch from 31006dd to 8d30867 Compare November 25, 2024 16:20
@joamaki joamaki requested review from a team as code owners November 25, 2024 16:20
@joamaki joamaki requested a review from jrajahalme November 25, 2024 16:20
@joamaki joamaki force-pushed the pr/joamaki/maglev-cleanup branch from 8d30867 to 5b9ccd7 Compare November 29, 2024 10:03
@joamaki joamaki force-pushed the pr/joamaki/maglev-cleanup branch 2 times, most recently from cb20112 to 7f7a5b5 Compare December 3, 2024 11:53
@joamaki
Copy link
Contributor Author

joamaki commented Dec 3, 2024

/test

@joamaki joamaki enabled auto-merge December 3, 2024 14:15
@joamaki joamaki disabled auto-merge December 3, 2024 14:15
@joamaki joamaki force-pushed the pr/joamaki/maglev-cleanup branch from 7f7a5b5 to 1b85500 Compare December 3, 2024 14:35
@joamaki
Copy link
Contributor Author

joamaki commented Dec 3, 2024

/test

@joamaki joamaki force-pushed the pr/joamaki/maglev-cleanup branch from 1b85500 to 58cc253 Compare December 3, 2024 15:24
@joamaki joamaki requested a review from brb December 4, 2024 10:49
@joamaki
Copy link
Contributor Author

joamaki commented Dec 4, 2024

/test

Copy link
Member

@brb brb left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@joamaki joamaki enabled auto-merge December 5, 2024 10:44
@joamaki joamaki disabled auto-merge December 5, 2024 10:45
@joamaki joamaki force-pushed the pr/joamaki/maglev-cleanup branch 2 times, most recently from 39bebc2 to 9286446 Compare December 5, 2024 11:42
@joamaki
Copy link
Contributor Author

joamaki commented Dec 5, 2024

/test

@joamaki joamaki enabled auto-merge December 5, 2024 12:21
@joamaki joamaki force-pushed the pr/joamaki/maglev-cleanup branch 2 times, most recently from 6846835 to a6f67d1 Compare December 5, 2024 14:54
@joamaki
Copy link
Contributor Author

joamaki commented Dec 5, 2024

/test

Benchmark also the more realistic smaller sizes.
Results from my machine:

goos: linux
goarch: amd64
pkg: github.com/cilium/cilium/pkg/maglev
cpu: 13th Gen Intel(R) Core(TM) i9-13950HX
BenchmarkGetMaglevTable/2039-32                      681           1746071 ns/op          130665 B/op        151 allocs/op
BenchmarkGetMaglevTable/4093-32                      367           2793396 ns/op          212250 B/op        151 allocs/op
BenchmarkGetMaglevTable/16381-32                     135           8171612 ns/op         1192045 B/op        151 allocs/op
BenchmarkGetMaglevTable/131071-32                     22          52912588 ns/op         1138965 B/op        151 allocs/op

Signed-off-by: Jussi Maki <jussi@isovalent.com>
Add a test to maglev to make sure the generated table is always
the same with the default configuration. This ensures we don't accidentally
change the algorithm and end up with differing maglev tables on nodes when
upgrading.

Signed-off-by: Jussi Maki <jussi@isovalent.com>
Parallel test cases in pkg/loadbalancer/experimental are causing racy
access to the maglev permutations array.

Refactor the maglev package into a cell with its own configuration to allow
safely using it in parallel tests with potentially different configurations.

To avoid needless copying and construction of temporary data structures,
pass the backends as a sequence to GetLookupTable.

Benchmark results:
goos: linux
goarch: amd64
pkg: github.com/cilium/cilium/pkg/maglev
cpu: 13th Gen Intel(R) Core(TM) i9-13950HX
BenchmarkGetMaglevTable/2039-32                      724           1668577 ns/op           55210 B/op        146 allocs/op
BenchmarkGetMaglevTable/4093-32                      456           2624453 ns/op          112473 B/op        146 allocs/op
BenchmarkGetMaglevTable/16381-32                     135           8564586 ns/op         1060573 B/op        146 allocs/op
BenchmarkGetMaglevTable/131071-32                     25          49359121 ns/op          548535 B/op        146 allocs/op

Signed-off-by: Jussi Maki <jussi@isovalent.com>
@joamaki joamaki force-pushed the pr/joamaki/maglev-cleanup branch from a6f67d1 to 2993089 Compare December 6, 2024 13:41
@joamaki
Copy link
Contributor Author

joamaki commented Dec 6, 2024

/test

@joamaki joamaki added this pull request to the merge queue Dec 6, 2024
Merged via the queue into cilium:main with commit 273d83f Dec 6, 2024
64 checks passed
@joamaki joamaki deleted the pr/joamaki/maglev-cleanup branch December 6, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants