Skip to content

LocalCluster CPU usage climbs to 100% over time without submitting computations, connecting workers #4827

Closed

Description

@joseph-long

I noticed when I was working locally in a Jupyter Lab session on my laptop that computations would gradually slow down, down, down, until there was nothing to do but restart the notebook kernel (and therefore scheduler/workers). I started to pare down a minimal reproducing example, and got all the way down to launching a LocalCluster with zero workers. After five minutes, CPU use is hovering around 100%, and a few minutes later I start getting the message distributed.utils_perf - WARNING - full garbage collections took 19% CPU time recently repeated every ~1s. This is all without connecting a worker or trying to do any computation.

What happened: Requesting a LocalCluster results in a process that grows to use 100% of the CPU even when no workers are launched and no computations are requested.

What you expected to happen: CPU use should remain roughly static when not under load

Minimal Complete Verifiable Example:

from dask.distributed import Client, LocalCluster
cluster = LocalCluster(n_workers=0)
client = Client(cluster.scheduler.address)
# wait 5 minutes and check CPU use

Screen Shot 2021-05-17 at 5 47 15 PM
Screen Shot 2021-05-17 at 5 51 07 PM
Screen Shot 2021-05-17 at 5 52 10 PM

Anything else we need to know?:

I also tried setting the loop implementation to uvloop in ~/.config/dask/dask.yaml and the issue persisted. Above screenshots are from running with the default config except for:

logging:
  distributed: debug
  distributed.client: warning
  distributed.scheduler: debug
  bokeh: error

Environment:

  • Dask version: 2021.5.0
  • Python version: 3.9.4
  • Operating System: macOS Big Sur 11.3.1
  • Install method (conda, pip, source): conda

Activity

  1. joseph-long commented on May 18, 2021

    @joseph-long
    Author

    This appears to be an interaction between JupyterLab and Dask, since running the minimal reproducing code in a plain vanilla python session showed ~20% CPU consistently over time.

  2. joseph-long commented on May 18, 2021

    @joseph-long
    Author

    Launching dask-scheduler and dask-worker in a terminal and just connecting from JupyterLab does seem to result in asymptotically increasing CPU.

  3. jrbourbeau commented on May 18, 2021

    @jrbourbeau
    Member

    Thanks for reporting this issue @joseph-long! I tried this out locally and observed similar behavior.

    cc @ian-r-rose due to the Jupyter connection

  4. ian-r-rose commented on May 18, 2021

    @ian-r-rose
    Collaborator

    Thanks for the ping! I wonder if this is at all related to dask/dask-labextension#185 .

  5. joseph-long commented on May 18, 2021

    @joseph-long
    Author

    Yes, seems likely. It seems limited to the labextension display of the plots. Opening up the scheduler web UI directly doesn't accumulate CPU load the same way, in my testing. If you think it's better to continue over on the labextension issue tracker, I can move over there!

    Here's a py-spy / speedscope.app profile trace of the scheduler that (if I'm reading it correctly) indicates most of the time is spent in Bokeh:

    image

    View in speedscope

  6. ian-r-rose commented on May 18, 2021

    @ian-r-rose
    Collaborator

    xref: dask/dask-labextension#185 (comment)

    I think it's a problem with the bokeh server that it can't handle frequent requests without leaking memory, but there are also things we can probably do on the dask-labextension side to quiet down the number of requests. Let's continue discussion over in the linked issue, if you don't mind @joseph-long

  7. ian-r-rose commented on May 18, 2021

    @ian-r-rose
    Collaborator

    Fix open, if you care to take it for a spin @joseph-long: dask/dask-labextension#188

  8. joseph-long commented on May 19, 2021

    @joseph-long
    Author

    Unrelated issue but following the development install instructions I ran in to this:

    $ jupyter labextension develop . --overwrite
    Traceback (most recent call last):
      File "/Users/josephlong/devel/dask-labextension/setup.py", line 8, in <module>
        from jupyter_packaging import (
    ModuleNotFoundError: No module named 'jupyter_packaging'
    An error occured.
    FileNotFoundError: The Python package `.` is not a valid package, it is missing the `setup.py` file.
    

    Had to pip install jupyter-packaging manually and then install worked.

    Anyway, I've been running the PR version for a few minutes now and CPU use is constant! Hooray!

  9. ian-r-rose commented on Jun 2, 2021

    @ian-r-rose
    Collaborator

    I've published a patch release of dask-labextension which avoids this behavior. It doesn't fix any underlying reference leaks on the scheduler, but should make it much less likely that users will run into them.

    A small reproducer for this which is independent of using JupyterLab:

    In one terminal:

    dask-scheduler --dashboard-address :33102

    Run a small python script:

    import requests
    import time
    
    while True:
        requests.get("http://localhost:33102")
        time.sleep(.1)

    watch CPU for the process climb.

    A fair criticism here is that this may not be the best way of checking alive-ness of the dashboard, and I would welcome other ideas :)

  10. joseph-long commented on Jun 3, 2021

    @joseph-long
    Author

    It's like you read my mind. I was just checking in to see if the PR had made it into a release!

  11. jrbourbeau commented on Jun 3, 2021

    @jrbourbeau
    Member

    Thanks @ian-r-rose! @joseph-long do you mind trying out the new dask-labextension release and letting us know if it fixes the issues you were seeing?

  12. jrbourbeau commented on Jun 10, 2021

    @jrbourbeau
    Member

    Closing this issue as being resolved by dask/dask-labextension#188. @joseph-long let us know if you want us to reopen

  13. joseph-long commented on Jun 10, 2021

    @joseph-long
    Author

    Tried the new release and it worked for me, but forgot to comment. Thanks!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions