@@ -56,7 +56,7 @@ func (n *NodeScheduler) Schedule(schedContext *SchedulingContext, jctx *context.
5656 if err != nil {
5757 return nil , err
5858 }
59- err = n .populateQueueImpactFields (schedContext , queues )
59+ err = n .populateQueueImpactFields (schedContext , jctx , queues )
6060 if err != nil {
6161 return nil , err
6262 }
@@ -73,7 +73,7 @@ func (n *NodeScheduler) Schedule(schedContext *SchedulingContext, jctx *context.
7373 queueCostChanges := map [string ]float64 {}
7474 for _ , jobToEvict := range allJobs {
7575 availableResource = availableResource .Add (jobToEvict .resources )
76- totalCost += jobToEvict .cost
76+ totalCost += jobToEvict .costToPreempt
7777 if _ , present := queueCostChanges [jobToEvict .queue ]; ! present {
7878 queueCostChanges [jobToEvict .queue ] = 0
7979 }
@@ -93,9 +93,7 @@ func (n *NodeScheduler) Schedule(schedContext *SchedulingContext, jctx *context.
9393 return nil , fmt .Errorf ("could not find queue context for queue %s" , queue )
9494 }
9595
96- // TODO This should work fine, but probably should be cost / original total cost
97- // So if it a queue is way above its fairshare, this number reflects the % of current allocation lost, rather than % of fairshare
98- impact := math .Abs (costChange ) / qctx .Fairshare
96+ impact := math .Abs (costChange ) / qctx .CurrentCost
9997 if impact > maximumQueueImpact {
10098 maximumQueueImpact = impact
10199 }
@@ -127,6 +125,7 @@ func (n *NodeScheduler) getPreemptibleJobDetailsByQueue(
127125 jobToSchedule * context.JobSchedulingContext ,
128126 node * internaltypes.Node ) (map [string ][]* preemptibleJobDetails , error ) {
129127 queues := map [string ][]* preemptibleJobDetails {}
128+ start := time .Now ()
130129 for jobId , resource := range node .AllocatedByJobId {
131130 job := n .jobDb .GetById (jobId )
132131 if job == nil {
@@ -154,15 +153,16 @@ func (n *NodeScheduler) getPreemptibleJobDetailsByQueue(
154153 }
155154 jctx , ok := qctx .SuccessfulJobSchedulingContexts [jobId ]
156155 if ! ok {
157- return nil , fmt .Errorf ("could not job context for job %s in successful scheduling contexts for queue %s, expected to find it scheduled on node %s" , jobId , queue , node .GetName ())
156+ return nil , fmt .Errorf ("could not find job context for job %s in successful scheduling contexts for queue %s, expected to find it scheduled on node %s" , jobId , queue , node .GetName ())
158157 }
159158 if jctx .PodSchedulingContext == nil {
160159 return nil , fmt .Errorf ("no pod scheduling context exists on jctx for job %s despite it being in successful scheduling contexts" , jobId )
161160 }
162161 scheduledAtPriority = jctx .PodSchedulingContext .ScheduledAtPriority
163162 } else {
163+ // TODO handle latest run not existing
164164 scheduledAtPriority = * job .LatestRun ().ScheduledAtPriority ()
165- age = time . Now () .Sub (* job .LatestRun ().LeaseTime ()).Milliseconds ()
165+ age = start .Sub (* job .LatestRun ().LeaseTime ()).Milliseconds ()
166166 }
167167 if scheduledAtPriority > jobToSchedule .Job .PriorityClass ().Priority {
168168 // Can't evict jobs of higher priority
@@ -188,7 +188,7 @@ func (n *NodeScheduler) getPreemptibleJobDetailsByQueue(
188188 return queues , nil
189189}
190190
191- func (n * NodeScheduler ) populateQueueImpactFields (schedContext * SchedulingContext , queues map [string ][]* preemptibleJobDetails ) error {
191+ func (n * NodeScheduler ) populateQueueImpactFields (schedContext * SchedulingContext , jobToSchedule * context. JobSchedulingContext , queues map [string ][]* preemptibleJobDetails ) error {
192192 for queue , items := range queues {
193193 sort .Sort (internalQueueOrder (items ))
194194
@@ -204,6 +204,8 @@ func (n *NodeScheduler) populateQueueImpactFields(schedContext *SchedulingContex
204204 updatedQueueCost = item .queueCostAfterPreemption
205205 if item .queueCostAfterPreemption > qctx .Fairshare {
206206 item .costToPreempt = 0
207+ } else if item .scheduledAtPriority < jobToSchedule .Job .PriorityClass ().Priority {
208+ item .costToPreempt = 0
207209 } else {
208210 // This could be improved to handle crossing the fairshare boundary better
209211 // It could just cost the amount the queue is brought below fairshare, rather than the full item cost
0 commit comments