Skip to content

Conversation

joamaki
Copy link
Contributor

@joamaki joamaki commented Jul 22, 2025

The L3n4Addr is used in a lot of places and is compared and hashed a lot. Reduce memory usage and speed up comparisons by making L3n4Addr a unique.Handle. In the pkg/loadbalancer/benchmark this is a 30% save on memory!

The relevant change is to pkg/loadbalancer/loadbalancer.go, other files are changed just to accomodate the new API.

pkg/loadbalancer/benchmark before:

Min: Allocated 563043kB in total, 1837855 objects / 118158kB still reachable (per service:  36 objs, 11531B alloc,  2419B in-use)
Avg: Allocated 583710kB in total, 2174642 objects / 154810kB still reachable (per service:  43 objs, 11954B alloc,  3170B in-use)
Max: Allocated 643000kB in total, 3089878 objects / 263505kB still reachable (per service:  61 objs, 13168B alloc,  5396B in-use)

After:

Min: Allocated 510398kB in total, 1734286 objects /  83716kB still reachable (per service:  34 objs, 10452B alloc,  1714B in-use)
Avg: Allocated 523617kB in total, 2188965 objects / 125627kB still reachable (per service:  43 objs, 10723B alloc,  2572B in-use) 
Max: Allocated 564751kB in total, 3478097 objects / 229608kB still reachable (per service:  69 objs, 11566B alloc,  4702B in-use)

@joamaki joamaki added the release-note/misc This PR makes changes that have no direct user impact. label Jul 22, 2025
@github-actions github-actions bot added the sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. label Jul 22, 2025
@joamaki joamaki force-pushed the pr/joamaki/l3n4addr-unique branch from d58729d to dc559e2 Compare July 22, 2025 09:20
@joamaki
Copy link
Contributor Author

joamaki commented Jul 22, 2025

/test

@joamaki joamaki force-pushed the pr/joamaki/l3n4addr-unique branch from dc559e2 to f1acff4 Compare July 22, 2025 09:51
@joamaki
Copy link
Contributor Author

joamaki commented Jul 22, 2025

/test

@joamaki
Copy link
Contributor Author

joamaki commented Jul 22, 2025

/scale-100

@joamaki joamaki marked this pull request as ready for review July 23, 2025 07:44
@joamaki joamaki requested review from a team as code owners July 23, 2025 07:44
Copy link
Member

@MrFreezeex MrFreezeex left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to me from a clustermesh perspective, also I looked a bit the new implementation and lgtm too/seems pretty nice :D (although I don't know too well this part of the code 😅 )

@joamaki joamaki enabled auto-merge July 24, 2025 09:29
@tklauser tklauser removed the request for review from derailed July 25, 2025 09:08
Copy link
Member

@sayboras sayboras left a comment

Choose a reason for hiding this comment

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

🚢

@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 Jul 28, 2025
The L3n4Addr is used in a lot of places and is compared and hashed a lot.
Reduce memory usage and speed up comparisons by making L3n4Addr a unique.Handle.

pkg/loadbalancer/benchmark before:
Min: Allocated 563043kB in total, 1837855 objects / 118158kB still reachable (per service:  36 objs, 11531B alloc,  2419B in-use)
Avg: Allocated 583710kB in total, 2174642 objects / 154810kB still reachable (per service:  43 objs, 11954B alloc,  3170B in-use)
Max: Allocated 643000kB in total, 3089878 objects / 263505kB still reachable (per service:  61 objs, 13168B alloc,  5396B in-use)

After:
Min: Allocated 510398kB in total, 1734286 objects /  83716kB still reachable (per service:  34 objs, 10452B alloc,  1714B in-use)
Avg: Allocated 523617kB in total, 2188965 objects / 125627kB still reachable (per service:  43 objs, 10723B alloc,  2572B in-use)
Max: Allocated 564751kB in total, 3478097 objects / 229608kB still reachable (per service:  69 objs, 11566B alloc,  4702B in-use)

Signed-off-by: Jussi Maki <jussi@isovalent.com>
@joamaki joamaki force-pushed the pr/joamaki/l3n4addr-unique branch from f1acff4 to 35f3d8d Compare July 29, 2025 15:13
@joamaki joamaki requested review from a team as code owners July 29, 2025 15:13
@joamaki joamaki requested review from marseel and squeed July 29, 2025 15:13
@joamaki
Copy link
Contributor Author

joamaki commented Jul 29, 2025

/test

@joamaki joamaki added the needs-backport/1.18 This PR / issue needs backporting to the v1.18 branch label Jul 29, 2025
@joamaki
Copy link
Contributor Author

joamaki commented Jul 29, 2025

Marking this as needs-backport/1.18 since it reduces memory usage significantly.

@joamaki joamaki force-pushed the pr/joamaki/l3n4addr-unique branch from 35f3d8d to 089b870 Compare July 29, 2025 15:52
@joamaki joamaki removed request for a team, marseel and squeed July 29, 2025 15:53
@joamaki
Copy link
Contributor Author

joamaki commented Jul 29, 2025

Reverted the L4Type as U8Proto change I had as I had missed that L4Addr was embedded into ClusterService and thus is serialized to kvstore. Have to revisit hat by decoupling ClusterService from the loadbalancer types in another PR. Removed the review requests related to this.

@joamaki
Copy link
Contributor Author

joamaki commented Jul 29, 2025

/test

@joestringer joestringer removed the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jul 29, 2025
@joamaki joamaki added this pull request to the merge queue Jul 30, 2025
Merged via the queue into cilium:main with commit 676d346 Jul 30, 2025
68 checks passed
@joamaki joamaki deleted the pr/joamaki/l3n4addr-unique branch July 30, 2025 08:33
@maintainer-s-little-helper maintainer-s-little-helper bot added ready-to-merge This PR has passed all tests and received consensus from code owners to merge. labels Jul 30, 2025
@rastislavs rastislavs mentioned this pull request Jul 31, 2025
14 tasks
@rastislavs rastislavs 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 Jul 31, 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 4, 2025
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. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants