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

karmada-metrics-adapter: reduce memory usage #4796

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

chaunceyjiang
Copy link
Member

@chaunceyjiang chaunceyjiang commented Apr 3, 2024

When there is a large amount of pod usage in the member cluster, metrics-adapter will consume a lot of memory. The reason is that it caches all the information of all pods in the cluster. However, we don't need all this information, so we trim some of the information to reduce memory usage.

What type of PR is this?
/kind bug

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

The core idea of this PR is to use TransformFunc to trim the fields that pod and node need to buffer. Currently, it only retains fields such as name, namespace, labels, etc. Other fields are not needed, so we do not need to cache them.

Does this PR introduce a user-facing change?:

karmada-metrics-adapter: reduce memory usage

@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Apr 3, 2024
@karmada-bot karmada-bot requested review from jwcesign and Poor12 April 3, 2024 02:41
@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 3, 2024
@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 3, 2024
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

Good Job!

pkg/metricsadapter/controller.go Outdated Show resolved Hide resolved
pkg/metricsadapter/controller.go Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Apr 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.76%. Comparing base (57c1989) to head (1186588).
Report is 20 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4796      +/-   ##
==========================================
- Coverage   51.78%   51.76%   -0.02%     
==========================================
  Files         250      250              
  Lines       24989    24980       -9     
==========================================
- Hits        12940    12931       -9     
+ Misses      11340    11339       -1     
- Partials      709      710       +1     
Flag Coverage Δ
unittests 51.76% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chaunceyjiang chaunceyjiang force-pushed the pods branch 3 times, most recently from 23bdd83 to d60be38 Compare April 3, 2024 04:37
When there is a large amount of pod usage in the member cluster, metrics-adapter will consume a lot of memory. The reason is that it caches all the information of all pods in the cluster. However, we don't need all this information, so we trim some of the information to reduce memory usage.

Signed-off-by: chaunceyjiang <[email protected]>
@chaosi-zju
Copy link
Member

chaosi-zju commented Apr 3, 2024

We have tested on such environment: 2 member clusters, each cluster have 500 node, 10000 pod in all.

before this PR introduced: karmada-metrics-adapter cost 1.3GB memory at least (and may probabilistically rise), memory overhead is mainly due to the line _ = sci.Lister(provider.PodsGVR).

after this PR introduced: only cost about 300MB.

This is a significant performance optimization ! ٩(๑❛ᴗ❛๑)۶

@chaosi-zju
Copy link
Member

Now, can you add more explaination in PR description to summarize how does this PR works to reduce the memory?

You only said you trimmed some of the information, may be you can explain more about why typedmanager is better than genericmanager, or other summary terms.

@chaosi-zju
Copy link
Member

/LGTM

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 3, 2024
@XiShanYongYe-Chang
Copy link
Member

It's probably more of a feature.
/kind feature
/lgtm

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Apr 3, 2024
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/approve
Great work!

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 3, 2024
@karmada-bot karmada-bot merged commit b0da31a into karmada-io:master Apr 3, 2024
12 checks passed
@chaunceyjiang chaunceyjiang deleted the pods branch April 7, 2024 02:06
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. kind/bug Categorizes issue or PR as related to a bug. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants