Navigation Menu

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

scheduler: Tasks with a desired state < RUNNING should count #1980

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion manager/scheduler/constraint_test.go
Expand Up @@ -55,7 +55,7 @@ func setupEnv() {
},
},
Tasks: make(map[string]*api.Task),
DesiredRunningTasksCountByService: make(map[string]int),
ActiveTasksCountByService: make(map[string]int),
}
}

Expand Down
38 changes: 19 additions & 19 deletions manager/scheduler/nodeinfo.go
Expand Up @@ -11,10 +11,10 @@ import (
// NodeInfo contains a node and some additional metadata.
type NodeInfo struct {
*api.Node
Tasks map[string]*api.Task
DesiredRunningTasksCount int
DesiredRunningTasksCountByService map[string]int
AvailableResources api.Resources
Tasks map[string]*api.Task
ActiveTasksCount int
ActiveTasksCountByService map[string]int
AvailableResources api.Resources

// recentFailures is a map from service ID to the timestamps of the
// most recent failures the node has experienced from replicas of that
Expand All @@ -28,9 +28,9 @@ func newNodeInfo(n *api.Node, tasks map[string]*api.Task, availableResources api
nodeInfo := NodeInfo{
Node: n,
Tasks: make(map[string]*api.Task),
DesiredRunningTasksCountByService: make(map[string]int),
AvailableResources: availableResources,
recentFailures: make(map[string][]time.Time),
ActiveTasksCountByService: make(map[string]int),
AvailableResources: availableResources,
recentFailures: make(map[string][]time.Time),
}

for _, t := range tasks {
Expand All @@ -48,9 +48,9 @@ func (nodeInfo *NodeInfo) removeTask(t *api.Task) bool {
}

delete(nodeInfo.Tasks, t.ID)
if oldTask.DesiredState == api.TaskStateRunning {
nodeInfo.DesiredRunningTasksCount--
nodeInfo.DesiredRunningTasksCountByService[t.ServiceID]--
if oldTask.DesiredState <= api.TaskStateRunning {
nodeInfo.ActiveTasksCount--
nodeInfo.ActiveTasksCountByService[t.ServiceID]--
}

reservations := taskReservations(t.Spec)
Expand All @@ -65,15 +65,15 @@ func (nodeInfo *NodeInfo) removeTask(t *api.Task) bool {
func (nodeInfo *NodeInfo) addTask(t *api.Task) bool {
oldTask, ok := nodeInfo.Tasks[t.ID]
if ok {
if t.DesiredState == api.TaskStateRunning && oldTask.DesiredState != api.TaskStateRunning {
if t.DesiredState <= api.TaskStateRunning && oldTask.DesiredState > api.TaskStateRunning {
nodeInfo.Tasks[t.ID] = t
nodeInfo.DesiredRunningTasksCount++
nodeInfo.DesiredRunningTasksCountByService[t.ServiceID]++
nodeInfo.ActiveTasksCount++
nodeInfo.ActiveTasksCountByService[t.ServiceID]++
return true
} else if t.DesiredState != api.TaskStateRunning && oldTask.DesiredState == api.TaskStateRunning {
} else if t.DesiredState > api.TaskStateRunning && oldTask.DesiredState <= api.TaskStateRunning {
nodeInfo.Tasks[t.ID] = t
nodeInfo.DesiredRunningTasksCount--
nodeInfo.DesiredRunningTasksCountByService[t.ServiceID]--
nodeInfo.ActiveTasksCount--
nodeInfo.ActiveTasksCountByService[t.ServiceID]--
return true
}
return false
Expand All @@ -84,9 +84,9 @@ func (nodeInfo *NodeInfo) addTask(t *api.Task) bool {
nodeInfo.AvailableResources.MemoryBytes -= reservations.MemoryBytes
nodeInfo.AvailableResources.NanoCPUs -= reservations.NanoCPUs

if t.DesiredState == api.TaskStateRunning {
nodeInfo.DesiredRunningTasksCount++
nodeInfo.DesiredRunningTasksCountByService[t.ServiceID]++
if t.DesiredState <= api.TaskStateRunning {
nodeInfo.ActiveTasksCount++
nodeInfo.ActiveTasksCountByService[t.ServiceID]++
}

return true
Expand Down
8 changes: 4 additions & 4 deletions manager/scheduler/nodeset.go
Expand Up @@ -35,8 +35,8 @@ func (ns *nodeSet) addOrUpdateNode(n NodeInfo) {
if n.Tasks == nil {
n.Tasks = make(map[string]*api.Task)
}
if n.DesiredRunningTasksCountByService == nil {
n.DesiredRunningTasksCountByService = make(map[string]int)
if n.ActiveTasksCountByService == nil {
n.ActiveTasksCountByService = make(map[string]int)
}
if n.recentFailures == nil {
n.recentFailures = make(map[string][]time.Time)
Expand Down Expand Up @@ -96,8 +96,8 @@ func (ns *nodeSet) tree(serviceID string, preferences []*api.PlacementPreference
// sure that the tree structure is not affected by
// which properties nodes have and don't have.

if node.DesiredRunningTasksCountByService != nil {
tree.tasks += node.DesiredRunningTasksCountByService[serviceID]
if node.ActiveTasksCountByService != nil {
tree.tasks += node.ActiveTasksCountByService[serviceID]
}

if tree.next == nil {
Expand Down
6 changes: 3 additions & 3 deletions manager/scheduler/scheduler.go
Expand Up @@ -517,8 +517,8 @@ func (s *Scheduler) scheduleTaskGroup(ctx context.Context, taskGroup map[string]
}
}

tasksByServiceA := a.DesiredRunningTasksCountByService[t.ServiceID]
tasksByServiceB := b.DesiredRunningTasksCountByService[t.ServiceID]
tasksByServiceA := a.ActiveTasksCountByService[t.ServiceID]
tasksByServiceB := b.ActiveTasksCountByService[t.ServiceID]

if tasksByServiceA < tasksByServiceB {
return true
Expand All @@ -528,7 +528,7 @@ func (s *Scheduler) scheduleTaskGroup(ctx context.Context, taskGroup map[string]
}

// Total number of tasks breaks ties.
return a.DesiredRunningTasksCount < b.DesiredRunningTasksCount
return a.ActiveTasksCount < b.ActiveTasksCount
}

var prefs []*api.PlacementPreference
Expand Down