Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions src/channel_manager.rs

This file was deleted.

52 changes: 52 additions & 0 deletions src/channel_manager_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use async_trait::async_trait;
use datafusion::error::DataFusionError;
use datafusion::prelude::SessionConfig;
use std::sync::Arc;
use tonic::body::BoxBody;
use url::Url;

pub(crate) fn set_distributed_channel_resolver(
cfg: &mut SessionConfig,
channel_resolver: impl ChannelResolver + Send + Sync + 'static,
) {
cfg.set_extension(Arc::new(ChannelResolverExtension(Arc::new(
channel_resolver,
))));
}

pub(crate) fn get_distributed_channel_resolver(
cfg: &SessionConfig,
) -> Option<Arc<dyn ChannelResolver + Send + Sync>> {
cfg.get_extension::<ChannelResolverExtension>()
.map(|cm| cm.0.clone())
}

#[derive(Clone)]
struct ChannelResolverExtension(Arc<dyn ChannelResolver + Send + Sync>);

pub type BoxCloneSyncChannel = tower::util::BoxCloneSyncService<
http::Request<BoxBody>,
http::Response<BoxBody>,
tonic::transport::Error,
>;

/// Abstracts networking details so that users can implement their own network resolution
/// mechanism.
#[async_trait]
pub trait ChannelResolver {
/// 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>;
Copy link
Collaborator

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:

  1. 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? 🤔
  2. 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?

Copy link
Collaborator Author

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.

}

#[async_trait]
impl ChannelResolver for Arc<dyn ChannelResolver + Send + Sync> {
fn get_urls(&self) -> Result<Vec<Url>, DataFusionError> {
self.as_ref().get_urls()
}

async fn get_channel_for_url(&self, url: &Url) -> Result<BoxCloneSyncChannel, DataFusionError> {
self.as_ref().get_channel_for_url(url).await
}
}
File renamed without changes.
3 changes: 3 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod composed_extension_codec;
#[allow(unused)]
pub mod ttl_map;
pub mod util;

pub(crate) use composed_extension_codec::ComposedPhysicalExtensionCodec;
Loading