Skip to content

2.28.0 performance related issues #6694

Closed

Description

@sofroniewn

What happened:

Hello! After the 2.28.0 release the napari project is having some dask performance related issues, including timeout fails of some of tests that now take significantly longer. Changing the dask config did not recover the old behavior as I would have expected based on the docs.

A more detailed investigation can be found in the napari issue tracker here napari/napari#1656 but I will reproduce a minimal example below.

What you expected to happen:
I didn't expect such large slow downs with the new release.

Minimal Complete Verifiable Example:

import dask.array as da
import numpy as np
import time


data = da.random.random(
    size=(100_000, 1000, 1000), chunks=(1, 1000, 1000)
)

idxs = [(0,), (50_000,), (99_999,)]

t0 = time.time()
reduced_data = np.min([np.min(data[idx]) for idx in idxs])
t1 = time.time()
print(t1 - t0)

On 2.27.0 this takes about 0.13 seconds to run, on 2.28.0 this takes 4.3 seconds to run.

Anything else we need to know?:

Looking at the 2.28.0 release notes I saw #6665 and think this maybe related to that. I noticed the note on efficiency which suggested there may now be some additional overhead, but I didn't expect the slow down to be so large (note while the above is just a toy example, the slowdown is quite noticeable for real-world examples too).

I tried using

with dask.config.set({"array.slicing.split-large-chunks": False}):
    data = da.random.random(
        size=(100_000, 1000, 1000), chunks=(1, 1000, 1000)
    )

    idxs = [(0,), (50_000,), (99_999,)]

    t0 = time.time()
    reduced_data = np.min([np.min(data[idx]) for idx in idxs])
    t1 = time.time()
    print(t1 - t0)

but I saw no difference between having the setting True or False in both this toy example, or in the real config inside napari if I added it to napari here. If I could get the config working as expected then I can just change the default value and we would be fine.

Environment:

  • Dask version: 2.28.0
  • Python version: 3.7
  • Operating System: MacOS
  • Install method (conda, pip, source): pip

Activity

  1. TomAugspurger commented on Oct 1, 2020

    @TomAugspurger
    Member

    Sorry about the slowdown, and thanks for opening an issue.

    My hope is that #6665 isn't to blame here. It should only apply at graph construction time, but it seems like the slowdown is in compute.

    # Dask 2.27.0
    In [4]: %timeit data[(0,)]
    239 µs ± 24.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
    
    # Dask master
    In [7]: %timeit data[(0,)]
    251 µs ± 37.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
    # Dask 2.27.0
    In [3]: %timeit a.compute()
    34.3 ms ± 16.8 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
    
    # Dask master
    In [3]: %timeit a.compute()
    669 ms ± 113 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

    Right now my guess is that our new graph culling is to blame, but I'll bisect that now.

  2. TomAugspurger commented on Oct 1, 2020

    @TomAugspurger
    Member

    Seems that f0b2ac2 (#6510) is the culprit.

    # b72593b62
    In [3]: %timeit a.compute()
    21.6 ms ± 2.55 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
    
    # f0b2ac29d
    In [3]: %timeit a.compute()
    495 ms ± 35.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

    @madsbk are you able to take a look? The full reproducer is

    import dask.array as da
    
    
    data = da.random.random(
        size=(100_000, 1000, 1000), chunks=(1, 1000, 1000)
    )
    
    a = data[(0,)].min()
    a.compute()
  3. sofroniewn commented on Oct 1, 2020

    @sofroniewn
    Author

    Thanks for looking in @TomAugspurger and identifying the commit!! It's much appreciated.

  4. TomAugspurger commented on Oct 1, 2020

    @TomAugspurger
    Member

    @madsbk in case it helps narrow things down further, I notice that the slowdown is just in the optimization stage.

    # b72593b62
    In [10]: %timeit _ = dask.optimize(a)
    5.14 ms ± 254 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
    
    # dask master
    In [15]: %timeit _ = dask.optimize(a)
    370 ms ± 6.31 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

    snakeviz suggests that we're spending a bunch of time (roughly 2/3rds) in dask.core.keys_in_tasks.

  5. madsbk commented on Oct 1, 2020

    @madsbk
    Contributor

    snakeviz suggests that we're spending a bunch of time (roughly 2/3rds) in dask.core.keys_in_tasks.

    Yes, did a quick profile and in master we are calling keys_in_tasks() 100012 times whereas 2.27.0 only calls in 14 times!

  6. madsbk commented on Oct 1, 2020

    @madsbk
    Contributor

    I think I understand the issue. In Layer.cull() we find the dependencies of all keys even though cull() might only traverse a few keys.

    We need to make HLG support a get-dependencies-of-a-single-key. I am happy to implement this but I am out-of-office must of tomorrow so it will have to wait till Monday :/

  7. TomAugspurger commented on Oct 1, 2020

    @TomAugspurger
    Member

    Thanks for looking!

    I believe that we're scheduled to have a release tomorrow. If we want to "fix" this regression for that release we could consider reverting #6510 for that release, and restoring it shortly after. It reverts cleanly, I haven't run the tests so I'm not sure what else that would necessitate reverting (maybe 7827330, and it would block work by others like Rick's ShuffleStage PR).

    cc @jrbourbeau as well, if you have a preference for how to proceed.

  8. madsbk commented on Oct 1, 2020

    @madsbk
    Contributor

    I haven't run the tests so I'm not sure what else that would necessitate reverting (maybe 7827330, and it would block work by others like Rick's ShuffleStage PR).

    Reverting is fine with me, it shouldn't effect 7827330 but yes it will block Rick's ShuffleStage and my follow up HLG work: #6689 and #6693.

  9. jakirkham commented on Oct 1, 2020

    @jakirkham
    Member

    cc @rjzamora (for vis)

  10. mrocklin commented on Oct 2, 2020

    @mrocklin
    Member

    After looking at this briefly I think that @madsbk fix will be fine, however I think it makes more sense logistically to revert in this case, release, let things settle over the weekend, and then go on a merging spree (there is a lot of interesting work in both dask/dask and dask/distributed).

    @jrbourbeau are you still planning to handle the release today? If not I'm happy to do it.

  11. sofroniewn commented on Oct 2, 2020

    @sofroniewn
    Author

    I've just tested #6699 and confirmed it fixes the performance regression for me. I also asked a question about adding timing based tests that might actually be better for this thread rather than the PR. In napari we use the pytest.mark.timeout(n) decorator in a few places to catch major performance regressions - see this test for example, which was very helpful for us identifying this performance regression - we saw it on our CI right away on the 2.28.0 release, and I'm wondering if some/ more rough tests like that might be helpful for dask too?

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