← 输入框|github.com|刷新
Skip to content

Dask features - #14

Merged
dmedv merged 6 commits into
masterfrom
dask
Feb 24, 2021
Merged

dmedv merged 6 commits into
masterfrom
dask

Conversation

@dmedv

@dmedv dmedv commented Feb 11, 2021

Copy link
Copy Markdown
Contributor

Adding the new Dask module. It currently has only one function that creates a new Dask client.

Usage:

import SciServer.Dask

# Attached cluster (when a cluster is created together with a new container)
client = SciServer.Dask.getClient()

# Detached cluster (probably won't be used much, except for testing)
compute_url = 'https://apps.sciserver.org/compute'
ref_id = 'dask-b17b5a3e-6c1d-11eb-82c5-5254001d4703'
client = SciServer.Dask.getClient(compute_url, ref_id)

@amitschang amitschang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes me notice that the setup file lacks any dependencies, maybe this should be done as a separate issue, or should the requirements for this be added to setup.py (like:

    install_requires = ['requests', 'dask', 'dask[distributed]']

?

Comment thread py3/SciServer/Dask.py Outdated
"""
Creates a new client for the specified Dask cluster.

If `compute_url` and `ref_id` are not set, cluster connection properties will be read from the ``~/dask-cluster.json`` file injected into new SciServer Compute containers automatically when they are created with an attached Dask cluster.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a bit long?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. Fixed.

Comment thread py3/SciServer/Dask.py
Comment on lines +45 to +46
with open(base_dir + '/ca.pem', 'w+b') as f:
f.write(b64decode(data['ca']))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused by the combination of PEM file with the binary file option and base64 decoding. The PEM is a plain ASCII file with the certificate/key contents base64 encoded.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's because Compute encodes the PEM files in base64 before putting them in JSON fields. Maybe not strictly necessary, but we get a nice long string with no line breaks, always nice to wrap files in base64, even if they are supposed to be ascii... Similarly, for example, in k8s PEM files would be encoded as base64 if they were put in a secret.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok, this makes sense. The +b would still cause some confusion though, I think

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why? b64decode returns bytes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

but those bytes ought to be ASCII, in any case, I'm sure it would not make a material difference

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't quite understand... Simply removing b would result in an error, obviously. To make it work in text mode I would have to do something like this (unless I'm missing something obvious):

with open(base_dir + '/ca.pem', 'w+',encoding='ascii') as f:
        f.write(b64decode(data['ca']).decode('ascii'))

This looks more, not less confusing to me... Wouldn't working with bytes be more generic and less error prone?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess my point is that since that we expect that to be ascii data and not binary, that doing

with open(base_dir + '/ca.pem', 'w') as f:
    f.write(b64decode(data['ca']).decode('ascii'))

Is a bit more explicit, and would fail fast if the data were in fact not encoded as such - rather than down the line when dask workers are making a connection.

of course it is fine as-is, so I already hit the approval button :)

@dmedv

dmedv commented Feb 11, 2021

Copy link
Copy Markdown
Contributor Author

Regarding the dependencies, I'd rather create a separate issue, because it's not just a Dask problem.

@glemson glemson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see no problems (which does not mean there are none).

@dmedv

dmedv commented Feb 12, 2021

Copy link
Copy Markdown
Contributor Author

Perhaps compute_url should be made part of Config.py, instead of passing it as a parameter. @amitschang @glemson @mtaghiza what do you think?

@amitschang

Copy link
Copy Markdown
Contributor

Perhaps compute_url should be made part of Config.py, instead of passing it as a parameter. @amitschang @glemson @mtaghiza what do you think?

Yes, this would make good sense (if so, we should not forget to make a helm change for computedomain chart to get that set properly in k8s installs)

@dmedv

dmedv commented Feb 12, 2021

Copy link
Copy Markdown
Contributor Author

@amitschang Ok, I've made that change. Feel free to update k8s charts.

@amitschang amitschang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good

@mtaghiza

Copy link
Copy Markdown
Contributor

Is the user going to manually copy the ref_id parameter if the code is not run inside sciserver-compute?
I'm not sure if that is a real use case, but if it is, then one could create a function that returns automatically all the ref_ids a user could use, similar as what is done in the Jobs module with the function that returns all the compute domains a user has access to.

@dmedv

dmedv commented Feb 15, 2021 •

Copy link
Copy Markdown
Contributor Author

@mtaghiza ref_id of available Dask clusters are shown on the Dask tab in the Compute UI, so, at least for now, the idea is to copy the ids manually from there. There is also a Compute API method that will get you a list of all available clusters, but it might need some more work so I'm not including it in this SciScript update yet. In most cases users won't need to provide ref_id manually though.

@mtaghiza

Copy link
Copy Markdown
Contributor

Might need to update the library version value (unfortunately hardcoded in the files) before merging to master

@dmedv
dmedv merged commit b630eb8 into master Feb 24, 2021
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.

4 participants