Skip to content

Commit c5d26a8

Browse files
pbacskowilfred-s
authored andcommitted
[YUNIKORN-1770] Avoid resource clone in Application.tryNodes() (#553)
Closes: #553 Signed-off-by: Wilfred Spiegelenburg <[email protected]>
1 parent 94e6f2d commit c5d26a8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pkg/scheduler/objects/application.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ func (sa *Application) tryNodes(ask *AllocationAsk, iterator NodeIterator) *Allo
14561456
zap.Time("createTime", ask.GetCreateTime()),
14571457
zap.Duration("askAge", askAge),
14581458
zap.Duration("reservationDelay", reservationDelay))
1459-
score := ask.GetAllocatedResource().FitInScore(node.GetAvailableResource())
1459+
score := node.GetFitInScoreForAvailableResource(ask.GetAllocatedResource())
14601460
// Record the so-far best node to reserve
14611461
if score < scoreReserved {
14621462
scoreReserved = score

pkg/scheduler/objects/node.go

+8
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ func (sn *Node) GetAvailableResource() *resources.Resource {
255255
return sn.availableResource.Clone()
256256
}
257257

258+
// GetFitInScoreForAvailableResource calculates a fit in score for "res" based on the current
259+
// available resources, avoiding cloning. The caller must ensure that "res" cannot change while this method is running.
260+
func (sn *Node) GetFitInScoreForAvailableResource(res *resources.Resource) float64 {
261+
sn.RLock()
262+
defer sn.RUnlock()
263+
return res.FitInScore(sn.availableResource)
264+
}
265+
258266
// Get the utilized resource on this node.
259267
func (sn *Node) GetUtilizedResource() *resources.Resource {
260268
total := sn.GetCapacity()

0 commit comments

Comments
 (0)