Skip to content

Teach Autoscaler about Scale Down Delay - #9565

Merged
knative-prow-robot merged 4 commits into
knative:masterfrom
julz:autoscaledown
Sep 25, 2020
Merged

knative-prow-robot merged 4 commits into
knative:masterfrom
julz:autoscaledown

Conversation

@julz

@julz julz commented Sep 24, 2020 •

Copy link
Copy Markdown
Contributor

Part of #9092.

Add ScaleDownDelay to DeciderSpec and teach Autoscaler how to respect it. At this point this is still a no-op since we never actually set a non-zero ScaleDownDelay (next PR will change that).

Couple things worth commenting on:

  • Although a 1-element scale-down window is almost the same as no window at all, it's not quite the same (because if we run Scale twice in the same interval, which can happen on initial scale-up, we'll pick the largest of the two rather than the most recent), therefore use a zeroDelay when delay is zero. This also makes setting non-zero ScaleDownDelay effectively act as a feature flag for the whole feature, which is nice.

  • The max.TimedWindow package has a slightly different API from the delayer interface introduced here (Record/Current vs Delay). I think that's fine and good because the concept of delay is part of autoscaler, and doesn't make much sense in the more generic aggregation/max package, therefore Im wrapping here to avoid polluting the generic package with concepts from the specific one. This may be a terrible idea though; if anyone hates it happy to change it :) (this is all private anyway though).. Dropped the interfaces \o/.

/assign @markusthoemmes @vagababov

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Sep 24, 2020
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/autoscale labels Sep 24, 2020

@knative-prow-robot knative-prow-robot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@julz: 0 warnings.

Details

In response to this:

Part of #9092.

Add ScaleDownDelay to DeciderSpec and teach Autoscaler how to respect it. At this point this is still a no-op since we never actually set a non-zero ScaleDownDelay (next PR will change that).

Couple things worth commenting on:

  • Although a 1-element scale-down window is almost the same as no window at all, it's not quite the same (because if we run Scale twice in the same interval, which can happen on initial scale-up, we'll pick the largest of the two rather than the most recent), therefore use a zeroDelay when delay is zero. This also makes setting non-zero ScaleDownDelay effectively act as a feature flag for the whole feature, which is nice.

  • The max.TimedWindow package has a slightly different API from the delayer interface introduced here (Record/Current vs Delay). I think that's fine and good because the concept of delay is part of autoscaler, and doesn't make much sense in the more generic aggregation/max package, therefore Im wrapping here to avoid polluting the generic package with concepts from the specific one. This may be a terrible idea though; if anyone hates it happy to change it :) (this is all private anyway though).

/assign @markusthoemmes @vagababov

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 24, 2020
@codecov

codecov Bot commented Sep 24, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #9565 into master will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9565      +/-   ##
==========================================
+ Coverage   88.72%   88.81%   +0.08%     
==========================================
  Files         213      213              
  Lines        9387     9397      +10     
==========================================
+ Hits         8329     8346      +17     
+ Misses        801      794       -7     
  Partials      257      257              
Impacted Files Coverage Δ
pkg/autoscaler/scaling/multiscaler.go 89.74% <ø> (ø)
pkg/autoscaler/scaling/autoscaler.go 97.72% <100.00%> (+1.82%) ⬆️
pkg/reconciler/configuration/configuration.go 87.50% <0.00%> (-1.67%) ⬇️
pkg/activator/net/revision_backends.go 91.40% <0.00%> (ø)
pkg/queue/handler.go 93.75% <0.00%> (+21.87%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 16b680a...e8ca9bc. Read the comment docs.

Comment thread pkg/autoscaler/scaling/autoscaler.go Outdated
ReadyCount() (int, error)
}

type delayer interface {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

probably a comment would help, what and how we delay

Comment thread pkg/autoscaler/scaling/autoscaler.go Outdated
}

type delayer interface {
Delay(now time.Time, value int32) int32

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Delay(now time.Time, value int32) int32
delay(now time.Time, value int32) int32

or we expect external impls?

Comment thread pkg/autoscaler/scaling/autoscaler.go Outdated
Comment on lines +320 to +332
type zeroDelay struct{}

func (zeroDelay) Delay(_ time.Time, v int32) int32 { return v }

// timeWindowDelay delays scale down decisions using a TimeWindow.
type timeWindowDelay struct {
window *max.TimeWindow
}

func (t timeWindowDelay) Delay(now time.Time, v int32) int32 {
t.window.Record(now, v)
return t.window.Current()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can just join those and return v if delay=0.

@julz

julz commented Sep 24, 2020

Copy link
Copy Markdown
Contributor Author

pushed a version that drops the interfaces entirely. @vagababov wdyt?

@knative-metrics-robot

Copy link
Copy Markdown

The following is the coverage report on the affected files.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/autoscaler/scaling/autoscaler.go 97.8% 99.0% 1.2
pkg/autoscaler/scaling/multiscaler.go 92.2% 93.1% 1.0

@vagababov vagababov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm
/hold

Very nice. I'll let Markus look it over too.
At some point we'll need to chop the function into pieces, but obviously not here.

@knative-prow-robot knative-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Sep 24, 2020
Comment thread pkg/autoscaler/scaling/autoscaler.go Outdated
return nil, errors.New("stats reporter must not be nil")
}

delayer := max.NewTimeWindow(tickInterval, tickInterval)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we create this default? Couldn't we pass nil down and then key the usage decision off of this being nil or not? Seems like the default is never used anyway.

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.

yeah good catch - this is an artefact of when I had a different interface for zero rather than the if

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.

done

for i := 0; i < 2; i++ {
pc.readyCount = i
a := newAutoscaler(testNamespace, testRevision, metrics, pc, deciderSpec, context.Background())
a := newAutoscaler(testNamespace, testRevision, metrics, pc, deciderSpec, max.NewTimeWindow(tickInterval, tickInterval), context.Background())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you go by the suggestion above, passing nil here might be better.

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 25, 2020

@markusthoemmes markusthoemmes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 25, 2020
@knative-prow-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: julz, markusthoemmes

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@julz

julz commented Sep 25, 2020

Copy link
Copy Markdown
Contributor Author

/unhold

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 25, 2020
@julz

julz commented Sep 25, 2020

Copy link
Copy Markdown
Contributor Author

/retest

@vagababov

Copy link
Copy Markdown
Contributor

We need to do something about that test.
cc @ZhiminXiang

@knative-test-reporter-robot

Copy link
Copy Markdown

The following jobs failed:

Test name Triggers Retries
pull-knative-serving-unit-tests 0/3

Failed non-flaky tests preventing automatic retry of pull-knative-serving-unit-tests:

pkg/queue.TestHandlerBreakerQueueFull

@julz

julz commented Sep 25, 2020

Copy link
Copy Markdown
Contributor Author

hm cc @vagababov I think that's a new one?

/retest

@vagababov

Copy link
Copy Markdown
Contributor

I'll look at it.

@knative-prow-robot
knative-prow-robot merged commit 886a228 into knative:master Sep 25, 2020
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. area/autoscale cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants