-
Notifications
You must be signed in to change notification settings - Fork 7
fix(scheduler): preserve worker context when resizing #1044
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
base: main
Are you sure you want to change the base?
Changes from all commits
c049d07
2c5a622
0916e74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -80,35 +80,37 @@ def __init__( | |||||||
| executor_kwargs["restart_limit"] = restart_limit | ||||||||
| self._process_kwargs = executor_kwargs | ||||||||
| self._max_workers = max_workers | ||||||||
| self_id = random.getrandbits(128) | ||||||||
| self._self_id = self_id | ||||||||
| self._self_id = random.getrandbits(128) | ||||||||
| _interrupt_bootup_dict[self._self_id] = False | ||||||||
| alive_workers = [max_workers] | ||||||||
| alive_workers_lock = Lock() | ||||||||
| bootup_events = [Event() for _ in range(self._max_workers)] | ||||||||
| bootup_events[0].set() | ||||||||
| self._alive_workers = [max_workers] | ||||||||
| self._alive_workers_lock = Lock() | ||||||||
| self._bootup_events = [Event() for _ in range(self._max_workers)] | ||||||||
| self._bootup_events[0].set() | ||||||||
| self._set_process( | ||||||||
| process=[ | ||||||||
| Thread( | ||||||||
| target=_execute_multiple_tasks, | ||||||||
| kwargs=executor_kwargs | ||||||||
| | { | ||||||||
| "worker_id": worker_id, | ||||||||
| "stop_function": lambda: _interrupt_bootup_dict[self_id], | ||||||||
| "bootup_event": bootup_events[worker_id], | ||||||||
| "next_bootup_event": ( | ||||||||
| bootup_events[worker_id + 1] | ||||||||
| if worker_id + 1 < self._max_workers | ||||||||
| else None | ||||||||
| ), | ||||||||
| "alive_workers": alive_workers, | ||||||||
| "alive_workers_lock": alive_workers_lock, | ||||||||
| }, | ||||||||
| kwargs=self._worker_kwargs(worker_id), | ||||||||
| ) | ||||||||
| for worker_id in range(self._max_workers) | ||||||||
| ], | ||||||||
| ) | ||||||||
|
|
||||||||
| def _worker_kwargs(self, worker_id: int) -> dict: | ||||||||
| self_id = self._self_id | ||||||||
| return self._process_kwargs | { | ||||||||
| "worker_id": worker_id, | ||||||||
| "stop_function": lambda: _interrupt_bootup_dict[self_id], | ||||||||
| "bootup_event": self._bootup_events[worker_id], | ||||||||
| "next_bootup_event": ( | ||||||||
| self._bootup_events[worker_id + 1] | ||||||||
| if worker_id + 1 < len(self._bootup_events) | ||||||||
| else None | ||||||||
| ), | ||||||||
| "alive_workers": self._alive_workers, | ||||||||
| "alive_workers_lock": self._alive_workers_lock, | ||||||||
| } | ||||||||
|
|
||||||||
| @property | ||||||||
| def max_workers(self) -> int: | ||||||||
| return self._max_workers | ||||||||
|
|
@@ -126,12 +128,19 @@ def max_workers(self, max_workers: int): | |||||||
| process for process in self._process if process.is_alive() | ||||||||
| ] | ||||||||
| elif self._max_workers < max_workers: | ||||||||
| old_max_workers = self._max_workers | ||||||||
| self._bootup_events.extend( | ||||||||
| Event() for _ in range(max_workers - old_max_workers) | ||||||||
| ) | ||||||||
| for idx in range(old_max_workers, max_workers): | ||||||||
| self._bootup_events[idx].set() | ||||||||
| self._alive_workers[0] += max_workers - old_max_workers | ||||||||
|
Contributor
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. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Synchronize the live-worker count update.
Proposed fix- self._alive_workers[0] += max_workers - old_max_workers
+ with self._alive_workers_lock:
+ self._alive_workers[0] += max_workers - old_max_workers📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| new_process_lst = [ | ||||||||
| Thread( | ||||||||
| target=_execute_multiple_tasks, | ||||||||
| kwargs=self._process_kwargs, | ||||||||
| kwargs=self._worker_kwargs(worker_id), | ||||||||
| ) | ||||||||
| for _ in range(max_workers - self._max_workers) | ||||||||
| for worker_id in range(old_max_workers, max_workers) | ||||||||
| ] | ||||||||
| for process_instance in new_process_lst: | ||||||||
| process_instance.start() | ||||||||
|
|
||||||||
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Release the first added worker from bootup.
_worker_kwargs()snapshots the original tail worker'snext_bootup_eventasNone. After resize, the first added worker waits on the new unset event, but no existing worker can signal it. The added worker and later added workers remain blocked inbootup_event.wait().Signal the first new bootup event when resizing. If strict worker-ID boot order must also apply during concurrent startup, use a resizable handoff instead of a static
next_bootup_event.Proposed fix
self._bootup_events.extend( Event() for _ in range(max_workers - old_max_workers) ) + self._bootup_events[old_max_workers].set() self._alive_workers[0] += max_workers - old_max_workersAlso applies to: 130-140
🤖 Prompt for AI Agents