Skip to content

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

Closed

Description

@z4m0

What happened:
The Dask Scheduler Dashboard CPU usage increases when the dashboard is used but it keeps being high after the user closes the dashboard. I think that this could be related with other issues like dask/dask#8493.

Steps to reproduce:

  1. Start dask-scheduler
  2. Open the browser at localhost:8787
  3. Reload several times.

You can expect the CPU usage to increase the more you reload.

What you expected to happen:
The CPU usage should be stable or at least decrease when the user closes the tab.

More information:
I've added logs to see the active Bokeh sessions

#dashboard/scheduler.py
...
def connect(application, http_server, scheduler, prefix=""):
    bokeh_app = BokehApplication(
        applications, scheduler, prefix=prefix, template_variables=template_variables
    )
    application.add_application(bokeh_app)
    bokeh_app.initialize(IOLoop.current())
    bokeh_app.add_handlers(
        r".*",
        [
            (
                r"/",
                web.RedirectHandler,
                {"url": urljoin((prefix or "").strip("/") + "/", r"status")},
            )
        ],
    )

    import threading
    threading.Thread(
        target=run_stuff,
        args=(bokeh_app,),
    ).start()

from time import sleep

def run_stuff(bokeh_app):
    while True:
        sleep(1)
        sessions = bokeh_app.get_sessions("/status")
        print('Total sessions', len(sessions))
        for (c, session) in enumerate(sessions):
            print('conn:', c, session.connection_count)

Each time the browser reloads the number of sessions increases even though the connection count for all sessions but one is 0.

How to fix this? (I think)

The problem is that the cleaning callback loop is not started. To start one simply has to call bokeh_app.start() after the initialization.

#dashboard/scheduler.py
...
def connect(application, http_server, scheduler, prefix=""):
    bokeh_app = BokehApplication(
        applications, scheduler, prefix=prefix, template_variables=template_variables
    )
    application.add_application(bokeh_app)
    bokeh_app.initialize(IOLoop.current())
    bokeh_app.add_handlers(
        r".*",
        [
            (
                r"/",
                web.RedirectHandler,
                {"url": urljoin((prefix or "").strip("/") + "/", r"status")},
            )
        ],
    )
    bokeh_app.start()

Also setting the option unused_session_lifetime_milliseconds to 500 helps cleaning the sessions faster.

Environment:

  • Dask version: 2022.6.1
  • Python version: 3.10
  • Operating System: Ubuntu 22.04
  • Install method (conda, pip, source): pip

Activity

  1. added
    bug
    and removed on Jul 5, 2022
  2. pavithraes commented on Jul 6, 2022

    @pavithraes
    Member

    @z4m0 Thank you for a well-explained report, and for including a possible solution!

  3. transferred this issue fromdask/daskon Jul 8, 2022
  4. z4m0 commented on Jul 14, 2022

    @z4m0
    ContributorAuthor

    @pavithraes Any news on this? Do you need a PR?

  5. gjoseph92 commented on Jul 14, 2022

    @gjoseph92
    Collaborator

    @z4m0 a PR would be welcome if you feel like opening one, thanks!

  6. z4m0 commented on Jul 19, 2022

    @z4m0
    ContributorAuthor

    @gjoseph92 I've opened a (one line) PR if somebody can review it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdiagnosticsscheduler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions