-
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
core: Limit GC size #1012
Merged
Merged
core: Limit GC size #1012
Changes from 1 commit
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,13 @@ import ( | |
"github.com/hashicorp/nomad/scheduler" | ||
) | ||
|
||
var ( | ||
// maxIdsPerReap is the maximum number of evals and allocations to reap in a | ||
// single Raft transaction. This is to ensure that the Raft message does not | ||
// become too large. | ||
maxIdsPerReap = (1024 * 512) / 36 // 0.5 MB of ids. | ||
) | ||
|
||
// CoreScheduler is a special "scheduler" that is registered | ||
// as "_core". It is used to run various administrative work | ||
// across the cluster. | ||
|
@@ -232,22 +239,62 @@ func (c *CoreScheduler) gcEval(eval *structs.Evaluation, thresholdIndex uint64) | |
// allocs. | ||
func (c *CoreScheduler) evalReap(evals, allocs []string) error { | ||
// Call to the leader to issue the reap | ||
req := structs.EvalDeleteRequest{ | ||
Evals: evals, | ||
Allocs: allocs, | ||
WriteRequest: structs.WriteRequest{ | ||
Region: c.srv.config.Region, | ||
}, | ||
} | ||
var resp structs.GenericResponse | ||
if err := c.srv.RPC("Eval.Reap", &req, &resp); err != nil { | ||
c.srv.logger.Printf("[ERR] sched.core: eval reap failed: %v", err) | ||
return err | ||
for _, req := range c.partitionReap(evals, allocs) { | ||
var resp structs.GenericResponse | ||
if err := c.srv.RPC("Eval.Reap", req, &resp); err != nil { | ||
c.srv.logger.Printf("[ERR] sched.core: eval reap failed: %v", err) | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// partitionReap returns a list of EvalDeleteRequest to make, ensuring a single | ||
// request does not contain too many allocations and evaluations. This is | ||
// necessary to ensure that the Raft transaction does not become too large. | ||
func (c *CoreScheduler) partitionReap(evals, allocs []string) []*structs.EvalDeleteRequest { | ||
var requests []*structs.EvalDeleteRequest | ||
var submittedEvals, submittedAllocs int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just assign them to zero, same effect but cleaner |
||
for submittedEvals != len(evals) || submittedAllocs != len(allocs) { | ||
req := &structs.EvalDeleteRequest{ | ||
WriteRequest: structs.WriteRequest{ | ||
Region: c.srv.config.Region, | ||
}, | ||
} | ||
requests = append(requests, req) | ||
available := maxIdsPerReap | ||
|
||
// Add the evals first | ||
if remaining := len(evals) - submittedEvals; remaining > 0 { | ||
if remaining <= available { | ||
req.Evals = evals[submittedEvals:] | ||
available -= remaining | ||
submittedEvals += remaining | ||
} else { | ||
req.Evals = evals[submittedEvals : submittedEvals+available] | ||
submittedEvals += available | ||
|
||
// Exhausted space so skip adding allocs | ||
continue | ||
} | ||
} | ||
|
||
// Add the allocs | ||
if remaining := len(allocs) - submittedAllocs; remaining > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should probably GC allocs first, odd to have a alloc with no eval attached |
||
if remaining <= available { | ||
req.Allocs = allocs[submittedAllocs:] | ||
submittedAllocs += remaining | ||
} else { | ||
req.Allocs = allocs[submittedAllocs : submittedAllocs+available] | ||
submittedAllocs += available | ||
} | ||
} | ||
} | ||
|
||
return requests | ||
} | ||
|
||
// nodeGC is used to garbage collect old nodes | ||
func (c *CoreScheduler) nodeGC(eval *structs.Evaluation) error { | ||
// Iterate over the evaluations | ||
|
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
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.
I'd go lower to 256KB