You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dask scheduler high cpu usage when dashboard port is probed #8493
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
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
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?
@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.)
client=distributed.Client(...)
fromscheduler_profilersimportpyspy_on_schedulerwithpyspy_on_scheduler("profile.json", native=True):
input("Press enter to end profile")
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")
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:
You can see that the event loop only gets to spend 14% of the time idle (select).
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.
@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
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
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.
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?
@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.
Activity
asong-c commentedon Dec 15, 2021
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
ian-r-rose commentedon Dec 15, 2021
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?gjoseph92 commentedon Dec 16, 2021
@asong-c I think @ian-r-rose's suggestion of
{BASE_URL}/individual-plots.jsonis a good way to fix this for now. (Also I think the xref is dask/distributed#4827, not thedask/daskissue.)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:
If you upload the
profile.jsonfile 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/.pavithraes commentedon Jan 5, 2022
@asong-c Do these help fix your issue?
asong-c commentedon Jan 5, 2022
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@gjoseph92
https://gist.github.com/asong-c/9199f297477d9ba93845be8308fdbb26
gjoseph92 commentedon Jan 5, 2022
Thanks @asong-c, this is extremely helpful. For others, you can view the py-spy profile here:

profile-dash.json. I recommed looking atMainThreadin left-heavy view, which looks like this:select).@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
/healthendpoint, which is the canonical thing for a liveness probe I think.asong-c commentedon Jan 5, 2022
@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
asong-c commentedon Jan 6, 2022
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
gjoseph92 commentedon Jan 6, 2022
I'm glad
/healthworks. Though it's disappointing to me that reloading the dashboard is so expensive, I do think/healthis the right thing to poll (and the dashboard is arguably the wrong thing to poll). Don't think we need another profile.z4m0 commentedon Mar 2, 2022
I was trying to check for the healthiness of the scheduler and workers when I encountered that issue. Is there an equivelent
/healthto poll to know if the workers are healthy?gjoseph92 commentedon Mar 3, 2022
@z4m0 each worker should have an equivalent
/healthroute 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 thedashboard_addressto the Worker (likeWorker(..., dashboard_address=":9999"), ordask-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.
jsignell commentedon Apr 25, 2022
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.