-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-12560: [C++] Add scheduling option for Future callbacks #10258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-12560: [C++] Add scheduling option for Future callbacks #10258
Conversation
|
CC @pitrou I think you referenced this in your latest execution engine PR. |
|
I'm not sure why you're suggesting to add so much sophistication. To me there are only two interesting options: "always" and "if unfinished". So we could have |
c95244a to
e992bb6
Compare
|
Since I'm working on work stealing at the thread pool level I agree that idle is no longer needed. I've cleaned this up and rebased. It's much simpler than it was before. |
|
Also, I ran into a bit of trouble with the future callback's weak reference to the future. Before we could just assume it was valid since all callbacks were completed before |
pitrou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. This looks good to me on the principle.
cpp/src/arrow/util/future.cc
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullptr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
cpp/src/arrow/util/future.cc
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why "a copy"? It's not clear to me where a copy is being made.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copy is a few lines down when we call shared_from_this. I'll move the comment and make it more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's only the shared_ptr copy, then I'm not sure it's worth mentioning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the more important thing is that we are intentionally extending the lifetime of the future. I reworded the comment a bit and dropped the "copy". I can always remove it if we want.
cpp/src/arrow/util/future.cc
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The coding conventions prohibit passing mutable lrefs. You could make this a CallbackRecord&&, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
cpp/src/arrow/util/future.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid using ALL_CAPS names, because of potential clashes with macros (this is a common issue with Windows headers, unfortunately).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, technically the style guide prefers kAlways but I see Always used more often in Arrow. Although some of the gandiva code uses kAlways. (https://google.github.io/styleguide/cppguide.html#Enumerator_Names). Any preference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always sounds fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I'll make a PR to add this to the style guide docs as well.
cpp/src/arrow/util/future_test.cc
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird to have this in a private test file, and the mock executor in a .h.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My rationale was only that DelayedExecutor is only used in future_test.cc while MockExecutor is used in future_test.cc and thread_pool_test.cc but I see your point. I'll move this into test_common.h.
cpp/src/arrow/util/future_test.cc
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NEVER is never tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, but it would probably be nicer to be able to spell this as TransferAlways(fut).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
@pitrou Don't worry about the delay, I've been plenty busy elsewhere. I have a just a few follow-up questions and then I'll make the changes. |
c038210 to
a4bcf0f
Compare
|
Ok, I've addressed the comments and this is ready for review again. |
…hould schedule a new thread task. Previously callbacks always ran synchronously.
…inished has completed so the previous 'rely on WeakFuture being valid' trick no longer worked
… shadow a typed enum
be5aa79 to
747c498
Compare
|
Thanks for the update @westonpace . I'll merge once CI passes. |
Previously a future's callbacks would always run synchronously, either as part of
Future::MarkFinishedor as part ofFuture::AddCallback.Executor::Transfermade it possible to schedule continuations on a new thread but it would only take effect if the transferred future's callbacks were added before the source future finished. There are times when the desired behavior is to spawn a new thread task even if the source future is finished already.This PR adds three scheduling options:
The
Neveroption doesn't make any sense for transferring so the transfer only has two choices (always or if unfinished).