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

[v1.13] Author backport of "Address ipcache startup perfomance regression" #25185

Merged
merged 4 commits into from May 2, 2023

Conversation

bimmlerd
Copy link
Member

Once this PR is merged, you can update the PR labels via:

for pr in 25007; do contrib/backporting/set-labels.py $pr done 1.13; done

or with

make add-labels BRANCH=v1.13 ISSUES=25007

[ upstream commit 6651e89 ]

This patch adds a benchmark for ipcache.Upsert, with the intention of
exercising the logic for named ports. This exposes a performance
regression when upserting many pods, as is the case on agent startup.

The startup regression was due to losing an optimization in 93cd67f,
namely that the named ports bookkeeping is done only once named ports
are present in policies. Without the lazy bookkeeping, we have
accidentally quadratic behavior, as we look at every pod whenever a
new pod is added.

Follow up commits will address the issue, this is merely a convenient
reproduction of the regression.

Suggested-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
[ upstream commit 39cf09b ]

In preparation of introducing reference counting for named ports, change
the NamedPortMultiMap from a concrete type to an interface. This
produces a fair bit of churn in the test code (as it assumes the type is
a map). There are no functional changes, however.

The benefit of having this type be an interface is that we can switch
it's implementing type to use reference counting with a smaller patch.
That, in turn, will allow us to avoid looking at all other pods when a
new pod is added or deleted, just for the named port bookkeeping.

Suggested-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
[ upstream commit 33079de ]

This commit introduces reference counting for named ports. Using the
reference counting, we know when to add or remove named ports in our
bookkeeping, without having to look through all other pods. This leads
to a significant speedup when inserting many pods, as is the case on
agent startup.

Note that this patch does _not_ restore the original optimization of not
keeping track of named ports until used in a policy. We did not find a
good way of doing so while also avoiding re-introducing the deadlock
fixed in the commit referenced below. Instead, we always do the
bookkeeping, but in a more efficient manner.

The reference counting requires the use of a RWLock, since read and
write accesses to a map must be protected. Thus, there is potential for
introducing yet another deadlock. However, we argue that this is not the
case: We do _not_ acquire any other lock while holding our mutex M. A
wait cycle/deadlock involving M must include holding M when acquiring
some other lock, however. Therefore this patch cannot introduce a
deadlock.

Fixes: 93cd67f (ipcache: fix potential deadlock in GetNamedPorts)
Fixes: cilium#24987

Suggested-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
[ upstream commit 191b672 ]

With the reference counting in place, we can simplify the involved code
paths in the ipcache. There is now little point to conditionally perform
the update, as the update itself is about as expensive as checking
whether it is necessary. Therefore, opt for simpler code and always call
into NamedPortMultiMapUpdater.Update.

Indeed, this even gives a mild speedup:

goos: linux
goarch: arm64
pkg: github.com/cilium/cilium/pkg/ipcache
                      │   fix.txt   │            cleanup.txt             │
                      │   sec/op    │   sec/op     vs base               │
IPCacheUpsert10-10      48.84µ ± 5%   47.59µ ± 5%       ~ (p=0.165 n=10)
IPCacheUpsert100-10     508.3µ ± 5%   485.0µ ± 2%  -4.58% (p=0.005 n=10)
IPCacheUpsert1000-10    5.282m ± 5%   5.056m ± 2%  -4.28% (p=0.011 n=10)
IPCacheUpsert10000-10   48.63m ± 5%   44.87m ± 5%  -7.74% (p=0.009 n=10)
geomean                 1.589m        1.513m       -4.81%

Suggested-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
Signed-off-by: David Bimmler <david.bimmler@isovalent.com>
@bimmlerd bimmlerd requested a review from a team as a code owner April 28, 2023 07:51
@bimmlerd bimmlerd added kind/backports This PR provides functionality previously merged into master. backport/1.13 This PR represents a backport for Cilium 1.13.x of a PR that was merged to main. labels Apr 28, 2023
@bimmlerd bimmlerd changed the title v1.13 Backports 2023-04-28 [v1.13] Author backport of #25007 Apr 28, 2023
@bimmlerd
Copy link
Member Author

/test-backport-1.13

@bimmlerd bimmlerd changed the title [v1.13] Author backport of #25007 [v1.13] Author backport of "Address ipcache startup perfomance regression" Apr 28, 2023
@bimmlerd
Copy link
Member Author

bimmlerd commented Apr 28, 2023

/test-1.16-4.19

lots of jenkins failures with

error: rev-list died of signal 15
error: https://github.com/cilium/cilium did not send all necessary objects

error: git-remote-https died of signal 15

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2042)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1761)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$400(CliGitAPIImpl.java:72)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:442)
	at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:892)
	... 8 more
ERROR: Error fetching remote repo 'origin'

@bimmlerd
Copy link
Member Author

/test-1.17-4.19

@bimmlerd
Copy link
Member Author

/test-1.19-4.19

@bimmlerd
Copy link
Member Author

/test-1.20-4.19

@bimmlerd
Copy link
Member Author

/test-1.22-4.19

@bimmlerd
Copy link
Member Author

bimmlerd commented Apr 28, 2023

/ci-gke-1.13

failed with #24251

@ti-mo
Copy link
Contributor

ti-mo commented Apr 28, 2023

/test-runtime

Runtime tests were failing with

11:51:25  	 [09:47:41] FAIL: loader_test.go:159: LoaderTestSuite.TestCompileAndLoadDefaultEndpoint
...
11:51:25  	 [09:47:41] ... value *fmt.wrapError = &fmt.wrapError{msg:"Failed to compile bpf_lxc.o: Command execution failed for [llc -march=bpf -mcpu=v3 -filetype=obj -o /tmp/cilium_1682226187/bpf_lxc.o]: context deadline exceeded", err:(*fmt.wrapError)(0xc0005d6140)} ("Failed to compile bpf_lxc.o: Command execution failed for [llc -march=bpf -mcpu=v3 -filetype=obj -o /tmp/cilium_1682226187/bpf_lxc.o]: context deadline exceeded")

Probably something going on on Jenkins side.

@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 May 2, 2023
@michi-covalent michi-covalent merged commit 097fba3 into cilium:v1.13 May 2, 2023
62 checks passed
@bimmlerd bimmlerd deleted the pr/v1.13-backport-2023-04-28 branch May 2, 2023 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.13 This PR represents a backport for Cilium 1.13.x of a PR that was merged to main. kind/backports This PR provides functionality previously merged into master. ready-to-merge This PR has passed all tests and received consensus from code owners to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants