Skip to content
Draft
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
11 changes: 7 additions & 4 deletions benchmarks/src/bin/benchmark_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use datafusion_benchmarks::sql_benchmark_runner::{
use datafusion_benchmarks::sql_benchmark_suite::{
ReservedOptions, SuiteExample, SuiteMetadata, discover_suites,
};
use datafusion_benchmarks::util::{BenchmarkRun, CommonOpt, print_memory_stats};
use datafusion_benchmarks::util::{
BenchmarkRun, CommonOpt, build_runtime, print_memory_stats,
};
use datafusion_common::instant::Instant;
use datafusion_common::{DataFusionError, exec_datafusion_err};
use datafusion_common_runtime::SpawnedTask;
Expand All @@ -42,10 +44,10 @@ static ALLOC: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
#[global_allocator]
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[tokio::main]
async fn main() {
fn main() {
env_logger::init();
if let Err(error) = run_cli().await {
let runtime = build_runtime().expect("failed to build the Tokio runtime");
if let Err(error) = runtime.block_on(run_cli()) {
eprintln!("Error: {error}");
std::process::exit(1);
}
Expand Down Expand Up @@ -910,6 +912,7 @@ mod tests {
max_iterations: 1000,
lockstep_in: None,
lockstep_out: None,
reset_memory: false,
partitions: None,
batch_size: None,
mem_pool_type: "fair".to_string(),
Expand Down
7 changes: 4 additions & 3 deletions benchmarks/src/bin/dfbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ enum Options {
}

// Main benchmark runner entrypoint
#[tokio::main]
pub async fn main() -> Result<()> {
pub fn main() -> Result<()> {
env_logger::init();
datafusion_benchmarks::util::build_runtime()?.block_on(run(Cli::parse()))
}

let cli = Cli::parse();
async fn run(cli: Cli) -> Result<()> {
match cli.command {
Options::Cancellation(opt) => opt.run().await,
Options::Clickbench(opt) => opt.run().await,
Expand Down
9 changes: 5 additions & 4 deletions benchmarks/src/bin/external_aggr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use datafusion::execution::runtime_env::RuntimeEnvBuilder;
use datafusion::physical_plan::display::DisplayableExecutionPlan;
use datafusion::physical_plan::{collect, displayable};
use datafusion::prelude::*;
use datafusion_benchmarks::util::{BenchmarkRun, CommonOpt, QueryResult};
use datafusion_benchmarks::util::{BenchmarkRun, CommonOpt, QueryResult, build_runtime};
use datafusion_common::instant::Instant;
use datafusion_common::utils::get_available_parallelism;
use datafusion_common::{DEFAULT_PARQUET_EXTENSION, exec_err};
Expand Down Expand Up @@ -335,11 +335,12 @@ impl ExternalAggrConfig {
}
}

#[tokio::main]
pub async fn main() -> Result<()> {
pub fn main() -> Result<()> {
env_logger::init();
build_runtime()?.block_on(run(Cli::parse()))
}

let cli = Cli::parse();
async fn run(cli: Cli) -> Result<()> {
match cli.command {
ExternalAggrOpt::Benchmark(opt) => opt.run().await?,
}
Expand Down
10 changes: 7 additions & 3 deletions benchmarks/src/bin/imdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use clap::{Parser, Subcommand};
use datafusion::error::Result;
use datafusion_benchmarks::imdb;
use datafusion_benchmarks::util::build_runtime;

#[cfg(feature = "snmalloc")]
#[global_allocator]
Expand Down Expand Up @@ -38,10 +39,13 @@ enum BenchmarkSubCommandOpt {
DataFusionBenchmark(Box<imdb::RunOpt>),
}

#[tokio::main]
pub async fn main() -> Result<()> {
pub fn main() -> Result<()> {
env_logger::init();
match Cli::parse().command {
build_runtime()?.block_on(run(Cli::parse()))
}

async fn run(cli: Cli) -> Result<()> {
match cli.command {
ImdbOpt::Benchmark(BenchmarkSubCommandOpt::DataFusionBenchmark(opt)) => {
Box::pin(opt.run()).await
}
Expand Down
1 change: 1 addition & 0 deletions benchmarks/src/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ mod tests {
max_iterations: 1000,
lockstep_in: None,
lockstep_out: None,
reset_memory: false,
partitions: Some(1),
batch_size: None,
mem_pool_type: "fair".to_string(),
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/src/imdb/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ mod tests {
max_iterations: 1000,
lockstep_in: None,
lockstep_out: None,
reset_memory: false,
partitions: Some(2),
batch_size: Some(8192),
mem_pool_type: "fair".to_string(),
Expand Down Expand Up @@ -536,6 +537,7 @@ mod tests {
max_iterations: 1000,
lockstep_in: None,
lockstep_out: None,
reset_memory: false,
partitions: Some(2),
batch_size: Some(8192),
mem_pool_type: "fair".to_string(),
Expand Down
1 change: 1 addition & 0 deletions benchmarks/src/sql_benchmark_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ mod tests {
max_iterations: 1000,
lockstep_in: None,
lockstep_out: None,
reset_memory: false,
partitions: None,
batch_size: None,
mem_pool_type: "fair".to_string(),
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/src/tpch/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ mod tests {
max_iterations: 1000,
lockstep_in: None,
lockstep_out: None,
reset_memory: false,
partitions: Some(2),
batch_size: Some(8192),
mem_pool_type: "fair".to_string(),
Expand Down Expand Up @@ -473,6 +474,7 @@ mod tests {
max_iterations: 1000,
lockstep_in: None,
lockstep_out: None,
reset_memory: false,
partitions: Some(2),
batch_size: Some(8192),
mem_pool_type: "fair".to_string(),
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
//! Shared benchmark utilities
mod memory;
mod options;
mod reset;
mod run;
mod sampler;
pub mod simulated_object_store;

pub use memory::print_memory_stats;
pub use options::{CommonOpt, QueryOpt};
pub use reset::build_runtime;
pub use run::{BenchQuery, BenchmarkRun, QueryResult};
pub use sampler::Sampler;
14 changes: 11 additions & 3 deletions benchmarks/src/util/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ pub struct CommonOpt {
/// FIFO that this process reports `ready` / `elapsed` to. Requires --lockstep-in
#[arg(long = "lockstep-out", requires = "lockstep_in")]
pub lockstep_out: Option<PathBuf>,

/// Before each iteration, return free memory to the OS, so that the iteration does not depend
/// on what ran before it. Requires the `mimalloc_extended` feature
#[arg(long = "reset-memory")]
pub reset_memory: bool,
}

/// Session configuration overrides shared by query benchmarks.
Expand Down Expand Up @@ -136,17 +141,19 @@ impl CommonOpt {
/// Returns the [`Sampler`] that controls the iteration loop of one query.
pub fn sampler(&self) -> Sampler {
if let (Some(input), Some(output)) = (&self.lockstep_in, &self.lockstep_out) {
return Sampler::lockstep(Lockstep::global(input, output));
return Sampler::lockstep(Lockstep::global(input, output))
.with_reset_memory(self.reset_memory);
}
match self.max_time {
let sampler = match self.max_time {
None => Sampler::fixed(self.iterations),
Some(secs) => Sampler::adaptive(
self.iterations,
self.max_iterations,
Duration::from_secs_f64(secs),
self.target_precision,
),
}
};
sampler.with_reset_memory(self.reset_memory)
}

/// Return an appropriately configured `SessionConfig`
Expand Down Expand Up @@ -387,6 +394,7 @@ mod tests {
max_iterations: 1000,
lockstep_in: None,
lockstep_out: None,
reset_memory: false,
partitions: None,
batch_size: None,
mem_pool_type: "fair".to_string(),
Expand Down
Loading