-
-
Notifications
You must be signed in to change notification settings - Fork 150
basic sge implementation #6
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 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 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
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,124 @@ | ||
| import logging | ||
| import os | ||
| import socket | ||
| import sys | ||
|
|
||
| from distributed import LocalCluster | ||
| from distributed.utils import get_ip_interface | ||
|
|
||
| from .core import JobQueueCluster | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| dirname = os.path.dirname(sys.executable) | ||
|
|
||
|
|
||
| class SGECluster(JobQueueCluster): | ||
| """ Launch Dask on a SGE cluster | ||
|
|
||
| Parameters | ||
| ---------- | ||
| name : str | ||
| Name of worker jobs. Passed to `$SGE -N` option. | ||
| queue : str | ||
| Destination queue for each worker job. Passed to `#$ -q` option. | ||
| project : str | ||
| Accounting string associated with each worker job. Passed to | ||
| `#$ -A` option. | ||
| threads_per_worker : int | ||
| Number of threads per process. | ||
| processes : int | ||
| Number of processes per node. | ||
| memory : str | ||
| Bytes of memory that the worker can use. This should be a string | ||
| like "7GB" that can be interpretted both by SGE and Dask. | ||
| resource_spec : str | ||
| Request resources and specify job placement. Passed to `#$ -l` | ||
| option. | ||
| walltime : str | ||
| Walltime for each worker job. | ||
| interface : str | ||
| Network interface like 'eth0' or 'ib0'. | ||
| death_timeout : float | ||
| Seconds to wait for a scheduler before closing workers | ||
| extra : str | ||
| Additional arguments to pass to `dask-worker` | ||
| kwargs : dict | ||
| Additional keyword arguments to pass to `LocalCluster` | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> from dask_jobqueue import SGECluster | ||
| >>> cluster = SGECluster(project='...') | ||
| >>> cluster.start_workers(10) # this may take a few seconds to launch | ||
|
|
||
| >>> from dask.distributed import Client | ||
| >>> client = Client(cluster) | ||
|
|
||
| This also works with adaptive clusters. This automatically launches and | ||
| kill workers based on load. | ||
|
|
||
| >>> cluster.adapt() | ||
| """ | ||
| def __init__(self, | ||
| name='dask', | ||
| queue='default.q', | ||
| project=None, | ||
| resource_spec='h_vmem=36GB', | ||
| threads_per_worker=4, | ||
| processes=9, | ||
| memory='7GB', | ||
| walltime='0:30:0', | ||
| interface=None, | ||
| death_timeout=60, | ||
| extra='', | ||
| **kwargs): | ||
| self._template = """ | ||
| #!/bin/bash | ||
|
|
||
| #$ -N %(name)s | ||
| #$ -q %(queue)s | ||
| #$ -P %(project)s | ||
| #$ -l %(resource_spec)s | ||
| #$ -l h_rt=%(walltime)s | ||
| #$ -cwd | ||
| #$ -j y | ||
|
|
||
| %(base_path)s/dask-worker %(scheduler)s \ | ||
| --nthreads %(threads_per_worker)d \ | ||
| --nprocs %(processes)s \ | ||
| --memory-limit %(memory)s \ | ||
| --name %(name)s-%(n)d \ | ||
| --death-timeout %(death_timeout)s \ | ||
| %(extra)s | ||
| """.lstrip() | ||
|
|
||
| if interface: | ||
| host = get_ip_interface(interface) | ||
| extra += ' --interface %s ' % interface | ||
| else: | ||
| host = socket.gethostname() | ||
|
|
||
| project = project or os.environ.get('SGE_ACCOUNT') | ||
| if not project: | ||
| raise ValueError("Must specify a project like `project='UCLB1234' " | ||
| "or set SGE_ACCOUNT environment variable") | ||
| self.cluster = LocalCluster(n_workers=0, ip=host, **kwargs) | ||
| memory = memory.replace(' ', '') | ||
| self.config = {'name': name, | ||
| 'queue': queue, | ||
| 'project': project, | ||
| 'threads_per_worker': threads_per_worker, | ||
| 'processes': processes, | ||
| 'walltime': walltime, | ||
| 'scheduler': self.scheduler.address, | ||
| 'resource_spec': resource_spec, | ||
| 'base_path': dirname, | ||
| 'memory': memory, | ||
| 'death_timeout': death_timeout, | ||
| 'extra': extra} | ||
| self.jobs = dict() | ||
| self.n = 0 | ||
| self._adaptive = None | ||
|
|
||
| logger.debug("Job script: \n %s" % self.job_script()) | ||
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,67 @@ | ||
| import os | ||
| from time import time, sleep | ||
|
|
||
| import pytest | ||
|
|
||
| from dask.distributed import Client | ||
| from distributed.utils_test import loop # noqa: F401 | ||
| from pangeo import SGECluster | ||
|
|
||
|
|
||
| def test_basic(loop): | ||
| with SGECluster(walltime='00:02:00', threads_per_worker=2, memory='7GB', | ||
| interface='ib0', loop=loop) as cluster: | ||
|
Member
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. The interface keyword option here will likely fail on a CI system. |
||
| with Client(cluster) as client: | ||
| workers = cluster.start_workers(2) | ||
| future = client.submit(lambda x: x + 1, 10) | ||
| assert future.result(60) == 11 | ||
| assert cluster.jobs | ||
|
|
||
| info = client.scheduler_info() | ||
| w = list(info['workers'].values())[0] | ||
| assert w['memory_limit'] == 7e9 | ||
| assert w['ncores'] == 2 | ||
|
|
||
| cluster.stop_workers(workers) | ||
|
|
||
| start = time() | ||
| while len(client.scheduler_info()['workers']) > 0: | ||
| sleep(0.100) | ||
| assert time() < start + 10 | ||
|
|
||
| assert not cluster.jobs | ||
|
|
||
|
|
||
| def test_adaptive(loop): | ||
| with SGECluster(walltime='00:02:00', loop=loop) as cluster: | ||
| cluster.adapt() | ||
| with Client(cluster) as client: | ||
| future = client.submit(lambda x: x + 1, 10) | ||
| assert future.result(60) == 11 | ||
|
|
||
| assert cluster.jobs | ||
|
|
||
| start = time() | ||
| while len(client.scheduler_info()['workers']) != cluster.config['processes']: | ||
| sleep(0.1) | ||
| assert time() < start + 10 | ||
|
|
||
| del future | ||
|
|
||
| start = time() | ||
| while len(client.scheduler_info()['workers']) > 0: | ||
| sleep(0.100) | ||
| assert time() < start + 10 | ||
|
|
||
| start = time() | ||
| while cluster.jobs: | ||
| sleep(0.100) | ||
| assert time() < start + 10 | ||
|
|
||
|
|
||
| @pytest.mark.skipif('SGE_ACCOUNT' in os.environ, reason='SGE_ACCOUNT defined') | ||
| def test_errors(loop): | ||
| with pytest.raises(ValueError) as info: | ||
| SGECluster() | ||
|
|
||
| assert 'project=' in str(info.value) | ||
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.
Thoughts on #7 ?