viirya commented on code in PR #25583: URL: https://github.com/apache/datafusion/pull/25583#discussion_r4086141361
########## 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: @alamb Removed this benchmark and its terminology. The replacement in `datafusion/core/benches/partition_metrics.rs` runs a SQL query before reading the plan's metrics. ########## datafusion/physical-expr-common/benches/partition_metrics.rs: ########## @@ -0,0 +1,116 @@ +// Licensed to the Apache Software Foundation (ASF) under one Review Comment: @alamb Agreed, removed. The replacement uses `SELECT a + 1 AS b FROM t WHERE a < 16` and measures both metrics retrieval and execution with per-partition reporting. ########## 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: @alamb Yes—the values are positions in the registry's metrics vector, in registration order. I've documented this on `PartitionIndex::positions`. ########## 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: @alamb You're right; that comment was incorrect. I've removed it and switched to a benchmark that builds the plan from SQL, executes it, and reads its metrics in Rust. ########## 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: @alamb Implemented this as `plan.metrics().map(|m| m.for_partition(partition))`. Snapshots retain a fixed registration boundary and share an index updated only on partition reads, keeping index maintenance off the registration path. -- 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]
