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

Share a single etcd3 client logger across all clients #111477

Merged
merged 4 commits into from
Aug 1, 2022

Conversation

negz
Copy link
Contributor

@negz negz commented Jul 27, 2022

What type of PR is this?

/kind bug

What this PR does / why we need it:

Currently the API server creates one etcd client per CRD. If clients aren't provided a logger they'll each create their own. These loggers can account for ~20% of API server memory consumption on a cluster with hundreds of CRDs.

Which issue(s) this PR fixes:

Fixes #111476

Special notes for your reviewer:

With this single logger and ~1,900 CRDs loaded I'm seeing the API server using from 5.5 to 6.5 GiB RSS as garbage collection sawtooths. That's a saving of at least 1GiB.

Profile no longer shows the logger:

profile-with-one-logger

Note that I don't really know how to make this logger actually log anything so it's hard to confirm whether this change has any performance or observability impact.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


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>
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 27, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @negz. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jul 27, 2022
@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 27, 2022
@leilajal
Copy link
Contributor

/cc @apelisse @jpbetz
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jul 28, 2022
@jpbetz
Copy link
Contributor

jpbetz commented Jul 28, 2022

sure how viable completely disabling it is; this PR is intended more to start a discussion and to demonstrate what I did in #111476 to disable the logger

re: viability: Sounds like you're already thinking in this direction-- I'm relatively certain there is information being logged that would be sorely missed by cluster administrators when diagnosing etcd issues.

Any idea what the current log level is and what volume of data was being logged in the 1k+ CRD case?

@negz
Copy link
Contributor Author

negz commented Jul 29, 2022

Any idea what the current log level is and what volume of data was being logged in the 1k+ CRD case?

I don't see anything being logged, but I just have a toy kind cluster with the CRDs loaded and no controllers or real clients. I imagine there might be interesting logs on a real cluster.

Per #111476 (comment) this is almost certainly happening because we have one etcd client (and thus one logger) per CRD installed. I imagine we should probably share a client or pool of clients to etcd, but I'd love to get a fix for this memory usage into 1.25 and I believe the code freeze is days away.

Perhaps a reasonable quick fix for this logger issue would be to create one logger and pass it into all newly created etcd clients?

Currently the API server creates one etcd client per CRD. If clients
aren't provided a logger they'll each create their own. These loggers
can account for ~20% of API server memory consumption on a cluster with
hundreds of CRDs.

Signed-off-by: Nic Cope <nicc@rk0n.org>
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 29, 2022
@negz negz changed the title Disable the etcd3 client logger Share a single etcd3 client logger across all clients Jul 29, 2022
@negz
Copy link
Contributor Author

negz commented Jul 29, 2022

Just pushed a commit and edited the PR description to have clients share one logger rather than each creating their own.

@sttts
Copy link
Contributor

sttts commented Jul 29, 2022

/ok-to-test

@jpbetz
Copy link
Contributor

jpbetz commented Jul 29, 2022

The way the initialization of the default etcd logger is recreated here to have a shared logger looks right to me.
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 29, 2022
@negz
Copy link
Contributor Author

negz commented Jul 29, 2022

/test pull-kubernetes-e2e-kind-ipv6

@negz
Copy link
Contributor Author

negz commented Jul 30, 2022

I'm happy to take a shot at that in a separate PR

Draft started in #111559

@negz
Copy link
Contributor Author

negz commented Aug 1, 2022

I don't think I'll personally be confident enough in #111559 to get it done by the freeze tomorrow. Do folks feel like this one is ready to merge as a stop-gap?

@jqmichael
Copy link
Contributor

Related discussion about one etcd client per API Kind.

https://kubernetes.slack.com/archives/C0EG7JC6T/p1618439560231400

lavalamp
1 year ago
Yeah that sounds like what it currently does. What it should do is make one client per database (recall that you can put different collections in different etcd databases).
@jingyih
might have a patch laying around that fixes this.

@negz
Copy link
Contributor Author

negz commented Aug 1, 2022

What it should do is make one client per database (recall that you can put different collections in different etcd databases).

@jqmichael that sounds similar to what I've done in #111559 - I believe in this case one transport is roughly equivalent to one etcd database?

@lavalamp
Copy link
Member

lavalamp commented Aug 1, 2022

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lavalamp, negz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 1, 2022
@k8s-ci-robot k8s-ci-robot merged commit 59cedf4 into kubernetes:master Aug 1, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.25 milestone Aug 1, 2022
@negz negz deleted the biglogs branch August 2, 2022 20:40
k8s-ci-robot added a commit that referenced this pull request Aug 10, 2022
…-upstream-release-1.22

Automated cherry pick of #111477: Share a single etcd3 client logger across all clients
k8s-ci-robot added a commit that referenced this pull request Aug 10, 2022
…-upstream-release-1.24

Automated cherry pick of #111477: Share a single etcd3 client logger across all clients
k8s-ci-robot added a commit that referenced this pull request Aug 10, 2022
…-upstream-release-1.23

Automated cherry pick of #111477: Share a single etcd3 client logger across all clients
giorio94 added a commit to giorio94/cilium that referenced this pull request Jun 27, 2023
Currently, the etcd client logger is not explicitly configured when a
new etcd client is initialized, which means that a new one gets created
for every client. Yet, this comes with a significant memory cost,
which can be avoided explicitly initializing and configuring a shared
logger. This change mimics a similar one implemented for the kubernetes
apiserver: kubernetes/kubernetes#111477

The following reports the top 3 nodes from the heap pprof profile of an
idle process after initializing 1K etcd clients through `kvstore.NewClient`.

* Without the patch:

Showing nodes accounting for 268.62MB, 88.75% of 302.68MB total
Dropped 124 nodes (cum <= 1.51MB)
Showing top 3 nodes out of 60
      flat  flat%   sum%        cum   cum%
  224.33MB 74.11% 74.11%   224.33MB 74.11%  go.uber.org/zap/zapcore.newCounters
   32.45MB 10.72% 84.83%    32.45MB 10.72%  google.golang.org/grpc/internal/transport.newBufWriter
   11.85MB  3.91% 88.75%    11.85MB  3.91%  bufio.NewReaderSize

* With the patch:

Showing nodes accounting for 65.20MB, 69.19% of 94.23MB total
Showing top 3 nodes out of 137
      flat  flat%   sum%        cum   cum%
   43.62MB 46.29% 46.29%    43.62MB 46.29%  google.golang.org/grpc/internal/transport.newBufWriter
   19.08MB 20.25% 66.54%    19.08MB 20.25%  bufio.NewReaderSize
    2.50MB  2.65% 69.19%        3MB  3.19%  time.NewTimer

Co-authored-by: yougjiahe <yongjiahe@tuputech.com>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
borkmann pushed a commit to cilium/cilium that referenced this pull request Jun 27, 2023
Currently, the etcd client logger is not explicitly configured when a
new etcd client is initialized, which means that a new one gets created
for every client. Yet, this comes with a significant memory cost,
which can be avoided explicitly initializing and configuring a shared
logger. This change mimics a similar one implemented for the kubernetes
apiserver: kubernetes/kubernetes#111477

The following reports the top 3 nodes from the heap pprof profile of an
idle process after initializing 1K etcd clients through `kvstore.NewClient`.

* Without the patch:

Showing nodes accounting for 268.62MB, 88.75% of 302.68MB total
Dropped 124 nodes (cum <= 1.51MB)
Showing top 3 nodes out of 60
      flat  flat%   sum%        cum   cum%
  224.33MB 74.11% 74.11%   224.33MB 74.11%  go.uber.org/zap/zapcore.newCounters
   32.45MB 10.72% 84.83%    32.45MB 10.72%  google.golang.org/grpc/internal/transport.newBufWriter
   11.85MB  3.91% 88.75%    11.85MB  3.91%  bufio.NewReaderSize

* With the patch:

Showing nodes accounting for 65.20MB, 69.19% of 94.23MB total
Showing top 3 nodes out of 137
      flat  flat%   sum%        cum   cum%
   43.62MB 46.29% 46.29%    43.62MB 46.29%  google.golang.org/grpc/internal/transport.newBufWriter
   19.08MB 20.25% 66.54%    19.08MB 20.25%  bufio.NewReaderSize
    2.50MB  2.65% 69.19%        3MB  3.19%  time.NewTimer

Co-authored-by: yougjiahe <yongjiahe@tuputech.com>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

etcd3 client logger uses significant memory with many CRDs
8 participants