-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make number of scheduler workers reloadable (#11593)
## Development Environment Changes * Added stringer to build deps ## New HTTP APIs * Added scheduler worker config API * Added scheduler worker info API ## New Internals * (Scheduler)Worker API refactor—Start(), Stop(), Pause(), Resume() * Update shutdown to use context * Add mutex for contended server data - `workerLock` for the `workers` slice - `workerConfigLock` for the `Server.Config.NumSchedulers` and `Server.Config.EnabledSchedulers` values ## Other * Adding docs for scheduler worker api * Add changelog message Co-authored-by: Derek Strickland <1111455+DerekStrickland@users.noreply.github.com>
- Loading branch information
1 parent
d5e8081
commit 6e61606
Showing
21 changed files
with
2,211 additions
and
101 deletions.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
server: Make num_schedulers and enabled_schedulers hot reloadable; add agent API endpoint to enable dynamic modifications of these values. | ||
``` |
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,57 @@ | ||
{ | ||
"$schema": "https://aka.ms/codetour-schema", | ||
"title": "Scheduler Worker - Hot Reload", | ||
"steps": [ | ||
{ | ||
"file": "nomad/server.go", | ||
"description": "## Server.Reload()\n\nServer configuration reloads start here.", | ||
"line": 782, | ||
"selection": { | ||
"start": { | ||
"line": 780, | ||
"character": 4 | ||
}, | ||
"end": { | ||
"line": 780, | ||
"character": 10 | ||
} | ||
} | ||
}, | ||
{ | ||
"file": "nomad/server.go", | ||
"description": "## Did NumSchedulers change?\nIf the number of schedulers has changed between the running configuration and the new one we need to adopt that change in realtime.", | ||
"line": 812 | ||
}, | ||
{ | ||
"file": "nomad/server.go", | ||
"description": "## Server.setupNewWorkers()\n\nsetupNewWorkers performs three tasks:\n\n- makes a copy of the existing worker pointers\n\n- creates a fresh array and loads a new set of workers into them\n\n- iterates through the \"old\" workers and shuts them down in individual\n goroutines for maximum parallelism", | ||
"line": 1482, | ||
"selection": { | ||
"start": { | ||
"line": 1480, | ||
"character": 4 | ||
}, | ||
"end": { | ||
"line": 1480, | ||
"character": 12 | ||
} | ||
} | ||
}, | ||
{ | ||
"file": "nomad/server.go", | ||
"description": "Once all of the work in setupNewWorkers is complete, we stop the old ones.", | ||
"line": 1485 | ||
}, | ||
{ | ||
"file": "nomad/server.go", | ||
"description": "The `stopOldWorkers` function iterates through the array of workers and calls their `Shutdown` method\nas a goroutine to prevent blocking.", | ||
"line": 1505 | ||
}, | ||
{ | ||
"file": "nomad/worker.go", | ||
"description": "The `Shutdown` method sets `w.stop` to true signaling that we intend for the `Worker` to stop the next time we consult it. We also manually unpause the `Worker` by setting w.paused to false and sending a `Broadcast()` via the cond.", | ||
"line": 110 | ||
} | ||
], | ||
"ref": "f-reload-num-schedulers" | ||
} |
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,66 @@ | ||
{ | ||
"$schema": "https://aka.ms/codetour-schema", | ||
"title": "Scheduler Worker - Pause", | ||
"steps": [ | ||
{ | ||
"file": "nomad/leader.go", | ||
"description": "## Server.establishLeadership()\n\nUpon becoming a leader, the server pauses a subset of the workers to allow for the additional burden of the leader's goroutines. The `handlePausableWorkers` function takes a boolean that states whether or not the current node is a leader or not. Because we are in `establishLeadership` we use `true` rather than calling `s.IsLeader()`", | ||
"line": 233, | ||
"selection": { | ||
"start": { | ||
"line": 233, | ||
"character": 4 | ||
}, | ||
"end": { | ||
"line": 233, | ||
"character": 12 | ||
} | ||
} | ||
}, | ||
{ | ||
"file": "nomad/leader.go", | ||
"description": "## Server.handlePausableWorkers()\n\nhandlePausableWorkers ranges over a slice of Workers and manipulates their paused state by calling their `SetPause` method.", | ||
"line": 443, | ||
"selection": { | ||
"start": { | ||
"line": 443, | ||
"character": 18 | ||
}, | ||
"end": { | ||
"line": 443, | ||
"character": 26 | ||
} | ||
} | ||
}, | ||
{ | ||
"file": "nomad/leader.go", | ||
"description": "## Server.pausableWorkers()\n\nThe pausableWorkers function provides a consistent slice of workers that the server can pause and unpause. Since the Worker array is never mutated, the same slice is returned by pausableWorkers on every invocation.\nThis comment is interesting/potentially confusing\n\n```golang\n // Disabling 3/4 of the workers frees CPU for raft and the\n\t// plan applier which uses 1/2 the cores.\n``` \n\nHowever, the key point is that it will return a slice containg 3/4th of the workers.", | ||
"line": 1100, | ||
"selection": { | ||
"start": { | ||
"line": 1104, | ||
"character": 1 | ||
}, | ||
"end": { | ||
"line": 1105, | ||
"character": 43 | ||
} | ||
} | ||
}, | ||
{ | ||
"file": "nomad/worker.go", | ||
"description": "## Worker.SetPause()\n\nThe `SetPause` function is used to signal an intention to pause the worker. Because the worker's work is happening in the `run()` goroutine, pauses happen asynchronously.", | ||
"line": 91 | ||
}, | ||
{ | ||
"file": "nomad/worker.go", | ||
"description": "## Worker.dequeueEvaluation()\n\nCalls checkPaused, which will be the function we wait in if the scheduler is set to be paused. \n\n> **NOTE:** This is called here rather than in run() because this function loops in case of an error fetching a evaluation.", | ||
"line": 206 | ||
}, | ||
{ | ||
"file": "nomad/worker.go", | ||
"description": "## Worker.checkPaused()\n\nWhen `w.paused` is `true`, we call the `Wait()` function on the condition. Execution of this goroutine will stop here until it receives a `Broadcast()` or a `Signal()`. At this point, the `Worker` is paused.", | ||
"line": 104 | ||
} | ||
] | ||
} |
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,51 @@ | ||
{ | ||
"$schema": "https://aka.ms/codetour-schema", | ||
"title": "Scheduler Worker - Unpause", | ||
"steps": [ | ||
{ | ||
"file": "nomad/leader.go", | ||
"description": "## revokeLeadership()\n\nAs a server transistions from leader to non-leader, the pausableWorkers are resumed since the other leader goroutines are stopped providing extra capacity.", | ||
"line": 1040, | ||
"selection": { | ||
"start": { | ||
"line": 1038, | ||
"character": 10 | ||
}, | ||
"end": { | ||
"line": 1038, | ||
"character": 20 | ||
} | ||
} | ||
}, | ||
{ | ||
"file": "nomad/leader.go", | ||
"description": "## handlePausableWorkers()\n\nThe handlePausableWorkers method is called with `false`. We fetch the pausableWorkers and call their SetPause method with `false`.\n", | ||
"line": 443, | ||
"selection": { | ||
"start": { | ||
"line": 443, | ||
"character": 18 | ||
}, | ||
"end": { | ||
"line": 443, | ||
"character": 27 | ||
} | ||
} | ||
}, | ||
{ | ||
"file": "nomad/worker.go", | ||
"description": "## Worker.SetPause()\n\nDuring unpause, p is false. We update w.paused in the mutex, and then call Broadcast on the cond. This wakes the goroutine sitting in the Wait() inside of `checkPaused()`", | ||
"line": 91 | ||
}, | ||
{ | ||
"file": "nomad/worker.go", | ||
"description": "## Worker.checkPaused()\n\nOnce the goroutine receives the `Broadcast()` message from `SetPause()`, execution continues here. Now that `w.paused == false`, we exit the loop and return to the caller (the `dequeueEvaluation()` function).", | ||
"line": 104 | ||
}, | ||
{ | ||
"file": "nomad/worker.go", | ||
"description": "## Worker.dequeueEvaluation\n\nWe return back into dequeueEvaluation after the call to checkPaused. At this point the worker will either stop (if that signal boolean has been set) or continue looping after returning to run().", | ||
"line": 207 | ||
} | ||
] | ||
} |
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,36 @@ | ||
{ | ||
"$schema": "https://aka.ms/codetour-schema", | ||
"title": "Scheduler Worker - Start", | ||
"steps": [ | ||
{ | ||
"file": "nomad/server.go", | ||
"description": "## Server.NewServer()\n\nScheduler workers are started as the agent starts the `server` go routines.", | ||
"line": 402 | ||
}, | ||
{ | ||
"file": "nomad/server.go", | ||
"description": "## Server.setupWorkers()\n\nThe `setupWorkers()` function validates that there are enabled Schedulers by type and count. It then creates s.config.NumSchedulers by calling `NewWorker()`\n\nThe `_core` scheduler _**must**_ be enabled. **TODO: why?**\n", | ||
"line": 1443, | ||
"selection": { | ||
"start": { | ||
"line": 1442, | ||
"character": 4 | ||
}, | ||
"end": { | ||
"line": 1442, | ||
"character": 12 | ||
} | ||
} | ||
}, | ||
{ | ||
"file": "nomad/worker.go", | ||
"description": "## Worker.NewWorker\n\nNewWorker creates the Worker and starts `run()` in a goroutine.", | ||
"line": 78 | ||
}, | ||
{ | ||
"file": "nomad/worker.go", | ||
"description": "## Worker.run()\n\nThe `run()` function runs in a loop until it's paused, it's stopped, or the server indicates that it is shutting down. All of the work the `Worker` performs should be\nimplemented in or called from here.\n", | ||
"line": 152 | ||
} | ||
] | ||
} |
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
Oops, something went wrong.