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

background-sync: spread node updates over time. #32577

Merged
merged 1 commit into from
May 17, 2024
Merged

Conversation

marseel
Copy link
Contributor

@marseel marseel commented May 16, 2024

Before, depending on cluster-size we were triggering node update for
each node at fixed intervals depending on cluster-size. This resulted in
high cpu usage spike in agent. While the intent is to fix state that got
stale and shouldn't be the primary source of updates, it makes sense to
spread these updates over time to average out cpu usage.

Also, reenable backgroundSync test.

GC CPU usage on 100-node cluster with IPSec enabled before:
image
After:
image

Improved background resynchronization of nodes. Before all nodes were being updated at the same time, now we spread updates over time to average out CPU usage.

@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 May 16, 2024
@marseel marseel force-pushed the improve_background_sync branch 3 times, most recently from 2cd729a to 959d5ee Compare May 17, 2024 09:50
@marseel marseel changed the title Improve background sync background-sync: spread node updates over time. May 17, 2024
@marseel marseel added the release-note/minor This PR changes functionality that users may find relevant to operating Cilium. label May 17, 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 May 17, 2024
@marseel
Copy link
Contributor Author

marseel commented May 17, 2024

/test

@marseel marseel marked this pull request as ready for review May 17, 2024 10:01
@marseel marseel requested a review from a team as a code owner May 17, 2024 10:01
@marseel marseel requested review from danehans and removed request for danehans May 17, 2024 10:01
@marseel
Copy link
Contributor Author

marseel commented May 17, 2024

Removing @danehans from reviews due to cilium/community#118

@tklauser tklauser self-requested a review May 17, 2024 10:28
Before, depending on cluster-size we were triggering node update for
each node at fixed intervals depending on cluster-size. This resulted in
high cpu usage spike in agent. While the intent is to fix state that got
stale and shouldn't be the primary source of updates, it makes sense to
spread these updates over time to average out cpu usage.

Also, reenable backgroundSync test.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
@marseel
Copy link
Contributor Author

marseel commented May 17, 2024

/test

pkg/node/manager/manager.go Show resolved Hide resolved
marseel added a commit that referenced this pull request May 17, 2024
Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
marseel added a commit that referenced this pull request May 17, 2024
Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
@tklauser tklauser enabled auto-merge May 17, 2024 12:10
marseel added a commit that referenced this pull request May 17, 2024
Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
@tklauser tklauser added this pull request to the merge queue May 17, 2024
marseel added a commit that referenced this pull request May 17, 2024
Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
Merged via the queue into main with commit 1963879 May 17, 2024
271 checks passed
@tklauser tklauser deleted the improve_background_sync branch May 17, 2024 12:21
sayboras pushed a commit that referenced this pull request Jun 4, 2024
Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Added CI test to make sure that we accidentally don't add calls that
modify XFRMState without going through cache.

Also, added hidden option that allows to turn of caching.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
marseel added a commit to marseel/cilium that referenced this pull request Jun 4, 2024
[ upstream commit 2019ebe ]

During bootrstrap, we don't know number of nodes and new implementation
essentially was hot looping till fetched nodes. Also, in case of cluster
with single node, rate-limiter was not rate-limiting.

Fixes cilium#32577

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
marseel added a commit to marseel/cilium that referenced this pull request Jun 4, 2024
[ upstream commit 3a4c57f ]

[ Backporter's notes: switch default to false - not enabled ]

Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to cilium#32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Added CI test to make sure that we accidentally don't add calls that
modify XFRMState without going through cache.

Also, added hidden option that allows to turn of caching.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
marseel added a commit to marseel/cilium that referenced this pull request Jun 4, 2024
[ upstream commit 3a4c57f ]

[ Backporter's notes: switch default to false - so not enabled by
default. Switch from testing package to checkmate in unit tests ]

Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to cilium#32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Added CI test to make sure that we accidentally don't add calls that
modify XFRMState without going through cache.

Also, added hidden option that allows to turn of caching.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
marseel added a commit to marseel/cilium that referenced this pull request Jun 4, 2024
[ upstream commit 3a4c57f ]

[ Backporter's notes: switch default to false - so not enabled by
default. Switch from testing package to checkmate in unit tests ]

Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to cilium#32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Added CI test to make sure that we accidentally don't add calls that
modify XFRMState without going through cache.

Also, added hidden option that allows to turn of caching.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
@marseel marseel added the backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. label Jun 4, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Backport done to v1.15 in 1.15.6 Jun 4, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Backport pending to v1.14 in 1.14.12 Jun 4, 2024
marseel added a commit that referenced this pull request Jun 4, 2024
[ upstream commit 3a4c57f ]

[ Backporter's notes: switch default to false - so not enabled by
default. Switch from testing package to checkmate in unit tests. Flags
use Vp instead of vp. Minor conflicts with netlink.XfrmState* calls ]

Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Added CI test to make sure that we accidentally don't add calls that
modify XFRMState without going through cache.

Also, added hidden option that allows to turn of caching.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
marseel added a commit that referenced this pull request Jun 4, 2024
[ upstream commit 3a4c57f ]

[ Backporter's notes: switch default to false - so not enabled by
default. Switch from testing package to checkmate in unit tests. Flags
use Vp instead of vp. Minor conflicts with netlink.XfrmState* calls.
Switched from pkg/time to time ]

Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Added CI test to make sure that we accidentally don't add calls that
modify XFRMState without going through cache.

Also, added hidden option that allows to turn of caching.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
marseel added a commit that referenced this pull request Jun 4, 2024
[ upstream commit 2019ebe ]

[ Backporter's notes: minor conflicts due to lack of context and
closeChan instead. ]

During bootrstrap, we don't know number of nodes and new implementation
essentially was hot looping till fetched nodes. Also, in case of cluster
with single node, rate-limiter was not rate-limiting.

Fixes #32577

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
@marseel marseel added the backport-pending/1.13 The backport for Cilium 1.13.x for this PR is in progress. label Jun 4, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Backport pending to v1.13 in 1.13.17 Jun 4, 2024
marseel added a commit that referenced this pull request Jun 4, 2024
[ upstream commit 3a4c57f ]

[ Backporter's notes: switch default to false - so not enabled by
default. Switch from testing package to checkmate in unit tests. Flags
use Vp instead of vp. Minor conflicts with netlink.XfrmState* calls.
Switched from pkg/time to time. Switch from checkmate to check.v1 ]

Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Added CI test to make sure that we accidentally don't add calls that
modify XFRMState without going through cache.

Also, added hidden option that allows to turn of caching.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
qmonnet pushed a commit that referenced this pull request Jun 5, 2024
[ upstream commit 2019ebe ]

[ Backporter's notes: minor conflicts due to lack of context and
closeChan instead. ]

During bootrstrap, we don't know number of nodes and new implementation
essentially was hot looping till fetched nodes. Also, in case of cluster
with single node, rate-limiter was not rate-limiting.

Fixes #32577

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
@github-actions github-actions bot added backport-done/1.13 The backport for Cilium 1.13.x for this PR is done. and removed backport-pending/1.13 The backport for Cilium 1.13.x for this PR is in progress. labels Jun 5, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.13 to Backport done to v1.13 in 1.13.17 Jun 5, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed this from Backport pending to v1.13 in 1.13.17 Jun 5, 2024
qmonnet pushed a commit that referenced this pull request Jun 5, 2024
[ upstream commit 3a4c57f ]

[ Backporter's notes: switch default to false - so not enabled by
default. Switch from testing package to checkmate in unit tests. Flags
use Vp instead of vp. Minor conflicts with netlink.XfrmState* calls ]

Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Added CI test to make sure that we accidentally don't add calls that
modify XFRMState without going through cache.

Also, added hidden option that allows to turn of caching.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
qmonnet pushed a commit that referenced this pull request Jun 5, 2024
[ upstream commit 3a4c57f ]

[ Backporter's notes: switch default to false - so not enabled by
default. Switch from testing package to checkmate in unit tests ]

Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Added CI test to make sure that we accidentally don't add calls that
modify XFRMState without going through cache.

Also, added hidden option that allows to turn of caching.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
qmonnet pushed a commit that referenced this pull request Jun 5, 2024
[ upstream commit 2019ebe ]

During bootrstrap, we don't know number of nodes and new implementation
essentially was hot looping till fetched nodes. Also, in case of cluster
with single node, rate-limiter was not rate-limiting.

Fixes #32577

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
@github-actions github-actions bot added backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. and removed backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. labels Jun 5, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed this from Backport pending to v1.14 in 1.14.12 Jun 5, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Backport done to v1.14 in 1.14.12 Jun 5, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Backport done to v1.13 in 1.13.17 Jun 5, 2024
michi-covalent pushed a commit that referenced this pull request Jun 5, 2024
[ upstream commit 3a4c57f ]

[ Backporter's notes: switch default to false - so not enabled by
default. Switch from testing package to checkmate in unit tests. Flags
use Vp instead of vp. Minor conflicts with netlink.XfrmState* calls.
Switched from pkg/time to time. Switch from checkmate to check.v1 ]

Reduces GC CPU usage and memory allocations coming from XfrmStateList.
To ensure we have up-to-date cache, wrap all XfrmState related
functions inside cache, which is invalidated whenever XfrmState changes.

This is follow-up to #32577
While that PR averages out CPU usage over time, in large cluster 100+
nodes amount of allocations coming from netlink.XfrmStateList() is high
due to backgroundSync where we usually don't change any Xfrm states.
This becomes more and more expensive as number of nodes increases.

Added CI test to make sure that we accidentally don't add calls that
modify XFRMState without going through cache.

Also, added hidden option that allows to turn of caching.

Signed-off-by: Marcel Zieba <marcel.zieba@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-done/1.13 The backport for Cilium 1.13.x for this PR is done. backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. backport-done/1.15 The backport for Cilium 1.15.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/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
1.13.17
Backport done to v1.13
1.14.12
Backport done to v1.14
1.15.6
Backport done to v1.15
Development

Successfully merging this pull request may close these issues.

None yet

2 participants