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

Implementing predicates ordering #57168

Merged
merged 2 commits into from Dec 20, 2017

Conversation

yastij
Copy link
Member

@yastij yastij commented Dec 14, 2017

What this PR does / why we need it: implements predicates ordering for the scheduler

Which issue(s) this PR fixes : Fixes #53812

Special notes for your reviewer:

@bsalamat @gmarek @resouer as discussed on slack, to implement ordering we have to choices:

  • use a layered approach with a list that indexes the order of the predicates map

  • change the underlying data structure used to represent a collection of predicates (a map in our case) into a list of predicates objects.
    Going with this solution might be "cleaner" but it will require a lot of changes and will increase the cost for accessing predicates from O(1) to O(n) (n being the number of predicates used by the scheduler).

we might go with this solution for now. If the number of predicates start growing, we might switch to the second option.

Release note:

adding predicates ordering for the kubernetes scheduler.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 14, 2017
@yastij
Copy link
Member Author

yastij commented Dec 14, 2017

/assign @bsalamat @gmarek @resouer

Copy link
Member

@bsalamat bsalamat left a comment

Choose a reason for hiding this comment

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

Thanks, @yastij

}
for _, predicateKey := range predicates.getPredicatesOrdering() {
//TODO (yastij) : compute average predicate restrictiveness to export it as promethus metric
if predicate := predicateFuncs[predicateKey]; predicate != nil {
Copy link
Member

Choose a reason for hiding this comment

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

You should also check if the key exists in the map.

Copy link
Member Author

Choose a reason for hiding this comment

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

yup i'll check the returned bool instead.

@@ -79,6 +79,16 @@ const (
// For example:
// https://github.com/kubernetes/kubernetes/blob/36a218e/plugin/pkg/scheduler/factory/factory.go#L422

var (
predicatesOrdering = []string{"CheckNodeCondition",
Copy link
Member

Choose a reason for hiding this comment

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

It would be great to use constants instead of string literals here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that is the plan.

@@ -79,6 +79,16 @@ const (
// For example:
// https://github.com/kubernetes/kubernetes/blob/36a218e/plugin/pkg/scheduler/factory/factory.go#L422

var (
predicatesOrdering = []string{"CheckNodeCondition",
Copy link
Member

Choose a reason for hiding this comment

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

We should also add a comment that this list must be updated when new predicates are added.

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed

@yastij
Copy link
Member Author

yastij commented Dec 14, 2017

@bsalamat thanks for the review, updated this PR.

@yastij yastij changed the title WIP: Implementing predicates ordering Implementing predicates ordering Dec 14, 2017
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 14, 2017
@dims
Copy link
Member

dims commented Dec 14, 2017

/ok-to-test

@yastij i have triggered the tests ... you probably should squash the commits

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 14, 2017
@yastij
Copy link
Member Author

yastij commented Dec 14, 2017

@dims - can you add it to the 1.10 milestone ?

@dims
Copy link
Member

dims commented Dec 14, 2017

@yastij i don't have enough karma to do that :) but you should be good. the milestones kick on only late in the cycle. so stuff that is not marked but that have /lgtm and /approve without any milestones will still merge in master

@yastij
Copy link
Member Author

yastij commented Dec 14, 2017

@bsalamat - some tests might fail, maybe we should add a way to append a predicate name for test purpose ?

@bsalamat
Copy link
Member

@yastij It is fine to add a way for tests to add their predicates.

@yastij
Copy link
Member Author

yastij commented Dec 14, 2017

SGTM

@resouer
Copy link
Contributor

resouer commented Dec 15, 2017

@yastij I think you can discuss this during sig-scheduling meeting to see if it's a proper candidate for 1.10 release

@bsalamat
Copy link
Member

/sig scheduling

@k8s-ci-robot k8s-ci-robot added the sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. label Dec 15, 2017
@yastij
Copy link
Member Author

yastij commented Dec 16, 2017

@resouer - I'll be there to discuss this + some other items

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 16, 2017
@bsalamat
Copy link
Member

/lgtm

Thanks, @yastij!

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 19, 2017
@yastij
Copy link
Member Author

yastij commented Dec 19, 2017

/retest

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@resouer
Copy link
Contributor

resouer commented Dec 19, 2017

The test failure should be related, I will help to look at it later today

@yastij
Copy link
Member Author

yastij commented Dec 19, 2017

@resouer - can you undo the lgtm to avoid spam by the bot ?

@resouer
Copy link
Contributor

resouer commented Dec 19, 2017

/lgtm cancel

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 19, 2017
@yastij
Copy link
Member Author

yastij commented Dec 20, 2017

@resouer - the only way I can think of is to expose ordering through policy file, otherwise we have to hardcode ordering in our code. But as said @bsalamat we might want to wait and get feedback before doing it

@bsalamat
Copy link
Member

@resouer - the only way I can think of is to expose ordering through policy file, otherwise we have to hardcode ordering in our code. But as said @bsalamat we might want to wait and get feedback before doing it

Making the ordering configurable is certainly possible, but as we had discussed in the past, it may have limited usage. We should wait and see if there is any request to add the feature.

@resouer
Copy link
Contributor

resouer commented Dec 20, 2017

Slack talked with @yastij , the CI failure has been captured and will be fixed soon, really appreciate his effort!

@yastij
Copy link
Member Author

yastij commented Dec 20, 2017

@resouer @bsalamat - CI all green, ready to ship. Thanks everyone !

@dims
Copy link
Member

dims commented Dec 20, 2017

reapplying lgtm

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 20, 2017
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bsalamat, dims, yastij

Associated issue: #53812

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

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 57252, 57168). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 51fbd6e into kubernetes:master Dec 20, 2017
@yastij yastij deleted the predicates-ordering branch January 11, 2018 18:24
k8s-github-robot pushed a commit that referenced this pull request May 25, 2018
Automatic merge from submit-queue (batch tested with PRs 61963, 64279, 64130, 64125, 64049). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix TestSchedulerWithVolumeBinding to avoid setting predicate ordering.

It is causing data race condition as predicate ordering is changing global
variable `predicatesOrdering`. Infact this test does not require any special
predicate order and should work on default predicate ordering as far as
VolumeScheduling feature is enabled.

See these logs:

```
==================
==================
WARNING: DATA RACE
Read at 0x00c420894180 by goroutine 156:
  k8s.io/kubernetes/pkg/scheduler/core.podFitsOnNode()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/pkg/scheduler/core/generic_scheduler.go:503 +0xbb
  k8s.io/kubernetes/pkg/scheduler/core.(*genericScheduler).findNodesThatFit.func1()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/pkg/scheduler/core/generic_scheduler.go:353 +0x2f0
  k8s.io/kubernetes/vendor/k8s.io/client-go/util/workqueue.Parallelize.func1()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/vendor/k8s.io/client-go/util/workqueue/parallelizer.go:47 +0xa3

Previous write at 0x00c420894180 by goroutine 186:
  k8s.io/kubernetes/pkg/scheduler.TestSchedulerWithVolumeBinding()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/pkg/scheduler/scheduler_test.go:663 +0x71
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:777 +0x16d

Goroutine 156 (running) created at:
  k8s.io/kubernetes/vendor/k8s.io/client-go/util/workqueue.Parallelize()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/vendor/k8s.io/client-go/util/workqueue/parallelizer.go:43 +0x139
  k8s.io/kubernetes/pkg/scheduler/core.(*genericScheduler).findNodesThatFit()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/pkg/scheduler/core/generic_scheduler.go:378 +0xe8a
  k8s.io/kubernetes/pkg/scheduler/core.(*genericScheduler).Schedule()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/pkg/scheduler/core/generic_scheduler.go:131 +0x385
  k8s.io/kubernetes/pkg/scheduler.(*Scheduler).schedule()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/pkg/scheduler/scheduler.go:192 +0xcd
  k8s.io/kubernetes/pkg/scheduler.(*Scheduler).scheduleOne()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/pkg/scheduler/scheduler.go:447 +0x598
  k8s.io/kubernetes/pkg/scheduler.(*Scheduler).(k8s.io/kubernetes/pkg/scheduler.scheduleOne)-fm()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/pkg/scheduler/scheduler.go:182 +0x41
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil.func1()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:133 +0x61
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:134 +0xcd
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.Until()
      /home/avagarwa/upstream-code/gocode/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:88 +0x5a

Goroutine 186 (running) created at:
  testing.(*T).Run()
      /usr/lib/golang/src/testing/testing.go:824 +0x564
  testing.runTests.func1()
      /usr/lib/golang/src/testing/testing.go:1063 +0xa4
  testing.tRunner()
      /usr/lib/golang/src/testing/testing.go:777 +0x16d
  testing.runTests()
      /usr/lib/golang/src/testing/testing.go:1061 +0x4e1
  testing.(*M).Run()
      /usr/lib/golang/src/testing/testing.go:978 +0x2cd
  main.main()
      _testmain.go:52 +0x22a
==================
--- FAIL: TestSchedulerWithVolumeBinding (18.04s)
	testing.go:730: race detected during execution of test
FAIL
```

It is pretty easy to reproduce this race by following these steps:

```
cd pkg/scheduler
go test -c -race
stress -p 100 ./scheduler.test
```

Predicate ordering to this unit test was added here: #57168
Since the whole scheduler instance uses just one ordering at time, not sure what is the advantage. 

@kubernetes/sig-scheduling-bugs @bsalamat @k82cn @frobware @smarterclayton @sjenning 

```release-note
None
```
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. 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.

Implement predicate ordering for the kubernetes scheduler
8 participants