-
Notifications
You must be signed in to change notification settings - Fork 14
Introduce DistributedExt trait that extends the capabilities of DataFusion's session building tools
#106
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
Conversation
| } | ||
| } | ||
|
|
||
| pub trait MappedDistributedSessionBuilderExt { |
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.
This is pretty much just some trait trickery for allowing users to ergonomically build on top of existing DistributedSessionBuilder implementations adding further capabilities.
We use it in our localhost implementation for adding ourselves the LocalHostChannelResolver on top of whatever DistributedSessionBuilder each individual test provided.
NGA-TRAN
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.
Nice refactor. I only have a few minor comments for documentation and a set of questions for future thinking
| /// Gets all available worker URLs. Used during stage assignment. | ||
| fn get_urls(&self) -> Result<Vec<Url>, DataFusionError>; | ||
| /// For a given URL, get a channel for communicating to it. | ||
| async fn get_channel_for_url(&self, url: &Url) -> Result<BoxCloneSyncChannel, DataFusionError>; |
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 like this interface and I know you are refactoring it so it is not new but because I am here, I am trying to think out loud whether these are possible if we want to consider them in the future. I am talking about these in the context of providing API for scheduling, workload balancing and fairness for queries.
IIUC, these URLs are set per session, right? This means all queries of the same session will get the same set of workers. However, the number of workers each stage of a query uses depends on the needs of each stage itself and the stage will be able to control that which is very nice.
So a few thinkings:
- If we have a large pool of workers, a large query may use all of them to paralyze the execution but a medium query may only need a few workers. Let us talk about a medium query that only needs a subset of workers. Should we provide an interface to return the same subset of workers different stages of a query requests? Or we prefer different stage of a query uses different subset of workers? Or let them use random subset of workers? These have pros and cons and also depends on the nature of the queries. Maybe all three options are good for different use cases and we want to provide APIs for all options? 🤔
- How can we balance the workload for the workers if only a subset of the workers are used by many queries? If the queries keep using the first workers in the vector, will those workers be overused while the rest of the workers idle?
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.
However, the number of workers each stage of a query uses depends on the needs of each stage itself and the stage will be able to control that which is very nice.
Not really, only the head stage in a plan has control over which URLs get assigned to all tasks in the plan, so the worker URLs are just decided once per query (at the beginning of it)
Should we provide an interface to return the same subset of workers different stages of a query requests? Or let them use random subset of workers?
User's right now need to implement this trait for providing the URLs:
pub trait ChannelResolver {
fn get_urls(&self) -> Result<Vec<Url>, DataFusionError>;
}As they are free to return any Vec<Url> they want, they can choose to either always return the same, randomize it, etc..
Although at some point we probably want to extend the API to let people more control over the worker assignation itself.
How can we balance the workload for the workers if only a subset of the workers are used by many queries? If the queries keep using the first workers in the vector, will those workers be overused while the rest of the workers idle?
If the user implements something that does not shuffle the vector before returning it, then yes, probably only the first subset of workers will be used.
A first initial approach could be to just document this behavior so that users can inform their implementation, but extending the API somehow to allow finer grained control over worker assignation could also be a good approach.
| /// Ok(SessionStateBuilder::new() | ||
| /// .with_distributed_option_extension_from_headers::<CustomExtension>(&ctx.headers)? | ||
| /// .build()) | ||
| /// } |
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 had a hard time to see why we need this build_state function just to include just an Ok(...) but then I found you wrote build_state function and then provided it in start_localhost_context which makes sense. Maybe add that kind of instructions here or an appropriate place to show how to us it?
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 some comments about how to use them.
For showing how to use it with ArrowFlightEndpoint, I'm still not sure if it makes sense to do it either here, in the ArrowFlightEndpoint docs that I have not yet done, or as examples in a still not existent examples/ folder.
I'll make a follow up PR with this.
| /// Ok(SessionStateBuilder::new() | ||
| /// .with_distributed_option_extension_from_headers::<CustomExtension>(&ctx.headers)? | ||
| /// .build()) | ||
| /// } |
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.
All these instructions are similar to above. Since these are all functions of the same trait, do you think it is possible to make one set of instructions for all of them?
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.
🤔 not sure what do you mean by "set of instructions". If you are talking about the amount of repetition happening in this documentation, it's a bit annoying, but I don't think Rust offers any way of reusing docs from one method to others, so doc generators and IDEs are expecting the full doc to be inlined in each function.
robtandy
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.
Agree that the examples/ folder is now standing out as missing. It would be the entry point for interested users to see how to use the library.
This refactor looks ergonomically improved! PR approved. ty ty!
Introduces the
DistributedExttrait, that contributes new methods to upstream DataFusionSessionConfig,SessionStateBuilder,SessionStateandSessionContextfor working with Distributed DataFusion.The goal is that just by including the following import:
Some new methods will magically pop up in
SessionConfig,SessionStateBuilder,SessionStateandSessionContext:This makes adding Distributed capabilities to an existing DataFusion program a seamless experience, and users will have the perception that they are working with normal DataFusion.
Previously, the experience for providing distributed capabilities was all over the place:
With this PR, the experience of providing the Distributed extensions is done all as extension trait methods in DataFusion's
SessionConfig,SessionStateBuilder,SessionStateandSessionContext, and with all these methods well documented and centralized in one place (distributed_ext.rs)