-
-
Notifications
You must be signed in to change notification settings - Fork 150
Fix scale edge cases #171
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
Merged
Merged
Fix scale edge cases #171
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6750f01
Fix scale edge cases
guillaumeeb c4db1f7
Merge branch 'master' into robust_scale
guillaumeeb 5e834c2
enabling scale edge case test
guillaumeeb 189b263
use add_callback correctly
guillaumeeb e8b2fb1
Fix concurency issue and other code pieces
guillaumeeb 0be29be
wait some time for jobs to be cancelled
guillaumeeb 381dcdc
using coroutine to yeild scheduler calls. Removing lock
guillaumeeb 2406f6d
merge master and fix adaptive issues
guillaumeeb 22d53d0
Merge branch 'robust_scale' of https://github.com/guillaumeeb/dask-jo…
guillaumeeb b8c7836
some more adaptive and scale tests
guillaumeeb 0a2d2ce
Comments on cluster Manager desgin need
guillaumeeb 383854e
new flake check
guillaumeeb 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 hidden or 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 hidden or 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,114 @@ | ||
| import logging | ||
|
|
||
| from tornado import gen | ||
| from distributed.deploy import Cluster | ||
| from distributed.utils import log_errors | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ClusterManager(Cluster): | ||
| """ Intermediate Cluster object that should lead to a real ClusterManager | ||
|
|
||
| This tries to improve upstream Cluster object and underlines needs for | ||
| better decoupling between ClusterManager and Scheduler object | ||
|
|
||
| This currently expects a local Scheduler defined on the object, but should | ||
| eventually only rely on RPC calls on remote or local scheduler. | ||
| It provides common methods and an IPython widget display. | ||
|
|
||
| Clusters inheriting from this class should provide the following: | ||
|
|
||
| 1. A local ``Scheduler`` object at ``.scheduler``. In the future, just | ||
| a URL to local or remote scheduler. | ||
| 2. scale_up and scale_down methods as defined below:: | ||
|
|
||
| def scale_up(self, n: int): | ||
| ''' Brings total worker count up to ``n`` ''' | ||
|
|
||
| def scale_down(self, workers: List[str], n: int): | ||
| ''' Close the workers with the given addresses or remove pending | ||
| workers to match n running workers. | ||
| ''' | ||
|
|
||
| This will provide a general ``scale`` method as well as an IPython widget | ||
| for display. | ||
|
|
||
| Things the will need to change for the complete Cluster Manager Design: | ||
| - ClusterManager: | ||
| - Use it's own event loop, or the notebook one. | ||
| - Connect to a local or remote Scheduler through RPC, and then | ||
| communicate with it. | ||
| - Ability to start a local or remote scheduler. | ||
| - Scheduler | ||
| - Provide some remote methods: | ||
| - retire_workers(n: int): close enough workers ot have only n | ||
| running at the end. Return the closed workers. | ||
|
|
||
| Examples | ||
| -------- | ||
|
|
||
| >>> from distributed.deploy import Cluster | ||
| >>> class MyCluster(cluster): | ||
| ... def scale_up(self, n): | ||
| ... ''' Bring the total worker count up to n ''' | ||
| ... pass | ||
| ... def scale_down(self, workers, n=None): | ||
| ... ''' Close the workers with the given addresses ''' | ||
| ... pass | ||
|
|
||
| >>> cluster = MyCluster() | ||
| >>> cluster.scale(5) # scale manually | ||
| >>> cluster.adapt(minimum=1, maximum=100) # scale automatically | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| self._target_scale = 0 | ||
|
|
||
| @gen.coroutine | ||
| def _scale(self, n): | ||
| """ Asynchronously called scale method | ||
|
|
||
| This allows to do every operation with a coherent ocntext | ||
| """ | ||
| with log_errors(): | ||
| # here we rely on a ClusterManager attribute to retrieve the | ||
| # active and pending workers | ||
| if n == self._target_scale: | ||
| pass | ||
| elif n > self._target_scale: | ||
| self.scale_up(n) | ||
| else: | ||
| # TODO to_close may be empty if some workers are pending | ||
| # This may not be useful to call scheduler methods in this case | ||
| # Scheduler interface here may need to be modified | ||
| to_close = self.scheduler.workers_to_close( | ||
| n=len(self.scheduler.workers) - n) | ||
| logger.debug("Closing workers: %s", to_close) | ||
| # Should be an RPC call here | ||
| yield self.scheduler.retire_workers(workers=to_close) | ||
| # To close may be empty if just asking to remove pending | ||
| # workers, so we should also give a target number | ||
| self.scale_down(to_close, n) | ||
| self._target_scale = n | ||
|
|
||
| def scale(self, n): | ||
| """ Scale cluster to n workers | ||
|
|
||
| Parameters | ||
| ---------- | ||
| n: int | ||
| Target number of workers | ||
|
|
||
| Example | ||
| ------- | ||
| >>> cluster.scale(10) # scale cluster to ten workers | ||
|
|
||
| See Also | ||
| -------- | ||
| Cluster.scale_up | ||
| Cluster.scale_down | ||
| """ | ||
| # TODO we should not rely on scheduler loop here, self should have its | ||
| # own loop | ||
| self.scheduler.loop.add_callback(self._scale, n) | ||
This file contains hidden or 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 hidden or 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.
As a warning, now that you've added a
yieldin this coroutine it's entirely possible for another coroutine to start running while this one waits for a response. It is entirely possible that two_scalecoroutines will be active at the same time.You still can't use a
threading.Lockto fix this (threading locks will lock the entire event loop). You can use a Tornado lock, or a few other methods. Short term I wouldn't worry about it though.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.
Thanks for the precision. I don't think this is an issue yet.