Skip to content

Replace Bokeh Server with Tornado HTTPServer - #3658

Merged
mrocklin merged 35 commits into
dask:masterfrom
mrocklin:http
Apr 9, 2020
Merged

mrocklin merged 35 commits into
dask:masterfrom
mrocklin:http

Conversation

@mrocklin

@mrocklin mrocklin commented Mar 29, 2020 •

Copy link
Copy Markdown
Member

This creates a vanilla Tornado HTTPServer on the Worker and Schedulers, and then optionally attaches a Bokeh application to that server.

In [1]: from dask.distributed import LocalCluster                                                        

In [2]: cluster = LocalCluster()                                                                         

In [3]: cluster.scheduler.http_server                                                                    
Out[3]: <tornado.httpserver.HTTPServer at 0x7f74fc66f4d0>

In [4]: cluster.scheduler.http_application.applications                                                  
Out[4]: [<bokeh.server.tornado.BokehTornado at 0x7f74ef9dd650>]

Fixes #3645

The goal here is to allow us to always have an HTTP Server running, even if we aren't running the bokeh dashboard. This would be helpful for example for prometheus and health checks, and to allow for other uses of the HTTP Server in the future. I hope that it also makes it easier to configure HTTPS globally across the project.

However, while this cleans things up (at least in my opinion) this does introduce some possible breaking changes. The HTTP Server is no longer a "service" (this concept never really caught on anyway) and I'm tempted to change various keywords from "dashboard" to "http" (although this could easily be reverted if we want more backwards compatibility). Additionally I think I'm handling all of the Bokeh stuff correctly, but I'm working around considerable amount of engineering in that project.

I originally cc'ed @jcrist and @jacobtomlinson on the original issue, but I think that both of them are out for life reasons. cc'ing @quasiben @jrbourbeau and @TomAugspurger instead.

TODOs:

  • Figure out how to handle dashboard keywords, and whether or not to rename them to http or something else
  • Make the different sets of HTTP configurable. For example we probably always want the health checks, but may not always want the proxying or dashboard.
  • Add security back in
  • ...

@mrocklin

Copy link
Copy Markdown
Member Author

OK, for now I'm leaving the user-facing keywords as they were. We can handle renaming things in a future PR if we think it makes sense.

@mrocklin

Copy link
Copy Markdown
Member Author

The challenge with keeping the keywords as they were is that now we can have situations like the following:

dask-scheduler --dashboard-address :8787 --no-dashboard

Which means "host the HTTP Server at port 8787, but don't include the Bokeh stuff". This is a reasonable thing to do, but the spelling is unfortunate. We might also consider the following:

dask-scheduler --http-address :8787 --no-dashboard

And then we would deprecate --dashboard-address and route it to --http-address for a while.

@mrocklin

Copy link
Copy Markdown
Member Author

@fjetter this may interest you all as well

@mrocklin mrocklin changed the title [WIP] Replace Bokeh Server with Tornado HTTPServer Replace Bokeh Server with Tornado HTTPServer Mar 30, 2020
@StephanErb

StephanErb commented Mar 30, 2020 •

Copy link
Copy Markdown
Contributor

With the new code, would it still be supported to add custom routes via a preload module?

As of today the following code works great in a worker

@click.command()
@click.option("--my-custom-endpoint")
def dask_setup(instance, my_custom_endpoint):

    from distributed.dashboard.utils import RequestHandler
    from distributed.dashboard.worker import routes

    class MyHandler(RequestHandler):
        <snip>

    routes.append((my_custom_endpoint, MyHandler))

The code does not work for a scheduler though. For the scheduler the HTTP server instantiation and the preload does not align well, so one needs to dig deep into the internals to get the same effect:

    scheduler.services["dashboard"].server._tornado.add_handlers(
        r".*", [("/" + my_custom_endpoint, MyHandler)]

It is okay that this is now breaking for the scheduler due to the name changes, but I am still wondering: Is the clean integration of custom handlers still supported for the worker? Do you see an easy way to make it also possible for the scheduler?

@TomAugspurger

Copy link
Copy Markdown
Member

I don't think I'll have much useful feedback here. My only request is that we ensure we test against multiple versions of bokeh in our CI if we aren't already.

@mrocklin

Copy link
Copy Markdown
Member Author

Feature request: Please make it officially possible to add custom routes via a preload module.

Yes, I was also thinking about that. My current thought is that we include a list of modules in configuration. Maybe something like this:

scheudler:
  http:
    route-modules:
    - distributed.http.core
    - distributed.http.scheduler.prometheus
    - distributed.http.scheduler.proxy
    - distributed.http.scheduler.json

We would expect these modules to have a specific structure, like having a routes variable.

Thoughts on how we could improve this @StephanErb ?

@mrocklin

Copy link
Copy Markdown
Member Author

I don't think I'll have much useful feedback here. My only request is that we ensure we test against multiple versions of bokeh in our CI if we aren't already.

I'm currently not assuming my changes in Bokeh. Those changes will allow us to delete some code here in the future when our minimum version catch up.

@mrocklin

Copy link
Copy Markdown
Member Author

Tests pass. This is in a state where it could be merged. I haven't added the ability to extend or remove sets of routes yet though.

@jcrist

jcrist commented Mar 31, 2020

Copy link
Copy Markdown
Member

Apologies, I'm on leave right now without a computer (using my phone, not too easy to read code without a computer), this may not be relevant/already covered.

We would expect these modules to have a specific structure, like having a routes variable.

Instead of assuming a standard module structure, I'd prefer the scheduler/worker objects have a set of public methods on them, and use the existing preload script mechanism to add routes/modify the server as needed. This seems more extensible/flexible to me than forcing the user to split their code up into modules with a specific structure. In many cases the routes module may also add plugins or additional services, so keeping http server routes as part of the existing extension points makes more sense to me.

# pseudocode
def dask_setup(scheduler):
    scheduler.http_server.add_routes(...)

@mrocklin

Copy link
Copy Markdown
Member Author

Apologies, I'm on leave right now without a computer (using my phone, not too easy to read code without a computer), this may not be relevant/already covered.

Given that, thank you for taking the time. (and for typing with a small keyboard)

use the existing preload script mechanism to add routes/modify the server as needed

This remains a viable option. In general I agree that the preload mechanism is a good all-purpose solution to problems like this. We're not removing it. I think that the question is "do we want something else as well?"

My default answer to "do we want a new way to customize things?" is almost always "no, that adds complexity and future maintenance burden". We do need to add some configuration here though I think, not because we want to add new routes, but because we will likely want to exclude some. In particular, the proxy route is unlikely to fly in certain secure situations (I would guess). We'll want some mechanism to turn this off.

Now, that could just be a simple boolean in config

scheduler:
  http:
    proxy: false

Or, if we're going to have a config setting, we could generalize this from a single fixed flag, to a list of families of routes that users can include or not include. This should be more general purpose, and hopefully avoid more single-purpose flags from being necessary in the future.

scheduler:
  http:
    - proxy
    - info
    - json
    - prometheus

I'm not sure why people would want to turn off prometheus or one of the other sets of routes, but I wouldn't be very surprised if that occurred.

However, if we're going to have a fixed list of families, it might make sense to extend this to something that a user could extend on their own. This is how I got to the module approach. This may be too much design too early on though. I would love to hear feedback from other people who have more experience here, and I would love to find alternate approaches.

@mrocklin

mrocklin commented Apr 5, 2020 •

Copy link
Copy Markdown
Member Author

OK, I've implemented the separate route-groups as modules approach. The configuration looks like this:

distributed:
  scheduler:
    http:
      routes:
        - distributed.http.scheduler.prometheus
        - distributed.http.scheduler.info
        - distributed.http.scheduler.json
        - distributed.http.health
        - distributed.http.proxy
        - distributed.http.statics
  worker:
    http:
      routes:
        - distributed.http.worker.prometheus
        - distributed.http.health
        - distributed.http.statics

We look for a routes variable within the module.

This doesn't preclude people from also using preload scripts. I like it because it lets users turn off parts of our functionality (like the proxy, or info pages) in a way that is general enough to also extend to their own.

@mrocklin

mrocklin commented Apr 6, 2020

Copy link
Copy Markdown
Member Author

@StephanErb I encourage you to give this a try if you have the time and share any thoughts you may have.

@mrocklin

mrocklin commented Apr 6, 2020

Copy link
Copy Markdown
Member Author

Maybe @gforsyth has the background to be able to review here effectively?

@mrocklin

mrocklin commented Apr 6, 2020

Copy link
Copy Markdown
Member Author

This is at a point where I think that it is mergeable, and will have a positive impact. If there isn't any pushback here I will go ahead and merge this in 48 hours.

@gforsyth gforsyth 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 looks good to me, overall, @mrocklin -- a few comments below around some commented tests and a few broken routes.

applications = {
"/status": status_doc,
"/counters": counters_doc,
"/crossfilter": crossfilter_doc,

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.

possible this is completely unrelated but I'm getting a 404 when trying to access /crossfilter

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.

Hrm, this did cause me to realize that we weren't publishing the statics route to the workers (this is now fixed), but I am definitely able to access this route. I'm not sure what's going on here.

Comment thread distributed/http/scheduler/info.py Resolved
Comment thread distributed/http/scheduler/json.py Resolved
Comment thread distributed/http/tests/test_routing.py Resolved
@mrocklin

mrocklin commented Apr 6, 2020

Copy link
Copy Markdown
Member Author

Thank you for the careful review @gforsyth . That was useful.

@mrocklin

mrocklin commented Apr 8, 2020

Copy link
Copy Markdown
Member Author

Merging this soonish.

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.

Centralize HTTPServer in Server

5 participants