loadbalancer: Flatten the backend representation#44511
Merged
joamaki merged 2 commits intocilium:mainfrom Mar 6, 2026
Merged
Conversation
Contributor
Author
|
/test |
57c450a to
0a3876f
Compare
0a3876f to
3037ecf
Compare
Contributor
Author
|
/test |
rastislavs
approved these changes
Mar 5, 2026
Contributor
rastislavs
left a comment
There was a problem hiding this comment.
Looks good for my codeowners
joamaki
commented
Mar 5, 2026
This benchmarks adding a backend that is shared by 2000 services. Signed-off-by: Jussi Maki <jussi@isovalent.com>
Flatten the Backend by storing a backend instance per row in the backend table rather than having them inside the backend object. This makes handling backends that are shared by many services much more efficient: Before: jussi@macbook:~/go/src/github.com/cilium/cilium/pkg/loadbalancer/writer/ > go test . -bench . -benchmem goos: linux goarch: arm64 pkg: github.com/cilium/cilium/pkg/loadbalancer/writer Benchmark_UpsertServiceAndFrontends_100-6 3687 311606 ns/op 320918 objects/sec 326431 B/op 4639 allocs/op Benchmark_UpsertServiceAndFrontends_100_Unchanged-6 14514 81891 ns/op 1221133 objects/sec 50012 B/op 1151 allocs/op Benchmark_UpsertServiceAndFrontends_1-6 141879 8088 ns/op 123640 objects/sec 13087 B/op 89 allocs/op BenchmarkInsertBackend-6 3007 387712 ns/op 257923 objects/sec 511640 B/op 6785 allocs/op BenchmarkReplaceBackend-6 3216202 377.9 ns/op 2646089 objects/sec 448 B/op 9 allocs/op BenchmarkReplaceService-6 2284094 524.4 ns/op 1906815 objects/sec 464 B/op 10 allocs/op Benchmark_UpsertBackends_SharedBackendManyServices-6 1 3182529066 ns/op 962720856 B/op 16146352 allocs/op PASS ok github.com/cilium/cilium/pkg/loadbalancer/writer 10.315s After: jussi@macbook:~/go/src/github.com/cilium/cilium/pkg/loadbalancer/writer/ > stg push > loadbalancer-flatten-backend jussi@macbook:~/go/src/github.com/cilium/cilium/pkg/loadbalancer/writer/ > go test . -bench . -benchmem goos: linux goarch: arm64 pkg: github.com/cilium/cilium/pkg/loadbalancer/writer Benchmark_UpsertServiceAndFrontends_100-6 3796 314436 ns/op 318030 objects/sec 328109 B/op 4840 allocs/op Benchmark_UpsertServiceAndFrontends_100_Unchanged-6 14769 80686 ns/op 1239372 objects/sec 50012 B/op 1151 allocs/op Benchmark_UpsertServiceAndFrontends_1-6 144716 7964 ns/op 125565 objects/sec 13103 B/op 91 allocs/op BenchmarkInsertBackend-6 3433 338560 ns/op 295369 objects/sec 439490 B/op 5285 allocs/op BenchmarkReplaceBackend-6 4402164 272.7 ns/op 3667044 objects/sec 226 B/op 6 allocs/op BenchmarkReplaceService-6 2189962 535.3 ns/op 1868165 objects/sec 464 B/op 10 allocs/op Benchmark_UpsertBackends_SharedBackendManyServices-6 1480 756108 ns/op 552204 B/op 14062 allocs/op PASS ok github.com/cilium/cilium/pkg/loadbalancer/writer 8.681s The "Benchmark_UpsertBackends_SharedBackendManyServices" inserts a backend that is shared by 2000 services. By storing the backends flat in the table this is now 4000x faster and consumes ~500kB instead of 1GB of memory. The downside of this is that now it is harder to get the set of backend IP addresses and we need to dedup on the consuming side. The backend table by default is also now sorted first by service name. Fixes: cilium#44310 Signed-off-by: Jussi Maki <jussi@isovalent.com>
3037ecf to
3f911a2
Compare
Contributor
Author
|
/test |
jrajahalme
approved these changes
Mar 5, 2026
Contributor
Author
|
/test |
dylandreimerink
approved these changes
Mar 6, 2026
Member
|
/test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This flattens the
loadbalancer.Backendby storing "backend instance" per row in the backend table instead of having a map ofBackendParamsinside theBackendobject.Before:
After:
The "Benchmark_UpsertBackends_SharedBackendManyServices" inserts a backend that is shared by 2000 services.
By storing the backends flat in the table this is now 4000x faster and consumes ~500kB instead of 1GB
of memory.
The downside of this is that now it is harder to get the set of backend IP addresses and we need
to dedup on the consuming side. The backend table by default is also now sorted first by
service name.
Fixes: #44310