Skip to content

Commit

Permalink
Merge pull request #2786 from jiangkaihua/2782-modify-binpack-score
Browse files Browse the repository at this point in the history
Modify binpack score on nodes with releasing resources.
  • Loading branch information
volcano-sh-bot authored Apr 14, 2023
2 parents ee79957 + 8944bfd commit 31b47aa
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/scheduler/plugins/binpack/binpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,14 @@ func BinPackingScore(task *api.TaskInfo, node *api.NodeInfo, weight priorityWeig
continue
}

resourceScore := ResourceBinPackingScore(request, allocate, nodeUsed, resourceWeight)
klog.V(5).Infof("task %s/%s on node %s resource %s, need %f, used %f, allocatable %f, weight %d, score %f", task.Namespace, task.Name, node.Name, resource, request, nodeUsed, allocate, resourceWeight, resourceScore)
resourceScore, err := ResourceBinPackingScore(request, allocate, nodeUsed, resourceWeight)
if err != nil {
klog.V(4).Infof("task %s/%s cannot binpack node %s: resource: %s is %s, need %f, used %f, allocatable %f",
task.Namespace, task.Name, node.Name, resource, err.Error(), request, nodeUsed, allocate)
return 0
}
klog.V(5).Infof("task %s/%s on node %s resource %s, need %f, used %f, allocatable %f, weight %d, score %f",
task.Namespace, task.Name, node.Name, resource, request, nodeUsed, allocate, resourceWeight, resourceScore)

score += resourceScore
weightSum += resourceWeight
Expand All @@ -240,16 +246,16 @@ func BinPackingScore(task *api.TaskInfo, node *api.NodeInfo, weight priorityWeig
}

// ResourceBinPackingScore calculate the binpack score for resource with provided info
func ResourceBinPackingScore(requested, capacity, used float64, weight int) float64 {
func ResourceBinPackingScore(requested, capacity, used float64, weight int) (float64, error) {
if capacity == 0 || weight == 0 {
return 0
return 0, nil
}

usedFinally := requested + used
if usedFinally > capacity {
return 0
return 0, fmt.Errorf("not enough")
}

score := usedFinally * float64(weight) / capacity
return score
return score, nil
}

0 comments on commit 31b47aa

Please sign in to comment.