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

Fix session JobOrderFn to be predictable #3960

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions pkg/scheduler/framework/session_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package framework

import (
"k8s.io/klog/v2"
k8sframework "k8s.io/kubernetes/pkg/scheduler/framework"

"volcano.sh/apis/pkg/apis/scheduling"
Expand Down Expand Up @@ -538,12 +539,15 @@ func (ssn *Session) JobOrderFn(l, r interface{}) bool {
}
}

// If no job order funcs, order job by CreationTimestamp first, then by UID.
// If no job order funcs, order job by CreationTimestamp first, then by Name.
lv := l.(*api.JobInfo)
rv := r.(*api.JobInfo)
if lv.CreationTimestamp.Equal(&rv.CreationTimestamp) {
return lv.UID < rv.UID
// Use the Name of the Job instead of UID to get deterministic order by Job name
klog.V(3).Infof("Creation timestamps are the same for job %v and %v: %v . using name to order", lv.Name, rv.Name, lv.CreationTimestamp)
return lv.Name < rv.Name
Copy link
Member

Choose a reason for hiding this comment

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

If we encounter a situation where vcjobs have the same name but are in different namespaces, will the JobOrder still not return a consistent list order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. So Job Names are namespaced?

}
klog.V(3).Infof("Using creationTimestamp to order job priority %v: %v -- %v: %v ", lv.Name, lv.CreationTimestamp, rv.Name, rv.CreationTimestamp)
return lv.CreationTimestamp.Before(&rv.CreationTimestamp)
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/scheduler/util/scheduler_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ func SortNodes(nodeScores map[float64][]*api.NodeInfo) []*api.NodeInfo {
sort.Sort(sort.Reverse(sort.Float64Slice(keys)))
for _, key := range keys {
nodes := nodeScores[key]
// if the scores are the same, sort the nodes in predictable order using their names
// this is to avoid randomness in scheduling when scores are the same
if len(nodes) > 1 {
sort.Slice(nodes, func(i, j int) bool {
return nodes[i].Name < nodes[j].Name
})
klog.V(3).Infof("nodes with same score %v found. ordered nodes by name: %v", key, nodes)
}
nodesInorder = append(nodesInorder, nodes...)
}
return nodesInorder
Expand Down
Loading