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

keda-metrics-adapter calling apiserver qps are quite high #2914

Closed
bamboo12366 opened this issue Apr 17, 2022 · 7 comments · Fixed by #2922
Closed

keda-metrics-adapter calling apiserver qps are quite high #2914

bamboo12366 opened this issue Apr 17, 2022 · 7 comments · Fixed by #2922
Labels
bug Something isn't working

Comments

@bamboo12366
Copy link
Contributor

Report

we create arounds 200 scaleObjects in the cluster, the qps from keda-metrics-adapter to apiserver is quite high, which create burden to apiserver

image

the code for listing here: https://github.com/kedacore/keda/blob/main/pkg/provider/provider.go#L90

Expected Behavior

Not calling apiserver so frequently, should be done by reconcile by watching constantly

Actual Behavior

Calling apiserver every time the metrics request to get the so resource

Steps to Reproduce the Problem

large amounts of scaleObjectx

Logs from KEDA operator

No response

KEDA Version

2.6.1

Kubernetes Version

1.20

Platform

Other

Scaler Details

No response

Anything else?

  1. maybe we can using the shared informer with scaledObject Controller, when get new so can get directly from informer cache
  2. or create a shared cache between controller and provider

if you guys feel ok either way, I can give a try

@bamboo12366 bamboo12366 added the bug Something isn't working label Apr 17, 2022
@tomkerkhove tomkerkhove moved this to Proposed in Roadmap - KEDA Core Apr 17, 2022
@zroubalik
Copy link
Member

Yeah, this is something that needs improvement, @bamboo12366 would be nice if you can try to tackle this.

FYI there's already controller present in the MetricsAdapter (currently used for metricNames), so you might want to go this direction: https://github.com/kedacore/keda/blob/main/controllers/keda/metrics_adapter_controller.go

@zroubalik
Copy link
Member

zroubalik commented Apr 19, 2022

There might be even an easier solution, replace following section:

// get the scaled objects matching namespace and labels
scaledObjects := &kedav1alpha1.ScaledObjectList{}
opts := []client.ListOption{
client.InNamespace(namespace),
client.MatchingLabels(selector),
}
err = p.client.List(ctx, scaledObjects, opts...)

with

...
	scaledObject := &kedav1alpha1.ScaledObject{}
	p.client.Get(ctx, namespaceNameParsedFromMetricSelector, scaledObject)
...

we should be able to parse ScaledObject.Name from a label scaledobject.keda.sh/name that is set on ScaledObject and most likely is part of the metricSelector.

It's definitely worth exploring.

@bamboo12366
Copy link
Contributor Author

bamboo12366 commented Apr 19, 2022

hey @zroubalik

can I just using the manager.GetClient() and pass the client to the provider, thus the provider and scaledObject Controller are sharing the same informer cache together

the code will be like
https://github.com/kedacore/keda/blob/main/adapter/main.go#L119-L123

with

        mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
		Scheme:    scheme,
		Namespace: namespace,
	})
	if err != nil {
		return nil, nil, err
	}
	if err := runScaledObjectController(ctx, mgr, handler, logger, externalMetricsInfo, externalMetricsInfoLock, maxConcurrentReconciles, stopCh); err != nil {
		return nil, nil, err
	}
	
	return kedaprovider.NewProvider(ctx, logger, handler, mgr.GetClient(), namespace, externalMetricsInfo, externalMetricsInfoLock), stopCh, nil

@zroubalik
Copy link
Member

ScaledObject controller is running in KEDA Operator Pod, Provider in Metrics Server Pod.

@zroubalik
Copy link
Member

The client for Metrics Server (thus provider) is setup here: https://github.com/kedacore/keda/blob/main/adapter/main.go

I happy to see any improvements on this side.

@bamboo12366
Copy link
Contributor Author

yea, what trouble me is the Metrics Server pare.
I will create a PR work on this

@bamboo12366
Copy link
Contributor Author

@zroubalik master, could you help me review on this #2922?

Repository owner moved this from Proposed to Ready To Ship in Roadmap - KEDA Core May 2, 2022
@tomkerkhove tomkerkhove moved this from Ready To Ship to Done in Roadmap - KEDA Core Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants