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

Feat: memory optimization via enhance informer cache #5683

Merged
merged 7 commits into from
Mar 20, 2023

Conversation

Somefive
Copy link
Collaborator

@Somefive Somefive commented Mar 15, 2023

Description of your changes

Apply 3 methods to optimize the memory usage.

  1. Drop managedFields and kubectl.kubernetes.io/last-applied-configuration when storing Application, ApplicationRevision, ResourceTracker in informer. (This only affect the cache, etcd storage not change)
  2. Reduce the memory usage of ApplicationRevision by sharing the storage of ComponentDefinition, TraitDefinition, WorkflowStepDefinition. (Let them use the same pointer if the hash equals)
  3. Disable the informer cache for ConfigMap caused by Workflow Context. (At the cost of slower Workflow Context updates)

Before Optimization
image

After Optimization
image

3k app, 9k apprev, RSS 1.02G(Alloc: 401M, Sys: 897M) -> 739M(Alloc: 203M, Sys: 707M), enhance 25%~30%.

Refactor:

  1. Remove unused flags for optimization.

I have:

  • Read and followed KubeVela's contribution process.
  • Related Docs updated properly. In a new feature or configuration option, an update to the documentation is necessary.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Special notes for your reviewer

@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Patch coverage: 90.38% and project coverage change: -0.18 ⚠️

Comparison is base (b28b165) 61.59% compared to head (1eaa863) 61.42%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5683      +/-   ##
==========================================
- Coverage   61.59%   61.42%   -0.18%     
==========================================
  Files         216      217       +1     
  Lines       30442    30582     +140     
==========================================
+ Hits        18751    18785      +34     
- Misses       9976    10080     +104     
- Partials     1715     1717       +2     
Flag Coverage Δ
core-unittests 55.76% <80.00%> (+0.02%) ⬆️
e2e-multicluster-test 25.85% <88.46%> (+0.19%) ⬆️
e2e-rollout-tests 22.40% <88.46%> (+0.46%) ⬆️
e2etests 27.63% <88.46%> (-0.35%) ⬇️

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

Impacted Files Coverage Δ
pkg/features/controller_features.go 100.00% <ø> (ø)
pkg/workflow/workflow.go 100.00% <ø> (ø)
pkg/cache/informer.go 88.80% <88.80%> (ø)
cmd/core/app/server.go 59.09% <100.00%> (+0.18%) ⬆️
pkg/appfile/parser.go 63.76% <100.00%> (-0.52%) ⬇️
pkg/cache/optimize.go 62.50% <100.00%> (+9.86%) ⬆️
...er/core.oam.dev/v1alpha2/application/dispatcher.go 94.40% <100.00%> (ø)
...ller/core.oam.dev/v1alpha2/application/revision.go 71.48% <100.00%> (-0.88%) ⬇️
pkg/controller/flags.go 100.00% <100.00%> (ø)

... and 10 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Somefive Somefive force-pushed the feat/support-apprev-def-cache branch 7 times, most recently from 4a4fad3 to afc5c8c Compare March 16, 2023 01:52
@Somefive Somefive marked this pull request as ready for review March 16, 2023 02:31
}

// NewClientDisableCacheFor get ClientDisableCacheFor for building controller
func NewClientDisableCacheFor() []client.Object {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func NewClientDisableCacheFor() []client.Object {
func Resources2DisableCache() []client.Object {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is aligned with the naming of controller-runtime manager. See

ClientDisableCacheFor: cache.NewClientDisableCacheFor(),

Copy link
Collaborator

Choose a reason for hiding this comment

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

they're different, the naming is trying to become a sentence:

Client disable cache for "some resources", so the field should be "some resources", not copy-pase the name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

@Somefive Somefive force-pushed the feat/support-apprev-def-cache branch 2 times, most recently from 538c98c to 1a4a5e9 Compare March 16, 2023 03:04
enableInMemoryWorkflowContext: false
disableResourceApplyDoubleCheck: false
enableResourceTrackerDeleteOnlyTrigger: true
informerCache: true
applicationRevisionDefinitionStorage: true
disableWorkflowContextConfigMapCache: true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we provide a new optimize section for these fine-grained cache items?

Suggested change
disableWorkflowContextConfigMapCache: true
disableCacheItems:
disableWorkflowContextConfigMapCache: false

BTW, the parameter name is confusion, it's default to disable the cache or not?

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be

Suggested change
disableWorkflowContextConfigMapCache: true
disableCacheItems:
workflowContextConfigMapCache: false

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to default enabled featuregate

charts/vela-core/values.yaml Outdated Show resolved Hide resolved
@@ -60,6 +62,9 @@ func BuildCache(ctx context.Context, scheme *runtime.Scheme, shardingObjects ...
return nil, err
}
}
if OptimizeInformerCache && OptimizeApplicationRevisionDefinitionStorage {
go DefaultDefinitionCache.Get().Start(ctx, c, ApplicationRevisionDefinitionCachePruneDuration)
Copy link
Collaborator

Choose a reason for hiding this comment

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

does all cache using a go routine? can we align with them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes. all definition cache use one single goroutine.

@Somefive Somefive force-pushed the feat/support-apprev-def-cache branch from a7a2f0a to c28b89d Compare March 16, 2023 04:10
@Somefive Somefive force-pushed the feat/support-apprev-def-cache branch from c28b89d to 6e42ec2 Compare March 17, 2023 09:14
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
Signed-off-by: Somefive <yd219913@alibaba-inc.com>
@Somefive Somefive force-pushed the feat/support-apprev-def-cache branch from 6e42ec2 to 1eaa863 Compare March 17, 2023 09:15
Copy link
Collaborator

@barnettZQG barnettZQG left a comment

Choose a reason for hiding this comment

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

LGTM

@chivalryq chivalryq merged commit 50458bc into kubevela:master Mar 20, 2023
@Somefive Somefive deleted the feat/support-apprev-def-cache branch June 20, 2023 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants