-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
etcd3 client logger uses significant memory with many CRDs #111476
Comments
|
/sig api-machinery |
This logger is responsible for 20% of the API server's memory usage when many CRDs are installed. See the below issue for more context. kubernetes#111476 Signed-off-by: Nic Cope <nicc@rk0n.org>
|
Since you looked at the code, and I'd rather not spend time doing that. Any chance you can tell if it's because it's being mis-used? |
|
This is a scale dimension where the apiserver has historically scaled poorly. With the OpenAPI discovery performance being improved it looks like this might be a hint at what the next bottleneck might be? Any idea how many etcd clients were instantiated? I suspect it's quite a lot. |
Sadly I didn't yet look deeply past turning it off. I was slightly optimistic that we might just be able to disable it without any meaningful impact. What I do know is that the offending code seems to be on the etcd3 client end - i.e. it defaults to creating its own logger when one isn't supplied. You can see that code at https://github.com/etcd-io/etcd/blob/v3.5.4/client/pkg/logutil/zap.go#L24. |
I don't - will try to find out. |
The zap logs might tell you if you have the data. If my memory of the code is right, you should get 1 etcd client per CRD right now (plus some for builtin types). |
|
/triage accepted |
Based on my read of the code, you're right. I see roughly:
I'm experiencing technical difficulties getting lsof running in my kind container but /proc/pid/net confirms we have a connection to etcd per CRD: $ k get crd|wc -l
1878
$ docker exec -it e092b6d27bf-withlogger-control-plane bash
root@e092b6d27bf-withlogger-control-plane:/# ps -C kube-apiserver
PID TTY TIME CMD
493 ? 00:29:03 kube-apiserver
# With the 1,878 CRDs loaded
# Column 3 is the remote host and port per https://www.kernel.org/doc/Documentation/networking/proc_net_tcp.txt
# 0100007F:094B is hex for 127.0.0.1:2379 (the etcd client port)
root@e092b6d27bf-withlogger-control-plane:/# cat /proc/493/net/tcp|awk '{ print $3 }'|grep '0100007F:094B'|wc -l
1937
# After running kubectl delete crds --all
root@e092b6d27bf-withlogger-control-plane:/# cat /proc/493/net/tcp|awk '{ print $3 }'|grep '0100007F:094B'|wc -l
60Note that 1,937 - 60 = 1,877 - the number of CRDs we have loaded (the 1,878 above includes the header line). |
This logger is responsible for 20% of the API server's memory usage when many CRDs are installed. See the below issue for more context. kubernetes/kubernetes#111476 Signed-off-by: Nic Cope <nicc@rk0n.org> Kubernetes-commit: 0e5401c93940126beac45264aa056507b0950075
This logger is responsible for 20% of the API server's memory usage when many CRDs are installed. See the below issue for more context. kubernetes#111476 Signed-off-by: Nic Cope <nicc@rk0n.org>
This logger is responsible for 20% of the API server's memory usage when many CRDs are installed. See the below issue for more context. kubernetes#111476 Signed-off-by: Nic Cope <nicc@rk0n.org>
This logger is responsible for 20% of the API server's memory usage when many CRDs are installed. See the below issue for more context. kubernetes#111476 Signed-off-by: Nic Cope <nicc@rk0n.org>
This logger is responsible for 20% of the API server's memory usage when many CRDs are installed. See the below issue for more context. kubernetes/kubernetes#111476 Signed-off-by: Nic Cope <nicc@rk0n.org> Kubernetes-commit: 6204b37b180f597840d5cdf687ab5411cac6ee3c
This logger is responsible for 20% of the API server's memory usage when many CRDs are installed. See the below issue for more context. kubernetes/kubernetes#111476 Signed-off-by: Nic Cope <nicc@rk0n.org> Kubernetes-commit: 9a60b0c5f4b50bf63c21af27bd379394ddee4413
This logger is responsible for 20% of the API server's memory usage when many CRDs are installed. See the below issue for more context. kubernetes/kubernetes#111476 Signed-off-by: Nic Cope <nicc@rk0n.org> Kubernetes-commit: c1c18295893282ae32e7be0d09f607680241712f
What happened?
The @crossplane project uses a lot of CRDs - in some cases almost 2,000. I do mean
kind: CustomResourceDefinitionhere, not custom resources. We've noticed that API server memory consumption balloons when many CRDs are installed - for example with ~1,900 CRDs we see the API server using up to ~8Gi RSS.A little profiling shows that around 1.5Gi of that memory is being used by the etcd3 client's logger.
With the Logger
With Kubernetes built from e092b6d with the CRDs at https://github.com/negz/crossplane-scale/tree/dc25bef/etoomanycrds/latest-crds loaded I'm seeing the API server using up to ~7.5GiB RSS. I see it dip to ~5.5GiB, presumably when garbage collection runs.
You can see
zapCore.newCounterstaking up a ton of memory below. Zap is the logger used by the etcd client. Note that this is a sample, so it's actually using more than the indicated ~800MiB.Without the Logger
I'm seeing the API server using up to ~6GiB RSS. I see it dip to ~4.5GiB, presumably due to GC runs.
You can see
zapCore.newCountersno longer appears below.What did you expect to happen?
I would not expect a logger to be responsible for such a significant amount of the API server's memory consumption.
How can we reproduce it (as minimally and precisely as possible)?
You can get the above profile by:
kind build node-image .to build a kind node.kind create cluster --image kindest/node:latestto start a control plane for the above build.kubectl apply -f https://raw.githubusercontent.com/negz/crossplane-scale/dc25bef/profile.yamlto allow anonymous pprof accesskubectl apply -fthe CRDs from https://github.com/negz/crossplane-scale/tree/dc25bef/etoomanycrds/latest-crdsgo tool pprof -png https+insecure://localhost:$(kind get kubeconfig|grep server|cut -d: -f4)/debug/pprof/heapI used https://github.com/nicolargo/glances to see the RSS but I imagine
topwould show it too. See #111477 for details on how I disabled the logger to get the "without logger" numbers.Anything else we need to know?
No response
Kubernetes version
v1.25.0-alpha.3.190+e092b6d27bff00Cloud provider
OS version
Install tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, ...) and versions (if applicable)
The text was updated successfully, but these errors were encountered: