Skip to content

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

Merged
zroubalik merged 7 commits into
kedacore:mainfrom
coderanger:less-scale-get
Jan 6, 2021
Merged

For scaling deployments in particular, use a direct object get rather than the /scale API#1458
zroubalik merged 7 commits into
kedacore:mainfrom
coderanger:less-scale-get

Conversation

@coderanger
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread pkg/scaling/executor/scale_scaledobjects.go Outdated
Also adds support for StatefulSets for symmetry.

Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
Comment thread pkg/scaling/executor/scale_scaledobjects.go Outdated
Comment thread pkg/scaling/executor/scale_scaledobjects.go Outdated
Comment thread pkg/scaling/executor/scale_scaledobjects.go Outdated
Comment thread pkg/scaling/executor/scale_scaledobjects.go Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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