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

For scaling deployments in particular, use a direct object get rather than the /scale API #1458

Merged
merged 7 commits into from
Jan 6, 2021

Conversation

coderanger
Copy link
Contributor

@coderanger coderanger commented Dec 28, 2020

So that it can use the informer cache for better performance.

This is annoying as a special case but is so common and improves performance so much that I think it's worthwhile to include. Another option would be to majorly increase the QPS rate limit on the scaling API client however that would also increase kube-apiserver load while watches/informers are generally much less impactful.

Checklist

Refs #1449

… than the /scale API so that it can use the informer cache for better performance.

This is annoying as a special case but is so common and improves performance so much that I think it's worthwhile to include. Another option would be to majorly increase the QPS rate limit on the scaling API client however that would also increase kube-apiserver load while watches/informers are generally much less impactful.

Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

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

Looking good, just a minor nit.

pkg/scaling/executor/scale_scaledobjects.go Outdated Show resolved Hide resolved
Also adds support for StatefulSets for symmetry.

Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
pkg/scaling/executor/scale_scaledobjects.go Outdated Show resolved Hide resolved
pkg/scaling/executor/scale_scaledobjects.go Outdated Show resolved Hide resolved
pkg/scaling/executor/scale_scaledobjects.go Outdated Show resolved Hide resolved
pkg/scaling/executor/scale_scaledobjects.go Outdated Show resolved Hide resolved
switch {
case targetGVKR.Group == "apps" && targetGVKR.Kind == "Deployment":
deployment := &appsv1.Deployment{}
err := e.client.Get(ctx, client.ObjectKey{Name: targetGVKR.Resource, Namespace: scaledObject.Namespace}, deployment)
Copy link
Member

Choose a reason for hiding this comment

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

targetName := scaledObject.Spec.ScaleTargetRef.Name

...

Suggested change
err := e.client.Get(ctx, client.ObjectKey{Name: targetGVKR.Resource, Namespace: scaledObject.Namespace}, deployment)
err := e.client.Get(ctx, client.ObjectKey{Name: targetName, Namespace: scaledObject.Namespace}, deployment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems weird to use different data sources, increased chance of them being out of sync?

Copy link
Member

@zroubalik zroubalik Jan 6, 2021

Choose a reason for hiding this comment

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

ScaledObject and the target workload should be always in the sync (the same namespace, if you are asking for this). But in your original code, I don't understand the intention, how do you want to guess the name from targetGVKR.Resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I completely misunderstood this code, you are correct :)

currentReplicas = *deployment.Spec.Replicas
case targetGVKR.Group == "apps" && targetGVKR.Kind == "StatefulSet":
statefulSet := &appsv1.StatefulSet{}
err := e.client.Get(ctx, client.ObjectKey{Name: targetGVKR.Resource, Namespace: scaledObject.Namespace}, statefulSet)
Copy link
Member

Choose a reason for hiding this comment

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

targetName := scaledObject.Spec.ScaleTargetRef.Name

...

Suggested change
err := e.client.Get(ctx, client.ObjectKey{Name: targetGVKR.Resource, Namespace: scaledObject.Namespace}, statefulSet)
err := e.client.Get(ctx, client.ObjectKey{Name: targetName, Namespace: scaledObject.Namespace}, statefulSet)

Co-authored-by: Zbynek Roubalik <726523+zroubalik@users.noreply.github.com>

Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
Co-authored-by: Zbynek Roubalik <726523+zroubalik@users.noreply.github.com>

Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
@zroubalik zroubalik merged commit 68a479c into kedacore:main Jan 6, 2021
ycabrer pushed a commit to ycabrer/keda that referenced this pull request Mar 1, 2021
… than the /scale API (kedacore#1458)

* For scaling deployments in particular, use a direct object get rather than the /scale API so that it can use the informer cache for better performance.

This is annoying as a special case but is so common and improves performance so much that I think it's worthwhile to include. Another option would be to majorly increase the QPS rate limit on the scaling API client however that would also increase kube-apiserver load while watches/informers are generally much less impactful.

Signed-off-by: Noah Kantrowitz <noah@coderanger.net>

* Update changelog.

Signed-off-by: Noah Kantrowitz <noah@coderanger.net>

* Use the already-normalized GVKR data so less weird string parsing.

Also adds support for StatefulSets for symmetry.

Signed-off-by: Noah Kantrowitz <noah@coderanger.net>

* Apply suggestions from code review

Co-authored-by: Zbynek Roubalik <726523+zroubalik@users.noreply.github.com>

Signed-off-by: Noah Kantrowitz <noah@coderanger.net>

* Apply suggestions from code review

Co-authored-by: Zbynek Roubalik <726523+zroubalik@users.noreply.github.com>

Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
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.

2 participants