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

Use scaleDown parameter to control if only scale up or down #456

Merged
merged 1 commit into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions go/autoscaler/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,21 @@ func scaleDryRun(r *ClusterResource, j job, curDiff int, scaleDown bool) (additi
instanceMax := j.Config.Spec.Trainer.MaxInstance
instanceMin := j.Config.Spec.Trainer.MinInstance

if r.GPULimit > r.GPUTotal || r.CPURequestMilli > r.CPUTotalMilli {
if plannedInstance-1 >= instanceMin {
if scaleDown {
if plannedInstance > instanceMax {
return -1
}

if r.GPULimit > r.GPUTotal || r.CPURequestMilli > r.CPUTotalMilli {
if plannedInstance > instanceMin {
return -1
}

// can not scale down further
return 0
}

// do not try to scale up
return 0
}

Expand Down
7 changes: 6 additions & 1 deletion go/autoscaler/autoscaler_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func TestScaleDryRunMoreGPU(t *testing.T) {
}
j := makeJob("name", "1", "1", "10Mi", "10Mi", "1", 1, 3, 1)
assert.Equal(t, 1, scaleDryRun(&r, j, 0, false))
assert.Equal(t, 0, scaleDryRun(&r, j, 0, true), "should not scale up if the scale down parameter is true")
}

func TestScaleDryRunNoMoreGPU(t *testing.T) {
Expand Down Expand Up @@ -179,7 +180,10 @@ func TestScaleDryRunScaleDownMoreThanExpected(t *testing.T) {
}

j := makeJob("name", "1", "1", "10Mi", "10Mi", "0", 1, 3, 6)
assert.Equal(t, -3, scaleDryRun(&r, j, 0, true))
assert.Equal(t, -1, scaleDryRun(&r, j, 0, true))
assert.Equal(t, -1, scaleDryRun(&r, j, -1, true))
assert.Equal(t, -1, scaleDryRun(&r, j, -2, true))
assert.Equal(t, 0, scaleDryRun(&r, j, -3, true))
}

func TestScaleDryRunScaleDownToMin(t *testing.T) {
Expand Down Expand Up @@ -216,6 +220,7 @@ func TestScaleDryRunScaleDownFullCluster(t *testing.T) {

j := makeJob("name", "1", "1", "10Mi", "10Mi", "0", 1, 3, 3)
assert.Equal(t, -1, scaleDryRun(&r, j, 0, true))
assert.Equal(t, 0, scaleDryRun(&r, j, 0, false), "should not scale down if the scale down parameter is false")
}

func TestScaleDryRunNoMem(t *testing.T) {
Expand Down