Skip to content

Dask scheduler high cpu usage when dashboard port is probed #8493

Closed

Description

@asong-c

What happened:
Seeing dask-schedular slowly creep to 100% cpu usage if the dashboard port is regularly probed

Running dask-scheduler in a kubernetes pod like
dask-scheduler --host 0.0.0.0 --dashboard-address 127.0.0.1:8100

I have a service which checks the liveness of the dashboard at port 8100 every second.
After a short period of time dask-scheduler consumes 100% of a vCPU requested by the pod. In this case 1000/3000 cpu in kubernetes

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
    203 test      20   0 5376764 703788  27232 R 100.0  0.5  16:54.21 dask-scheduler

I have also replicated this climbing cpu usage with simple get requests to the dashboard on a loop
curl -X GET -L -v 0.0.0.0:8100

Without probing the port or when disabling the dashboard, cpu usage remains constant while dash-scheduler is idling

Environment:

  • Dask version: 2021.3.0
  • Python version: 3.6
  • Operating System: Docker image based on Ubuntu 18.04
  • Install method (conda, pip, source): pip

Activity

  1. asong-c commented on Dec 15, 2021

    @asong-c
    Author

    I have also attempted this in a container with python 2.7 and see the same behavior, 1000mcpu are used up by dask-scheduler if the dashboard port is probed at an interval of 1 second

    Dask version: 2021.12.0
    Python version: 3.7
    Operating System: Docker image based on Ubuntu 18.04
    Install method (conda, pip, source): pip

  2. ian-r-rose commented on Dec 15, 2021

    @ian-r-rose
    Collaborator

    Hi @asong-c , I believe this is the same issue as what we ran into in dask/distributed#4827 / dask/dask-labextension#185 . Each poll of the dashboard endpoint triggers a huge amount of Bokeh model creation, which is never really cleaned up (at least, not on the timescale we care about).

    In that case, we fixed the issue by polling a known JSON endpoint rather than one of Bokeh's figure endpoints, specifically {BASE_URL}/individual-plots.json. Does that fix the issue you are seeing?

  3. added
    needs info
    on Dec 15, 2021
  4. gjoseph92 commented on Dec 16, 2021

    @gjoseph92
    Collaborator

    @asong-c I think @ian-r-rose's suggestion of {BASE_URL}/individual-plots.json is a good way to fix this for now. (Also I think the xref is dask/distributed#4827, not the dask/dask issue.)

    But it could be interesting for us to see a profile of what the scheduler is actually doing. You could try using this utility https://github.com/gjoseph92/scheduler-profilers to run py-spy on the scheduler and capture a profile of what's going on with something like:

    client = distributed.Client(...)
    from scheduler_profilers import pyspy_on_scheduler
    with pyspy_on_scheduler("profile.json", native=True):
        input("Press enter to end profile")

    If you upload the profile.json file to a gist (NOTE: will contain all the CLI arguments used to start the scheduler; use caution if this contains any secrets), then we can look at it in https://www.speedscope.app/.

  5. pavithraes commented on Jan 5, 2022

    @pavithraes
    Member

    @asong-c Do these help fix your issue?

  6. asong-c commented on Jan 5, 2022

    @asong-c
    Author

    Sorry for the delay and getting back to y'all, catching up after the holidays :)

    Unfortunately I haven't been able to modify the polling app to test changing the polling endpoint just yet, but I have gotten some of the profiling info.

    This is with and watching the kubernetes pod spike up to 1vcpu in use
    dask-scheduler --host 0.0.0.0 --dashboard-address 127.0.0.1:8100

    from scheduler_profilers import pyspy_on_scheduler
    with pyspy_on_scheduler("profile-dash.json", native=True):
      input("Press enter to end profile")
    

    @gjoseph92
    https://gist.github.com/asong-c/9199f297477d9ba93845be8308fdbb26

  7. gjoseph92 commented on Jan 5, 2022

    @gjoseph92
    Collaborator

    Thanks @asong-c, this is extremely helpful. For others, you can view the py-spy profile here: profile-dash.json. I recommed looking at MainThread in left-heavy view, which looks like this:
    image

    1. You can see that the event loop only gets to spend 14% of the time idle (select).
    2. Pretty much all of the time is spent in bokeh-related stuff

    @ian-r-rose's suggestion of polling a different endpoint is definitely the right approach for now. I think what's happening here is basically what it would be like if you refreshed the dashboard in your web browser every second. Unfortunately, it seems like bokeh isn't designed for that.

    There's also a /health endpoint, which is the canonical thing for a liveness probe I think.

  8. asong-c commented on Jan 5, 2022

    @asong-c
    Author

    @gjoseph92 thanks for the analysis!
    I'll also see if I can confirm stable cpu if I can hack our poller to reach /health or /individual-plots.json as well

  9. asong-c commented on Jan 6, 2022

    @asong-c
    Author

    I can confirm that with some hacks, polling /health does not result in cpu spiking reported in kubernetes (at least not after 10 min)
    I can do a new profiling run for what this looks like, but im guessing it isnt really needed

  10. gjoseph92 commented on Jan 6, 2022

    @gjoseph92
    Collaborator

    I'm glad /health works. Though it's disappointing to me that reloading the dashboard is so expensive, I do think /health is the right thing to poll (and the dashboard is arguably the wrong thing to poll). Don't think we need another profile.

  11. z4m0 commented on Mar 2, 2022

    @z4m0

    I was trying to check for the healthiness of the scheduler and workers when I encountered that issue. Is there an equivelent /health to poll to know if the workers are healthy?

  12. gjoseph92 commented on Mar 3, 2022

    @gjoseph92
    Collaborator

    @z4m0 each worker should have an equivalent /health route as well. However, by default this will run on a random port on the worker. Reading the code, looks like passing a port number as the dashboard_address to the Worker (like Worker(..., dashboard_address=":9999"), or dask-worker --dashboard-address=9999) will control this.

    But AFAIK there's no route on the scheduler that can aggregate this and tell you if all workers are healthy, if that's what you're asking for.

  13. jsignell commented on Apr 25, 2022

    @jsignell
    Member

    It looks like the behavior of the dashboard is understood (albeit undesirable) and unlikely to change. I'm going to go ahead and close this issue.

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

    needs info

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions