Skip to content

Commit 51ece85

Browse files
committed
scheduler: fixed a bug where the bandwidth of reserved cores were not taken into account
1 parent b8e7428 commit 51ece85

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

client/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3335,8 +3335,7 @@ func (c *Client) setGaugeForDiskStats(hStats *hoststats.HostStats, baseLabels []
33353335
func (c *Client) setGaugeForAllocationStats(baseLabels []metrics.Label) {
33363336
node := c.GetConfig().Node
33373337

3338-
available := node.NodeResources.Comparable()
3339-
available.Subtract(node.ReservedResources.Comparable())
3338+
available := node.Comparable()
33403339
allocated := c.getAllocatedResources(node)
33413340

33423341
// Emit allocated

nomad/structs/funcs.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,8 @@ func AllocsFit(node *Node, allocs []*Allocation, netIdx *NetworkIndex, checkDevi
189189
return false, "cores", used, nil
190190
}
191191

192-
// Check that the node resources (after subtracting reserved) are a
193-
// super set of those that are being allocated
194-
available := node.NodeResources.Comparable()
195-
available.Subtract(node.ReservedResources.Comparable())
192+
// Check that the node resources are a super set of those that are being allocated
193+
available := node.Comparable()
196194
if superset, dimension := available.Superset(used); !superset {
197195
return false, dimension, used, nil
198196
}
@@ -232,11 +230,8 @@ func AllocsFit(node *Node, allocs []*Allocation, netIdx *NetworkIndex, checkDevi
232230
}
233231

234232
func computeFreePercentage(node *Node, util *ComparableResources) (freePctCpu, freePctRam float64) {
235-
// Determine the node availability
236-
available := node.NodeResources.Comparable()
237-
available.Subtract(node.ReservedResources.Comparable())
238-
239233
// Compute the free percentage
234+
available := node.Comparable()
240235
freePctCpu = 1 - (float64(util.Flattened.Cpu.CpuShares) / float64(available.Flattened.Cpu.CpuShares))
241236
freePctRam = 1 - (float64(util.Flattened.Memory.MemoryMB) / float64(available.Flattened.Memory.MemoryMB))
242237
return freePctCpu, freePctRam

nomad/structs/structs.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,6 +2247,19 @@ func (n *Node) Canonicalize() {
22472247
}
22482248
}
22492249

2250+
// Comparable returns a comparable version of the node's resources available for scheduling.
2251+
// This conversion can be lossy so care must be taken when using it.
2252+
func (n *Node) Comparable() *ComparableResources {
2253+
if n == nil {
2254+
return nil
2255+
}
2256+
2257+
resources := n.NodeResources.Comparable()
2258+
resources.Subtract(n.ReservedResources.Comparable())
2259+
2260+
return resources
2261+
}
2262+
22502263
func (n *Node) Copy() *Node {
22512264
if n == nil {
22522265
return nil

scheduler/feasible/preemption.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,7 @@ func (p *Preemptor) Copy() *Preemptor {
162162

163163
// SetNode sets the node
164164
func (p *Preemptor) SetNode(node *structs.Node) {
165-
nodeRemainingResources := node.NodeResources.Comparable()
166-
167-
// Subtract the reserved resources of the node
168-
if c := node.ReservedResources.Comparable(); c != nil {
169-
nodeRemainingResources.Subtract(c)
170-
}
171-
p.nodeRemainingResources = nodeRemainingResources
165+
p.nodeRemainingResources = node.Comparable()
172166
}
173167

174168
// SetCandidates initializes the candidate set from which preemptions are chosen

0 commit comments

Comments
 (0)