You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 <[email protected]>
"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.",
23
+
"line": 812
24
+
},
25
+
{
26
+
"file": "nomad/server.go",
27
+
"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",
28
+
"line": 1482,
29
+
"selection": {
30
+
"start": {
31
+
"line": 1480,
32
+
"character": 4
33
+
},
34
+
"end": {
35
+
"line": 1480,
36
+
"character": 12
37
+
}
38
+
}
39
+
},
40
+
{
41
+
"file": "nomad/server.go",
42
+
"description": "Once all of the work in setupNewWorkers is complete, we stop the old ones.",
43
+
"line": 1485
44
+
},
45
+
{
46
+
"file": "nomad/server.go",
47
+
"description": "The `stopOldWorkers` function iterates through the array of workers and calls their `Shutdown` method\nas a goroutine to prevent blocking.",
48
+
"line": 1505
49
+
},
50
+
{
51
+
"file": "nomad/worker.go",
52
+
"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.",
"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()`",
8
+
"line": 233,
9
+
"selection": {
10
+
"start": {
11
+
"line": 233,
12
+
"character": 4
13
+
},
14
+
"end": {
15
+
"line": 233,
16
+
"character": 12
17
+
}
18
+
}
19
+
},
20
+
{
21
+
"file": "nomad/leader.go",
22
+
"description": "## Server.handlePausableWorkers()\n\nhandlePausableWorkers ranges over a slice of Workers and manipulates their paused state by calling their `SetPause` method.",
23
+
"line": 443,
24
+
"selection": {
25
+
"start": {
26
+
"line": 443,
27
+
"character": 18
28
+
},
29
+
"end": {
30
+
"line": 443,
31
+
"character": 26
32
+
}
33
+
}
34
+
},
35
+
{
36
+
"file": "nomad/leader.go",
37
+
"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.",
38
+
"line": 1100,
39
+
"selection": {
40
+
"start": {
41
+
"line": 1104,
42
+
"character": 1
43
+
},
44
+
"end": {
45
+
"line": 1105,
46
+
"character": 43
47
+
}
48
+
}
49
+
},
50
+
{
51
+
"file": "nomad/worker.go",
52
+
"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.",
53
+
"line": 91
54
+
},
55
+
{
56
+
"file": "nomad/worker.go",
57
+
"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.",
58
+
"line": 206
59
+
},
60
+
{
61
+
"file": "nomad/worker.go",
62
+
"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.",
"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.",
8
+
"line": 1040,
9
+
"selection": {
10
+
"start": {
11
+
"line": 1038,
12
+
"character": 10
13
+
},
14
+
"end": {
15
+
"line": 1038,
16
+
"character": 20
17
+
}
18
+
}
19
+
},
20
+
{
21
+
"file": "nomad/leader.go",
22
+
"description": "## handlePausableWorkers()\n\nThe handlePausableWorkers method is called with `false`. We fetch the pausableWorkers and call their SetPause method with `false`.\n",
23
+
"line": 443,
24
+
"selection": {
25
+
"start": {
26
+
"line": 443,
27
+
"character": 18
28
+
},
29
+
"end": {
30
+
"line": 443,
31
+
"character": 27
32
+
}
33
+
}
34
+
},
35
+
{
36
+
"file": "nomad/worker.go",
37
+
"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()`",
38
+
"line": 91
39
+
},
40
+
{
41
+
"file": "nomad/worker.go",
42
+
"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).",
43
+
"line": 104
44
+
},
45
+
{
46
+
"file": "nomad/worker.go",
47
+
"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().",
"description": "## Server.NewServer()\n\nScheduler workers are started as the agent starts the `server` go routines.",
8
+
"line": 402
9
+
},
10
+
{
11
+
"file": "nomad/server.go",
12
+
"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",
13
+
"line": 1443,
14
+
"selection": {
15
+
"start": {
16
+
"line": 1442,
17
+
"character": 4
18
+
},
19
+
"end": {
20
+
"line": 1442,
21
+
"character": 12
22
+
}
23
+
}
24
+
},
25
+
{
26
+
"file": "nomad/worker.go",
27
+
"description": "## Worker.NewWorker\n\nNewWorker creates the Worker and starts `run()` in a goroutine.",
28
+
"line": 78
29
+
},
30
+
{
31
+
"file": "nomad/worker.go",
32
+
"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",
0 commit comments