Skip to content

Conversation

@jakirkham
Copy link
Member

This appears to eat up a good chunk of time in places where the Status needs to be checked. So try dropping this method in favor of the default implementation.

That said, I'm sure this is here for some reason. So marking this as WIP so we can discuss whether removing is ok or if we need to figure out some alternative solution.

This appears to eat up a good chunk of time in places where the `Status`
needs to be checked. So try dropping this method in favor of the default
implementation.
@mrocklin
Copy link
Member

cc @Carreau

If we drop the special `__eq__` method, then these tests are no longer
relevant as they would error instead. So go ahead and drop them for now
should we decide to go ahead with this change.
@jakirkham
Copy link
Member Author

For context this Enum was added in PR ( #3853 ). AIUI this custom __eq__ was about having a smooth change from using strs to Enums in downstream libraries. Not sure if that already happened.

cc @lesteve @jacobtomlinson @jcrist

@jacobtomlinson
Copy link
Member

From a search through the Dask org it looks like strings are still used in dask-cloudprovider and dask-jobqueue.
We will need to update those before merging this.

@jakirkham
Copy link
Member Author

What sort of places are these strs used? Unfortunately searching for things like "finished" on GitHub were less helpful than expected. Though do see some use of Status here and below.

If other object instance is string, we compare with the values, but we
actually want to make sure the value compared with is in the list of
possible Status, this avoid comparison with non-existing status.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the need for some backwards compatibility, I wonder if we might first try the following:

try:
    return self.value == other.value
except AttributeError:
    ...

My experience is that try-except tends to be quite a bit faster than if/else in the try case, and this avoids the type check as well (which should be fine).

We can also migrate over all of the other projects if that will provide a large boost. It isn't hard to do.

@lesteve
Copy link
Member

lesteve commented Nov 25, 2020

This should be easily fixable in dask-jobqueue, if I believe my original comment in #3853 (comment). I have not done anything about it (and probably not planning to do anything about it in the next few days ...) though. Don't hesitate to ping me if you open a PR in dask-jobqueue!

@mrocklin
Copy link
Member

mrocklin commented Nov 25, 2020 via email

@mrocklin
Copy link
Member

mrocklin commented Nov 25, 2020 via email

@jakirkham
Copy link
Member Author

Thanks for filing all of these Matt! 😄

@jakirkham jakirkham marked this pull request as ready for review November 30, 2020 19:10
@jakirkham jakirkham changed the title [WIP] Drop custom __eq__ from Status Drop custom __eq__ from Status Nov 30, 2020
@jakirkham
Copy link
Member Author

Looks like those PRs have been merged. Thanks all! 😄

Marking this as ready for review 🙂

@jakirkham
Copy link
Member Author

Is anything else needed here? Or are we good to merge?

@mrocklin
Copy link
Member

mrocklin commented Dec 1, 2020

@jacobtomlinson @lesteve @guillaumeeb it would be convenient for the Scheduler performance work to drop backwards compatibility for string-valued statuses in the core dask.distributed package. This would break interoperability with dask-cloudprovider and dask-jobqueue prior to the recent PRs sent in last week.

Are you comfortable releasing soonish and dealing with the inevitable user complaints?

@jakirkham
Copy link
Member Author

It's worth noting the Enum object has been around since distributed version 2.19.0 ( 1408ab5 ).

I don't think we are planning on releasing Distributed soon, but I could be wrong about that.

@mrocklin
Copy link
Member

mrocklin commented Dec 1, 2020 via email

@jakirkham
Copy link
Member Author

Yep I understand. Just sharing info for the sake of transparency.

mrocklin pushed a commit that referenced this pull request Dec 1, 2020
In our profiling of the scheduler, we identified to main transitions that took a good chunk of time. These are `transition_processing_memory` and `transition_waiting_processing`. The former takes slightly longer than the other, but both are easily 2x slower than any transition that follows them. Both of them directly or indirectly make a call to `check_idle_saturated`. While this is not necessarily the worst bottleneck for either of them, it does stick out on the callgraph and stands a good chance of improving both transitions runtimes at once. Additionally `check_idle_saturated` includes a fair bit of code that simply crunches numbers and does not touch Python objects as much. It also isn't as dependent on the Cythonization of other classes as other functions in the profile are. So this makes it easier to Cythonize this piece of code without needing to touch too much other code.

Here we go through and annotate the local variables with types. Also we assign non-local variables accessed through attributes to local variables, which we type. Additionally we changed default argument values to be more friendly with C-style types. Initially we tried to type `self.idle`. However as [`self.idle` is a `sortedcontainers.SortedSet`]( https://github.com/dask/distributed/blob/9460e3fe1e0bcdb2daf6ebafe5335d536fa4f492/distributed/scheduler.py#L1292 ), this didn't work (as we need an actual Python `set` to type it). So we left this as untyped.

Should add as a good chunk of the time in `check_idle_saturated` is just spent doing `ws.status == Status.closed`, we still need PR ( #4270 ) to cutdown on the time spent in this method.



Combine assignments and separate them from `if` blocks.

* Change `occ` default to not be `None`

To make it easier to type `occ` later, define this as a non-`None`
value, which is also clearly bogus (namely `-1.0`). That way we can
still replace this value when it hasn't been otherwise set while also
including a type that includes the default value.

* Annotate `check_idle_saturated` for Cythonization

* Hackily type `set`s through local assignment

For now to just see what is possible, assign these attributes to local
variables typed as `set`s. This will allow Cython to use the
corresponding Python C APIs with these objects; thus, optimizing how
they are handled. This saves us temporarily from trying to more
generally Cythonize this class while exploring optimizations here.

* Drop typing of `self.idle`

As `self.idle` is actually a `SortedSet` instead of a `set`, we can't
type it. So revert the typing of `idle`. Though leave all other
`set`-based typing for other optimizations to be applied where possible.
Also leave the assignment of `self.idle` to `idle` as this generates the
attribute access code only once and we need this for both branches
anyways.
@Carreau
Copy link
Contributor

Carreau commented Dec 1, 2020

Sorry for the late reply; this does looks good to me;

If you are a bit worries, you can make one release where you turn this warning on by default. It will raise on users' code but they will still be able to turn the error off with a warning filter to ignore.

@jacobtomlinson
Copy link
Member

Dask cloudprovider 0.5.1 is now on PyPI. Thanks @mrocklin for pushing this forwards.

@jakirkham
Copy link
Member Author

Dask-Jobqueue 0.7.2 has also been released.

Since it sounds like we are planning to do a release of Dask + Distributed soon. Maybe we can merge this after that release? That would allow for more uptake of the downstream projects' releases before this change shows up. Thoughts?

@mrocklin
Copy link
Member

mrocklin commented Dec 9, 2020 via email

@jakirkham
Copy link
Member Author

Now that Dask + Distributed have been released and a week has passed, am curious are we comfortable merging this change? Or would we like to wait longer?

@jakirkham
Copy link
Member Author

Thoughts @mrocklin? 🙂

@mrocklin
Copy link
Member

mrocklin commented Jan 4, 2021

Sure. Let's go for it.

@mrocklin mrocklin merged commit 607cfd2 into dask:master Jan 4, 2021
@jakirkham jakirkham deleted the drop_eq_Status branch January 4, 2021 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants