-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor scheduler package to enable preemption for batch/service jobs #5545
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// +build !pro,!ent | ||
|
||
package scheduler | ||
|
||
import "github.com/hashicorp/nomad/nomad/structs" | ||
|
||
// selectNextOption calls the stack to get a node for placement | ||
func (s *GenericScheduler) selectNextOption(tg *structs.TaskGroup, selectOptions *SelectOptions) *RankedNode { | ||
return s.stack.Select(tg, selectOptions) | ||
} | ||
|
||
// handlePreemptions sets relevant preeemption related fields. In OSS this is a no op. | ||
func (s *GenericScheduler) handlePreemptions(option *RankedNode, alloc *structs.Allocation, missing placementResult) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// +build !pro,!ent | ||
|
||
package scheduler | ||
|
||
// NewGenericStack constructs a stack used for selecting service placements | ||
func NewGenericStack(batch bool, ctx Context) *GenericStack { | ||
// Create a new stack | ||
s := &GenericStack{ | ||
batch: batch, | ||
ctx: ctx, | ||
} | ||
|
||
// Create the source iterator. We randomize the order we visit nodes | ||
// to reduce collisions between schedulers and to do a basic load | ||
// balancing across eligible nodes. | ||
s.source = NewRandomIterator(ctx, nil) | ||
|
||
// Create the quota iterator to determine if placements would result in the | ||
// quota attached to the namespace of the job to go over. | ||
s.quota = NewQuotaIterator(ctx, s.source) | ||
|
||
// Attach the job constraints. The job is filled in later. | ||
s.jobConstraint = NewConstraintChecker(ctx, nil) | ||
|
||
// Filter on task group drivers first as they are faster | ||
s.taskGroupDrivers = NewDriverChecker(ctx, nil) | ||
|
||
// Filter on task group constraints second | ||
s.taskGroupConstraint = NewConstraintChecker(ctx, nil) | ||
|
||
// Filter on task group devices | ||
s.taskGroupDevices = NewDeviceChecker(ctx) | ||
|
||
// Create the feasibility wrapper which wraps all feasibility checks in | ||
// which feasibility checking can be skipped if the computed node class has | ||
// previously been marked as eligible or ineligible. Generally this will be | ||
// checks that only needs to examine the single node to determine feasibility. | ||
jobs := []FeasibilityChecker{s.jobConstraint} | ||
tgs := []FeasibilityChecker{s.taskGroupDrivers, s.taskGroupConstraint, s.taskGroupDevices} | ||
s.wrappedChecks = NewFeasibilityWrapper(ctx, s.quota, jobs, tgs) | ||
|
||
// Filter on distinct host constraints. | ||
s.distinctHostsConstraint = NewDistinctHostsIterator(ctx, s.wrappedChecks) | ||
|
||
// Filter on distinct property constraints. | ||
s.distinctPropertyConstraint = NewDistinctPropertyIterator(ctx, s.distinctHostsConstraint) | ||
|
||
// Upgrade from feasible to rank iterator | ||
rankSource := NewFeasibleRankIterator(ctx, s.distinctPropertyConstraint) | ||
|
||
// Apply the bin packing, this depends on the resources needed | ||
// by a particular task group. | ||
s.binPack = NewBinPackIterator(ctx, rankSource, false, 0) | ||
|
||
// Apply the job anti-affinity iterator. This is to avoid placing | ||
// multiple allocations on the same node for this job. | ||
s.jobAntiAff = NewJobAntiAffinityIterator(ctx, s.binPack, "") | ||
|
||
// Apply node rescheduling penalty. This tries to avoid placing on a | ||
// node where the allocation failed previously | ||
s.nodeReschedulingPenalty = NewNodeReschedulingPenaltyIterator(ctx, s.jobAntiAff) | ||
|
||
// Apply scores based on affinity stanza | ||
s.nodeAffinity = NewNodeAffinityIterator(ctx, s.nodeReschedulingPenalty) | ||
|
||
// Apply scores based on spread stanza | ||
s.spread = NewSpreadIterator(ctx, s.nodeAffinity) | ||
|
||
// Normalizes scores by averaging them across various scorers | ||
s.scoreNorm = NewScoreNormalizationIterator(ctx, s.spread) | ||
|
||
// Apply a limit function. This is to avoid scanning *every* possible node. | ||
s.limit = NewLimitIterator(ctx, s.scoreNorm, 2, skipScoreThreshold, maxSkip) | ||
|
||
// Select the node with the maximum score for placement | ||
s.maxScore = NewMaxScoreIterator(ctx, s.limit) | ||
return s | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we potentially want to have a way to modify the stack, rather than duping the whole setup? (mostly worried about duplicate work when introducing other new scheduler things that could easily be forgotten to be also PR'd to ENT)