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

stop proxy cache asynchronously #3027

Merged
merged 1 commit into from
Jan 10, 2023
Merged

Conversation

ikaven1024
Copy link
Member

Signed-off-by: yingjinhui yingjinhui@didiglobal.com

What type of PR is this?
/kind bug

What this PR does / why we need it:
When a member cluster is down, stopping the proxy cache for this cluster takes a few seconds(as below log, stop the pods cache takes 9s)

I0106 17:25:07.764975   62644 resource_cache.go:35] Stop store for yjh-1 /v1, Resource=pods
I0106 17:25:16.609796   62644 resource_cache.go:35] Stop store for yjh-1 /v1, Resource=nodes

During stopping, it hold the lock of MultiClusterCache. This results in client requests will be blocked. Because request handlers also need this lock:

func (c *MultiClusterCache) List(ctx context.Context, gvr schema.GroupVersionResource, options *metainternalversion.ListOptions) (runtime.Object, error) {
var resultObject runtime.Object
items := make([]runtime.Object, 0, int(math.Min(float64(options.Limit), 1024)))
requestResourceVersion := newMultiClusterResourceVersionFromString(options.ResourceVersion)
requestContinue := newMultiClusterContinueFromString(options.Continue)
clusters := c.getClusterNames()

func (c *MultiClusterCache) getClusterNames() []string {
c.lock.RLock()
defer c.lock.RUnlock()

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

`karmada-search`: avoid proxy request block when member cluster down.

@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Jan 6, 2023
@karmada-bot karmada-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jan 6, 2023
@jwcesign
Copy link
Member

jwcesign commented Jan 9, 2023

How long it takes now?

@XiShanYongYe-Chang
Copy link
Member

Hi @ikaven1024, does this change affect the access of other client requests to the cache resources of the cluster?

I have another question, why not do it here:

https://github.com/karmada-io/karmada/blob/master/pkg/search/proxy/store/multi_cluster_cache.go#L71

@karmada-bot karmada-bot 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 Jan 9, 2023
@ikaven1024
Copy link
Member Author

How long it takes now?

I add logs to measure the spending time:

I0109 12:12:00.792441   87527 multi_cluster_cache.go:64] MultiClusterCache update cache takes 162.416µs

@ikaven1024
Copy link
Member Author

I have another question, why not do it here:

https://github.com/karmada-io/karmada/blob/master/pkg/search/proxy/store/multi_cluster_cache.go#L71

You are right. But when users remove resource from ResourceRegistry also will stop the cache via clusterCache.updateCache. So I move the go to the place Cacher really stopping:

func (c *resourceCache) stop() {
	klog.Infof("Stop store for %s %s", c.clusterName, c.resource)
	go c.Store.DestroyFunc()
}

@jwcesign
Copy link
Member

jwcesign commented Jan 9, 2023

How long it takes now?

I add logs to measure the spending time:

I0109 12:12:00.792441   87527 multi_cluster_cache.go:64] MultiClusterCache update cache takes 162.416µs

Great!
/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 9, 2023
Signed-off-by: yingjinhui <yingjinhui@didiglobal.com>
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 9, 2023
@XiShanYongYe-Chang
Copy link
Member

/approve
Ask for @jwcesign to have a review again.

Hi @ikaven1024, do we need to cherry-pick this path to the previous release?

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: XiShanYongYe-Chang

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 Jan 9, 2023
@jwcesign
Copy link
Member

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2023
@karmada-bot karmada-bot merged commit 7c4d840 into karmada-io:master Jan 10, 2023
@ikaven1024 ikaven1024 deleted the fix-stop branch January 10, 2023 02:35
karmada-bot added a commit that referenced this pull request Jan 10, 2023
…27-upstream-release-1.4

Automated cherry pick of #3027: stop proxy cache asynchronously
karmada-bot added a commit that referenced this pull request Jan 10, 2023
…27-upstream-release-1.3

Automated cherry pick of #3027: stop proxy cache asynchronously
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. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants