Skip to content

Commit

Permalink
Merge pull request #1980 from aaronlehmann/bad-scheduling-decisions-p…
Browse files Browse the repository at this point in the history
…arallel-update

scheduler: Tasks with a desired state < RUNNING should count
  • Loading branch information
aluzzardi committed Feb 23, 2017
2 parents 4dbc0a3 + 69bd653 commit d29a857
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion manager/scheduler/constraint_test.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit d29a857

Please sign in to comment.