alamb commented on code in PR #25583: URL: https://github.com/apache/datafusion/pull/25583#discussion_r4084348534
########## datafusion/physical-expr-common/benches/partition_metrics.rs: ########## @@ -0,0 +1,116 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Container costs; run alongside the physical-plan shared-tree benchmark. Review Comment: what does "container" mean in this context? Also what is the "physical-plan shared-tree benchmark"? Maybe we could add a url link ########## datafusion/physical-expr-common/src/metrics/mod.rs: ########## @@ -509,33 +509,81 @@ impl FromIterator<Arc<Metric>> for MetricsSet { /// underlying metrics set #[derive(Default, Debug, Clone)] pub struct ExecutionPlanMetricsSet { - inner: Arc<Mutex<MetricsSet>>, + inner: Arc<Mutex<IndexedMetricsSet>>, +} + +/// Keep registration order for full snapshots, with positions for partition lookups. +/// Both are updated under the same lock, so readers never see a partial registration. +#[derive(Default, Debug)] +struct IndexedMetricsSet { + metrics: MetricsSet, + partitions: HashMap<usize, Vec<usize>>, Review Comment: Could we document what the entries in this this `usize` mean? Is it a map from `partition` --> indexes in Metrics set for that partition? ########## datafusion/physical-plan/benches/partition_metrics.rs: ########## @@ -0,0 +1,189 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Run with `cargo bench -p datafusion-physical-plan --bench partition_metrics`. +//! SQL cannot express per-task metrics reporting while retaining a shared plan. Review Comment: why can't SQL express per-task metrics? That doesn't make any sense to me ########## datafusion/physical-plan/src/execution_plan.rs: ########## @@ -706,14 +706,34 @@ pub trait ExecutionPlan: Any + Debug + DisplayAs + Send + Sync { /// [`MetricsSet`]s may change as execution progresses, the /// specific metrics will not. /// - /// Once `self.execute()` has returned (technically the future is - /// resolved) for all available partitions, the set of metrics - /// should be complete. If this function is called prior to - /// `execute()` new metrics may appear in subsequent calls. + /// New metrics may be registered during execution, including while streams + /// returned by [`Self::execute`] are being polled. Call again to obtain + /// metrics registered since the previous snapshot. fn metrics(&self) -> Option<MetricsSet> { None } + /// Return a snapshot of metrics whose [`Metric::partition`] is `Some(partition)`. Review Comment: I think we have had challenges in the past with `_partition` type APIs on ExecutionPlan to add partition aware APIs. For example, the similar `partition_statistics` was deprecated -- see https://docs.rs/datafusion/latest/datafusion/physical_plan/trait.ExecutionPlan.html#method.partition_statistics I wonder if it would make more sense to try and plumb the notion of partition more deeply in MetricsSet itself somehow? You already kind of do this for alreayd with `IndexedMetricSet` maybe we could make MetricsSet itself store metrics per-partition (rather than a flat Vec) and then you could add apis to metricsSet to access per partition information 🤔 ########## datafusion/physical-expr-common/benches/partition_metrics.rs: ########## @@ -0,0 +1,116 @@ +// Licensed to the Apache Software Foundation (ASF) under one Review Comment: I don't understand the value of this benchmark -- it seems like a better benchmark would be to run an actual query (`SELECT ....`) and then call get_metrics and metrics_per-partitition 🤔 I think it could be removed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
