Skip to content

k8s: In endpoint parsing reuse Backend and Ports for each address#40987

Merged
joamaki merged 1 commit intocilium:mainfrom
joamaki:pr/joamaki/k8s-improve-parse-endpointslice
Aug 8, 2025
Merged

k8s: In endpoint parsing reuse Backend and Ports for each address#40987
joamaki merged 1 commit intocilium:mainfrom
joamaki:pr/joamaki/k8s-improve-parse-endpointslice

Conversation

@joamaki
Copy link
Copy Markdown
Contributor

@joamaki joamaki commented Aug 7, 2025

Since the ports are the same for everything in the EndpointSlice just prepare the 'Ports' map once.

Similarly for Backend as the data is the same for each address allocate it just once.

To further reduce allocations pre-allocate the hash maps.

Benchmark results with https://github.com/joamaki/cilium-lb-load-test:

Current main (image tag deaee71):

Creating 1000 Services and EndpointSlices (30 backends per service, 30000 in total) in namespace cni-load-test... Finished creating resources.
Waiting 10 seconds to settle...
Recording memory usage
RSS (kB): 257724.0 (diff 55952.0)
Reachable kB: 42516.21875
Allocations: 3875906
Allocated kB: 169957.71875
CPU time seconds: 1.5099999999999998

This commit:

Creating 1000 Services and EndpointSlices (30 backends per service, 30000 in total) in namespace cni-load-test... Finished creating resources.
Waiting 10 seconds to settle...
Recording memory usage
RSS (kB): 258784.0 (diff 50344.0)
Reachable kB: 37336.3984375
Allocations: 3772102
Allocated kB: 162521.7578125
CPU time seconds: 1.4699999999999989

Roughly ~10% less memory allocated and reachable.

Reduced memory usage by roughly 10% for large EndpointSlices by sharing identical objects.

@joamaki joamaki added the release-note/misc This PR makes changes that have no direct user impact. label Aug 7, 2025
@joamaki joamaki requested a review from marseel August 7, 2025 08:59
@joamaki joamaki marked this pull request as ready for review August 7, 2025 08:59
@joamaki joamaki requested a review from a team as a code owner August 7, 2025 08:59
@joamaki joamaki added the needs-backport/1.18 This PR / issue needs backporting to the v1.18 branch label Aug 7, 2025
@joamaki
Copy link
Copy Markdown
Contributor Author

joamaki commented Aug 7, 2025

/test

@joamaki
Copy link
Copy Markdown
Contributor Author

joamaki commented Aug 7, 2025

Marked for v1.18 backports as this is a significant improvement in memory use for large clusters and the changes are small.

@joamaki
Copy link
Copy Markdown
Contributor Author

joamaki commented Aug 7, 2025

/test

Since the ports are the same for everything in the EndpointSlice
just prepare the 'Ports' map once.

Similarly for Backend as the data is the same for each address
allocate it just once.

To further reduce allocations pre-allocate the hash maps.

Benchmark results with https://github.com/joamaki/cilium-lb-load-test:

Current `main` (image tag deaee71):
Creating 1000 Services and EndpointSlices (30 backends per service, 30000 in total) in namespace cni-load-test...
Finished creating resources.
Waiting 10 seconds to settle...
Recording memory usage
RSS (kB): 257724.0 (diff 55952.0)
Reachable kB: 42516.21875
Allocations: 3875906
Allocated kB: 169957.71875
CPU time seconds: 1.5099999999999998

This commit:
Creating 1000 Services and EndpointSlices (30 backends per service, 30000 in total) in namespace cni-load-test...
Finished creating resources.
Waiting 10 seconds to settle...
Recording memory usage
RSS (kB): 258784.0 (diff 50344.0)
Reachable kB: 37336.3984375
Allocations: 3772102
Allocated kB: 162521.7578125
CPU time seconds: 1.4699999999999989

Roughly ~10% less memory allocated and reachable.

Signed-off-by: Jussi Maki <jussi@isovalent.com>
@joamaki joamaki force-pushed the pr/joamaki/k8s-improve-parse-endpointslice branch from 485d762 to 4516432 Compare August 7, 2025 15:25
@joamaki
Copy link
Copy Markdown
Contributor Author

joamaki commented Aug 7, 2025

/test

@joamaki joamaki requested a review from marseel August 7, 2025 15:33
Copy link
Copy Markdown
Member

@marseel marseel left a comment

Choose a reason for hiding this comment

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

Thanks, now looks good!

@joamaki joamaki enabled auto-merge August 8, 2025 06:50
@joamaki joamaki added this pull request to the merge queue Aug 8, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Aug 8, 2025
Merged via the queue into cilium:main with commit d8638b0 Aug 8, 2025
70 checks passed
@joamaki joamaki deleted the pr/joamaki/k8s-improve-parse-endpointslice branch August 8, 2025 09:36
@YutaroHayakawa YutaroHayakawa mentioned this pull request Aug 11, 2025
10 tasks
@YutaroHayakawa YutaroHayakawa added backport-pending/1.18 The backport for Cilium 1.18.x for this PR is in progress. and removed needs-backport/1.18 This PR / issue needs backporting to the v1.18 branch labels Aug 11, 2025
@github-actions github-actions bot added backport-done/1.18 The backport for Cilium 1.18.x for this PR is done. and removed backport-pending/1.18 The backport for Cilium 1.18.x for this PR is in progress. labels Aug 12, 2025
@cilium-release-bot cilium-release-bot bot moved this to Released in cilium v1.19.0 Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-done/1.18 The backport for Cilium 1.18.x for this PR is done. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.

Projects

No open projects
Status: Released

Development

Successfully merging this pull request may close these issues.

4 participants