Skip to content

Commit 710e74e

Browse files
authored
Add focused benchmark for Parquet pruning setup cache (#24323)
## Which issue does this PR close? * Part of #21554 ## Rationale for this change `ParquetPruningSetupCache` in #21566 needs a focused benchmark that exercises it under deliberately cache-favourable conditions. This benchmark provides a workload where many Parquet files share the same physical schema and use the same predicate, target partition count, and query, creating repeated opportunities to reuse pruning setup. It is intended to measure end-to-end scan cost for this specific workload shape, rather than represent general DataFusion performance or predict improvements in broader benchmarks such as ClickBench. ## What changes are included in this PR? * Adds a Criterion benchmark that creates 128 Parquet files sharing one physical schema and repeatedly executes `SELECT id FROM t WHERE id >= 0`. * Keeps file generation, runtime creation, table registration, and initial correctness validation outside the timed Criterion loop. * Validates that the query returns all 16,384 expected rows before benchmarking. * Enables Criterion's `async_tokio` feature so the asynchronous query execution can be benchmarked with the Tokio runtime. * Registers the new `parquet_pruning_setup_cache` benchmark target. * Documents that the benchmark is intentionally cache-favourable and that its results should not be interpreted as general DataFusion or ClickBench performance results. ## Are these changes tested? The benchmark includes a correctness check that verifies the query returns `128 × 128 = 16,384` rows before the timed benchmark begins. No additional tests are included in this patch. ## Are there any user-facing changes? No. This PR adds a focused benchmark and benchmark configuration only; it does not change user-facing DataFusion behavior or public APIs. ## LLM-generated code disclosure This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed.
1 parent bbf739a commit 710e74e

2 files changed

Lines changed: 115 additions & 1 deletion

File tree

‎benchmarks/Cargo.toml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ arrow = { workspace = true }
4444
async-trait = "0.1"
4545
bytes = { workspace = true }
4646
clap = { version = "4.6.0", features = ["derive", "env", "string"] }
47-
criterion = { workspace = true, features = ["html_reports"] }
47+
criterion = { workspace = true, features = ["async_tokio", "html_reports"] }
4848
datafusion = { workspace = true, default-features = true }
4949
datafusion-common = { workspace = true, default-features = true }
5050
datafusion-common-runtime = { workspace = true }
@@ -71,3 +71,7 @@ tempfile = { workspace = true }
7171
[[bench]]
7272
harness = false
7373
name = "sql"
74+
75+
[[bench]]
76+
harness = false
77+
name = "parquet_pruning_setup_cache"
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//! Benchmarks end-to-end Parquet scan cost for a cache-favourable workload.
19+
//!
20+
//! The 128 files share one physical schema and use the same predicate and target
21+
//! partition count, so pruning setup is reusable in a cache-enabled comparison
22+
//! branch. The predicate matches every file, so each scan must adapt the
23+
//! predicate and build (or reuse) pruning setup for all files.
24+
//!
25+
//! This is a focused baseline for comparing cache-disabled and cache-enabled
26+
//! branches. It is not a general DataFusion benchmark and must not be
27+
//! interpreted as a ClickBench performance result.
28+
29+
use std::{fs::File, sync::Arc};
30+
31+
use arrow::{
32+
array::Int64Array,
33+
datatypes::{DataType, Field, Schema},
34+
record_batch::RecordBatch,
35+
};
36+
use criterion::{Criterion, criterion_group, criterion_main};
37+
use datafusion::prelude::{SessionConfig, SessionContext};
38+
use parquet::arrow::ArrowWriter;
39+
use tempfile::TempDir;
40+
41+
const FILES: usize = 128;
42+
const ROWS_PER_FILE: usize = 128;
43+
44+
fn write_files() -> TempDir {
45+
let directory = tempfile::tempdir().unwrap();
46+
let schema = Arc::new(Schema::new(vec![Field::new("id", DataType::Int64, false)]));
47+
48+
for file_index in 0..FILES {
49+
let start = i64::try_from(file_index * ROWS_PER_FILE).unwrap();
50+
let values = Int64Array::from_iter_values(
51+
start..start + i64::try_from(ROWS_PER_FILE).unwrap(),
52+
);
53+
let batch =
54+
RecordBatch::try_new(Arc::clone(&schema), vec![Arc::new(values)]).unwrap();
55+
let file =
56+
File::create(directory.path().join(format!("{file_index}.parquet"))).unwrap();
57+
let mut writer = ArrowWriter::try_new(file, Arc::clone(&schema), None).unwrap();
58+
writer.write(&batch).unwrap();
59+
writer.close().unwrap();
60+
}
61+
62+
directory
63+
}
64+
65+
fn criterion_benchmark(criterion: &mut Criterion) {
66+
let directory = write_files();
67+
let runtime = tokio::runtime::Runtime::new().unwrap();
68+
let context = runtime.block_on(async {
69+
let context = SessionContext::new_with_config(
70+
SessionConfig::new().with_target_partitions(1),
71+
);
72+
context
73+
.register_parquet("t", directory.path().to_str().unwrap(), Default::default())
74+
.await
75+
.unwrap();
76+
context
77+
});
78+
79+
runtime.block_on(async {
80+
let batches = context
81+
.sql("SELECT id FROM t WHERE id >= 0")
82+
.await
83+
.unwrap()
84+
.collect()
85+
.await
86+
.unwrap();
87+
assert_eq!(
88+
batches.iter().map(RecordBatch::num_rows).sum::<usize>(),
89+
FILES * ROWS_PER_FILE
90+
);
91+
});
92+
93+
criterion.bench_function(
94+
"parquet_pruning_setup_cache/same_schema_files",
95+
|bencher| {
96+
bencher.to_async(&runtime).iter(|| async {
97+
context
98+
.sql("SELECT id FROM t WHERE id >= 0")
99+
.await
100+
.unwrap()
101+
.collect()
102+
.await
103+
.unwrap()
104+
});
105+
},
106+
);
107+
}
108+
109+
criterion_group!(benches, criterion_benchmark);
110+
criterion_main!(benches);

0 commit comments

Comments
 (0)