Skip to content

Commit

Permalink
[YUNIKORN-1770] Avoid resource clone in Application.tryNodes() (#553)
Browse files Browse the repository at this point in the history
Closes: #553

Signed-off-by: Wilfred Spiegelenburg <[email protected]>
  • Loading branch information
pbacsko authored and wilfred-s committed May 26, 2023
1 parent 94e6f2d commit c5d26a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/scheduler/objects/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ func (sa *Application) tryNodes(ask *AllocationAsk, iterator NodeIterator) *Allo
zap.Time("createTime", ask.GetCreateTime()),
zap.Duration("askAge", askAge),
zap.Duration("reservationDelay", reservationDelay))
score := ask.GetAllocatedResource().FitInScore(node.GetAvailableResource())
score := node.GetFitInScoreForAvailableResource(ask.GetAllocatedResource())
// Record the so-far best node to reserve
if score < scoreReserved {
scoreReserved = score
Expand Down
8 changes: 8 additions & 0 deletions pkg/scheduler/objects/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ func (sn *Node) GetAvailableResource() *resources.Resource {
return sn.availableResource.Clone()
}

// GetFitInScoreForAvailableResource calculates a fit in score for "res" based on the current
// available resources, avoiding cloning. The caller must ensure that "res" cannot change while this method is running.
func (sn *Node) GetFitInScoreForAvailableResource(res *resources.Resource) float64 {
sn.RLock()
defer sn.RUnlock()
return res.FitInScore(sn.availableResource)
}

// Get the utilized resource on this node.
func (sn *Node) GetUtilizedResource() *resources.Resource {
total := sn.GetCapacity()
Expand Down

0 comments on commit c5d26a8

Please sign in to comment.