Skip to content

Start bokeh app to activate bokeh's clean session callbacks. - #6728

Merged
jacobtomlinson merged 13 commits into
dask:mainfrom
z4m0:6694-bokeh-app-start
Jul 25, 2022
Merged

jacobtomlinson merged 13 commits into
dask:mainfrom
z4m0:6694-bokeh-app-start

Conversation

@z4m0

@z4m0 z4m0 commented Jul 15, 2022

Copy link
Copy Markdown
Contributor

Closes #6694

  • Tests added / passed
  • Passes pre-commit run --all-files

@GPUtester

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@github-actions

github-actions Bot commented Jul 15, 2022 •

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

       15 files  ±0         15 suites  ±0   6h 28m 13s ⏱️ - 7m 22s
  2 976 tests ±0    2 886 ✔️  - 1       88 💤 +1  2 ❌ +1 
22 064 runs  ±0  21 031 ✔️ ±0  1 031 💤 +1  2 ❌ ±0 

For more details on these failures, see this check.

Results for commit 5d1f48d. ± Comparison against base commit fae6a21.

♻️ This comment has been updated with latest results.

@gjoseph92
gjoseph92 requested a review from ian-r-rose July 19, 2022 15:07
@gjoseph92

Copy link
Copy Markdown
Collaborator

The bokeh server is not something I'm familiar with, @jsignell are you?

@ian-r-rose

Copy link
Copy Markdown
Collaborator

Thank you for this @z4m0! I gave this a spin, and indeed this fixes the "un-cleaned bokeh session" issue. This has cropped up a number of times, and is definitely a nasty failure mode, so kudos on finding the solution.

For folks wanting an easy reproducer, here is what I did to test this:

  1. In one terminal window, start a dask scheduler with dashboard at port 8787
  2. In a second window, run the following script which GETs the dashboard 100 times:
for i in {1..100}
do
  curl -X GET -L -v 127.0.0.1:8787
done
  1. Observe the "scheduler system" dashboard pane (or whatever system viewer you prefer). On main, CPU quickly rises to 100% and never really goes down. On this branch it also goes to 100%, but recovers after about 20-30 seconds as the unused sessions are cleaned up.

I think this PR is a huge improvement already, but a couple of suggestions:

  1. Here you have just called start() on the scheduler dashboard, but there is also an equivalent worker dashboard where we can do the same thing:

    def connect(application, http_server, worker, prefix=""):
    bokeh_app = BokehApplication(
    applications, worker, prefix=prefix, template_variables=template_variables
    )
    application.add_application(bokeh_app)
    bokeh_app.initialize(IOLoop.current())

    I expect that one to be much less important, since most people don't use that dashboard, but it's an easy thing to include.

  2. I would also love to figure out a way to stop the Bokeh application callbacks upon server close to avoid any zombie tasks. Unfortunately, the services startup logic is a bit convoluted, so I don't see a hugely convenient place to put it. But in the interests of keeping this somewhat encapsulated in the "application server" level, I might try Node.stop_services():

    def stop_services(self):
    for service in self.services.values():
    service.stop()

    It could be something along the lines of:

    def stop_services():
        for application in self.http_application.applications:
            if isinstance(application, BokehTornado):
                application.stop()
         for service in self.services.values(): 
             service.stop() 

I don't love the above snippet, so perhaps there are other suggestions people have.

@ncclementi

Copy link
Copy Markdown
Member

@jacobtomlinson You know your way around the dashboard, any suggestions for point 2) in Ian's comment #6728 (comment) ?

@z4m0

z4m0 commented Jul 20, 2022

Copy link
Copy Markdown
Contributor Author

@ian-r-rose I could validate number 1. Indeed sessions were accumulating as well. However for 2 I could not see any zombie task. Is there a way to reproduce this behaviour?

PD Sorry I messed the commit history of the PR. :(

@ian-r-rose

ian-r-rose commented Jul 20, 2022 •

Copy link
Copy Markdown
Collaborator

However for 2 I could not see any zombie task. Is there a way to reproduce this behaviour?

I'll see if I can come up with something -- I haven't seen it myself, I just have the generalized feeling that if we start a forever callback, as responsible users we should also stop it when done with it :)

@jacobtomlinson jacobtomlinson left a comment

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.

This seems great! Thanks for the efforts here.

I don't have any useful ideas around when to stop the server though. @ian-r-rose your snippet seems reasonable.

@ian-r-rose

Copy link
Copy Markdown
Collaborator

Update here: I did confirm that the various bokeh periodic callbacks keep on going forever after calling close() (though I didn't see any truly pathological behavior from that). So I think that making sure we clean up after ourselves is a good idea. I might amend the above suggestion to avoid an import of the optional bokeh dependency:

def stop_services():
    for application in self.http_application.applications:
        if hasattr(application, "stop") and callable(application.stop):
            application.stop()
     for service in self.services.values(): 
         service.stop()

@ian-r-rose ian-r-rose left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you @z4m0, this is a really nice contribution! If CI is happy with this fix, I am as well.

I see that you are hitting a known linting issue in #6743 which is unrelated to this PR.

Comment thread distributed/node.py
)

def stop_services(self):
if hasattr(self, "http_application"):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an unfortunately verbose check, but I still don't see a substantially cleaner way to do it.

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 it is but without that the test_worker_port_range was failing.

@jacobtomlinson jacobtomlinson left a comment

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.

Looks like the linter isn't happy. Could you fix this up, here are the docs on how to configure the linters to run on each commit. You'll likely need to run precommit install and precommit run --all-files.

@z4m0

z4m0 commented Jul 25, 2022

Copy link
Copy Markdown
Contributor Author

Looks like the linter isn't happy. Could you fix this up, here are the docs on how to configure the linters to run on each commit. You'll likely need to run precommit install and precommit run --all-files.

Ok it was fixed by #6779. Now the linter passes. The failing tests were passing in the last run though...

@jacobtomlinson

Copy link
Copy Markdown
Member

@z4m0 thanks! That's fine, there is some known CI instability here currently, the failures don't look related to this change.

@jacobtomlinson
jacobtomlinson merged commit 55cc1a5 into dask:main Jul 25, 2022
@ian-r-rose

Copy link
Copy Markdown
Collaborator

Thank you @z4m0 !

gjoseph92 pushed a commit to gjoseph92/distributed that referenced this pull request Oct 31, 2022
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.

The dashboard is not cleaning Bokeh Sessions after the browser disconnects.

7 participants