Skip to content

Use SpecCluster name in worker names - #3855

Merged
mrocklin merged 5 commits into
dask:masterfrom
lesteve:use-cluster-name-in-worker-name
Jun 6, 2020
Merged

mrocklin merged 5 commits into
dask:masterfrom
lesteve:use-cluster-name-in-worker-name

Conversation

@lesteve

@lesteve lesteve commented Jun 5, 2020 •

Copy link
Copy Markdown
Member

So this comes from a long discussion about using job arrays in Dask-Jobqueue iin dask/dask-jobqueue#196.

I'll try to summarise it:

  • the emphasis is for now to provide a work-around to people who have a strong constraint to use job arrays
  • when using a job array the job submission script looks like this (SGE here but would be similar for other job schedulers):
#!/usr/bin/env bash
# some other header things
# job array option
#$ -t 1-3

# 0 comes from `self._i` in SpecCluster
dask-worker <scheduler-address> --name 0

the problem is that this script will be run 3 times (the size of the job array) and workers will have the same name causing an error

  • we would like to do:
cluster = SGECluster(name='whatever_$SGE_TASK_ID', cores=1, memory='1GB')

so that the job submission script would look like this:

#!/usr/bin/env bash
# some other header things
# job array option
#$ -t 1-3

# 0 comes from `self._i` in SpecCluster
dask-worker <scheduler-address> --name whatever_$SGE_TASK_ID-0

This PR is an attempt at doing this. Suggestions on how to improve it would be more than welcome!

This modification is only motivated by Dask-Jobqueue so it could be argued that it should stay in Dask-Jobqueue. My feeling is that:

  • having the SpecCluster name be used in the worker names is a rather limited change (to be fair I am not sure what SpecCluster name is used for outside of the __repr__)
  • I have to say that my general approach is to keep as little tricky code in Dask-Jobqueue so this PR feels a better thing to do than overriding new_worker_spec in Dask-Jobqueue to do what we want. The latter approach feels more fragile and could break if some of the SpecCluster internals changed.

If I am being honest the Dask-Jobqueue use case feels a little bit kludgy because the key of the spec would be wathever_$SGE_TASK_ID-0, wathever_$SGE_TASK_ID-1 and the worker names would be whatever_1-0, whatever_2-0, whatever_3-0, whatever_1-1, etc ... not sure it that could cause a problem later down the line.

@lesteve

lesteve commented Jun 5, 2020 •

Copy link
Copy Markdown
Member Author

Slightly tangential: something I would love to get input on as well is what to do with the spec group.

I have read the SpecCluster docstring and this certainly looks like something that applies here (a single entry in the spec creates multiple Dask workers). Looking at the code it feels the spec group is only used in adaptive. Did I miss something? If it is only used in adaptive, I think the reasonable thing to do is to ignore it for the Dask-Jobqueue use case because the scaling is going to be weird anyway and the goal is to provide a work-around for now.

Note that in Dask-Jobqueue there would be two reasons of multiple Dask workers here:

  • one dask-worker command for each job id inside the job array
  • multiple Dask workers created by a single dask-worker command e.g. dask-worker --nprocs 3

Comment thread distributed/deploy/spec.py Outdated
Comment on lines +476 to +477
worker_name_template = f"{self._name}-{{}}"
worker_name = worker_name_template.format(self._i)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if instead we generalize this to having a SpecCluster._new_worker_name method or something similar? Today this would be the following by default

def _new_worker_name(self):
    while self._i in self.worker_spec:
        self._i += 1
    return self._i

But Dask-JobQueue could overwrite it on its own method.

This is just one idea, but shows how we might generailize something on SpecCluster that would make it easier to modify downstream without changing default behaviors on SpecCluster itself.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems completely reasonable (I thought about adding a worker_name_func as an argument to SpecCluster.__init__ which seems slightly overcomplicated but not the good old object-oriented approach), I'll do this and add some tests as well.

@lesteve lesteve Jun 6, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the _new_worker_name(self, worker_number) method. Taking the worker_number as argument of _new_worker_name seems like it will be simpler to customise in Dask-Jobqueue (no need for the self._i updating logic).

I also added some simple tests.

I am making the PR ready for review now that there are tests.

@lesteve
lesteve marked this pull request as ready for review June 6, 2020 06:36
Comment thread distributed/deploy/spec.py Resolved
@mrocklin

mrocklin commented Jun 6, 2020

Copy link
Copy Markdown
Member

This looks good to me. There was an unrelated test failure (I think). I'm going to increase a timeout and see if that helps (I hope that you do not mind my pushing to your branch).

@lesteve

lesteve commented Jun 6, 2020

Copy link
Copy Markdown
Member Author

I hope that you do not mind my pushing to your branch

I actually think this is a super useful feature and allow more productive iterations (both from the contributor and the maintainer point of view), so clearly pushes to my branches more than welcome!

@mrocklin
mrocklin merged commit 0acf1c8 into dask:master Jun 6, 2020
@lesteve
lesteve deleted the use-cluster-name-in-worker-name branch July 28, 2020 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants